This article mainly introduces the typecho plug-in compiling tutorial (I): HelloWorld. This article describes the plug-in file structure, plug-in information, plug-in structure, plug-in process, and so on, if you need a plug-in, you can refer to the plug-in that Laogu is writing about typecho. because typecho is not like wordpress, there are so many reference documents, there are still many pitfalls in writing a plug-in, however, with the continuous development of research, the old master is also getting started, so I will summarize this article and share it with you!
I. starting from HelloWorld
Basic information
Certainly, if you want to develop typecho, you must have read the official example plug-in HelloWorld source code?
Let's first look at the first few lines of the usr/plugins/HelloWorld/Plugin. php file.
The 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. we can obtain the following basic information about 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 link ---> http://typecho.org
All the information is displayed on the plug-in page, as shown in figure
Plug-in structure
Let's continue to look back at the code. the simplest plug-in structure is as follows (to shorten the length, Laogu removed the implementation of specific methods)
Every method has annotations, so I will not repeat them here.
It looks simple, right? In fact, there are still many pitfalls.
The code is as follows:
Class HelloWorld_Plugin implements Typecho_Plugin_Interface
{
/**
* Activate the plug-in method. If activation fails, an exception is thrown directly.
*
* @ Access public
* @ Return void
* @ Throws Typecho_Plugin_Exception
*/
Public static function activate (){}
/**
* Disable the plug-in method. if it fails to be disabled, an exception is thrown.
*
* @ Static
* @ Access public
* @ Return void
* @ Throws Typecho_Plugin_Exception
*/
Public static function deactivate (){}
/**
* Obtain 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 ){}
/**
* Personal user configuration panel
*
* @ Access public
* @ Param Typecho_Widget_Helper_Form $ form
* @ Return void
*/
Public static function personalConfig (Typecho_Widget_Helper_Form $ form ){}
/**
* Plugin implementation method
*
* @ Access public
* @ Return void
*/
Public static function render (){}
}
Plug-in process
The basic process of the plug-in is as follows.
1. after our plug-in is written, it will appear in the background
2. click the Enable button to execute the activate method of the corresponding plug-in class.
3. the plug-in is associated with the target plug-in point, waiting for triggering
4. call the deactivate method when you click disable.
This section is complete.
In the next section, I will describe the plug-in class methods in more detail.