Typecho plugin compilation tutorial (1): HelloWorld_PHP tutorial

Source: Internet
Author: User
Typecho plugin compilation tutorial (1): HelloWorld. Tutorial on compiling typecho plug-ins (1): HelloWorld this article mainly introduces the tutorial on compiling typecho plug-ins (1): HelloWorld, this article describes the file structure, plug-in information, plug-in structure typecho plug-in compiling tutorial (1): Hello World

This article mainly introduces the typecho plug-in compiling tutorial (1): Hello World. This article describes the plug-in file structure, plug-in information, plug-in structure, plug-in process, and so on, for more information, see

Recently, Lao Gao is writing a plug-in about typecho. because typecho is not like wordpress, there are so many reference documents, there are still many pitfalls in writing a plug-in, but 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.

Compile (1): Hello World this article mainly introduces the typecho plugin compilation tutorial (1): Hello World. This article describes the file structure, plug-in information, and plug-in structure of the plug-in...

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.