Typecho plug-in writing tutorial (1): Hello World_PHP tutorial

WBOY
Release: 2016-07-13 09:52:48
Original
783 people have browsed it

Typecho plug-in writing tutorial (1): Hello World

This article mainly introduces the typecho plug-in writing tutorial (1): Hello World. This article explains the file structure of the plug-in. For plug-in information, plug-in structure, plug-in process, etc., friends in need can refer to it

Recently, Lao Gao is writing a plug-in about typecho. Since typecho is not like WordPress, there are so many document references. There are still many pitfalls in writing a plug-in. However, as the research continues to deepen, Lao Gao gradually I got started, so I summarized this writing tutorial to share with everyone!

I. Starting from HelloWorld

Basic information

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

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. From the code, we can get 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 link ---> http://typecho.org

At the same time, this information will be displayed on the plug-in page, as shown below

Plug-in structure

We continue to look at the following code. The simplest plug-in structure is as follows (in order to shorten the length, Lao Gao has removed the implementation of specific methods)

Each method basically has comments, so I won’t go into details.

It seems simple, right? In fact, there are still many pitfalls.

The code is as follows:

class HelloWorld_Plugin implements Typecho_Plugin_Interface

 {

 /**

* Activate plug-in method. If activation fails, an exception will be thrown directly

*

* @access public

* @return void

* @throws Typecho_Plugin_Exception

*/

public static function activate(){}

 /**

* Disable plug-in method, if the disablement fails, an exception will be thrown 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 as follows.

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

2. After clicking the enable button, the activate method of the corresponding plug-in class will be executed

3. The plug-in is associated with the target plug-in point and is waiting to be triggered

4. Call the deactivate method when you click to deactivate

This section is over.

In the next section, Lao Gao will explain the plug-in class methods in more detail.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1007638.htmlTechArticletypecho plug-in writing tutorial (1): Hello World This article mainly introduces the typecho plug-in writing tutorial (1): Hello World, this article explains the file structure, plug-in information, and plug-in structure of the plug-in...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template