Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand the typecho plug-in Writing tutorial

Shulou Source: shulou.com Published: 2022-06-03 09:15:42 09月17日 Update

This article mainly introduces "how to understand typecho plug-in writing tutorials". In daily operation, I believe many people have doubts about how to understand typecho plug-in writing tutorials. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "how to understand typecho plug-in writing tutorials". Next, please follow the editor to study!

i. Start with HelloWorld.

Basic information

If you want to develop typecho, you must have read the source code of the official sample plug-in HelloWorld?

Let's look at the first few lines of the usr/plugins/HelloWorld/Plugin.php file first.

The copy code is as follows:

If (! defined ('_ _ TYPECHO_ROOT_DIR__')) exit

/ * *

* Hello World

*

* @ package HelloWorld

* @ author qining

* @ version 1.0.0

* @ link http://typecho.org

, /

...

...

These lines of code are the basic information of a plug-in, from which we can derive the following basic information related to the plug-in.

Plug-in description-> Hello World

Plug-in package name-> HelloWorld

Plug-in author-> qining

Plug-in version-> 1.0.0

Plug-in links-> http://typecho.org

At the same time, this information is displayed on the plug-in page, as shown in the following figure

Plug-in structure

Let's continue to look at the following code, and the simplest plug-in structure is as follows (to shorten the length, Lao Gao removes the implementation of the specific method)

Each method is basically annotated, and Lao Gao won't repeat it any more.

Doesn't it look easy? In fact, there are still a lot of holes in it.

The copy code is as follows:

Class HelloWorld_Plugin implements Typecho_Plugin_Interface

{

/ * *

* activate the plug-in method. If the activation fails, throw an exception directly.

*

* @ access public

* @ return void

* @ throws Typecho_Plugin_Exception

, /

Public static function activate () {}

/ * *

* disable the plug-in method. If it fails, throw an exception directly.

*

* @ static

* @ access public

* @ return void

* @ throws Typecho_Plugin_Exception

, /

Public static function deactivate () {}

/ * *

* get the plug-in configuration panel

*

* @ access public

* @ param Typecho_Widget_Helper_Form $form configuration panel

* @ return void

, /

Public static function config (Typecho_Widget_Helper_Form $form) {}

/ * *

* configuration panel for individual users

*

* @ access public

* @ param Typecho_Widget_Helper_Form $form

* @ return void

, /

Public static function personalConfig (Typecho_Widget_Helper_Form $form) {}

/ * *

* plug-in implementation method

*

* @ access public

* @ return void

, /

Public static function render () {}

}

Plug-in process

The basic process of the plug-in is like this.

1. When our plug-in is written, it will appear in the background.

two。 When the enable button is clicked, the activate method of the corresponding plug-in class is executed

3. The plug-in is associated with the target plug-in point, waiting for the trigger

4. Call the deactivate method when you click to deactivate

At this point, the study on "how to understand typecho plug-in writing tutorials" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Plug-ins methods code tutorials information learning panels configuration more process activation structure Lao Gao help practical next personal author at the same time background Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Technology NVidia Shulou Tech Info MySQL