Typecho Plugin Authoring Tutorial (a): Hello world

Source: Internet
Author: User
Tags php file throw exception

This article mainly introduces the Typecho plugin writing tutorial (a): Hello world, this article explains the plug-in file structure, plug-in information, plug-in structure, plug-in flow and so on, the need for friends can refer to the

Recently, the old Gao is writing a plug-in about Typecho, because Typecho unlike WordPress, there are so many document references, write a plug-in or encountered a lot of pits, but as the research continues to deepen, the old high also slowly started, and then summed up this writing tutorial to share to everyone!

I. Speaking from HelloWorld

Basic information

Presumably want to develop typecho you must have read the official example plug-in HelloWorld source?

Let's take a look at the first few lines of 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, and we can draw the following basic information about the plugin from the code

Plugin Description---> Hello world

Plug-in package name---> HelloWorld

Plugin Author---> qining

Plug-in version---> 1.0.0

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

This information is also displayed in the plugin page, as shown in the following figure

Plug-in structure

We continue to look at the following code, a simplest plug-in structure is as follows (in order to shorten the length of the old high removal of the implementation of the specific method)

Each method has a basic annotation, the old Gao no longer repeat.

Looks pretty simple, doesn't it? In fact, there are a lot of pits.

The code is as follows:

Class Helloworld_plugin implements Typecho_plugin_interface

{

/**

* Activate plug-in method, if activation fails, throw exception directly

*

* @access Public

* @return void

* @throws typecho_plugin_exception

*/

public static function Activate () {}

/**

* Disable plug-in method, if disabled, throw exception directly

*

* @static

* @access Public

* @return void

* @throws typecho_plugin_exception

*/

public static function Deactivate () {}

/**

* Get 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's configuration panel

*

* @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 for plug-ins is this.

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

2. Click on the Enable button, will perform the corresponding plug-in class activate method

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

4. Call the Deactivate method when you click Deactivate

End of this section.

The next section will describe the method of the plug-in class in more detail.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.