Home >Backend Development >PHP Tutorial >Typecho plug-in writing tutorial (4): Plug-in mounting_PHP tutorial

Typecho plug-in writing tutorial (4): Plug-in mounting_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:52:38942browse

Typecho plug-in writing tutorial (4): Plug-in mounting

This article mainly introduces the typecho plug-in writing tutorial (4): Plug-in mounting. This article explains how to find the plug-in. How to click and mount the plug-in, friends who need it can refer to it

Finally, after being able to save the configuration information, we can start writing the plug-in mounting function.

First of all, we need to know that the system has reserved plug-in points for us in various key links. When the system runs to the plug-in point, it will detect whether there is a plug-in hanging on this point, and then execute the plug-in logic!

The job of the plug-in is to find the appropriate plug-in point, hang it up, and then execute its own logic.

Plug-in point, plug-in hook, plug-in interface. . . It’s a concept here at Lao Gao

Official plug-in interface and function list

The logic that our plug-in needs to execute is here, the finishPublish method of the Widget_Contents_Post_Edit class

File path var/Widget/Contents/Post/Edit.php:736. You can see that the interface passes us two parameters, one is the published content and the other is the class itself. With the class itself, we can call its public methods at will in the plug-in!

The code is as follows:

// Article completed publishing plug-in interface

$this->pluginHandle()->finishPublish($contents, $this);

There is also a page publishing interface, which will be mentioned in the code below.

How to mount

The code is as follows, some are omitted.

The code is as follows:

class BaiduSubmitTest_Plugin implements Typecho_Plugin_Interface

 {

public static function activate(){

// Mount the interface for publishing articles and pages

Typecho_Plugin::factory('Widget_Contents_Post_Edit')->finishPublish = array('BaiduSubmitTest_Plugin', 'send');

Typecho_Plugin::factory('Widget_Contents_Page_Edit')->finishPublish = array('BaiduSubmitTest_Plugin', 'send');

Return 'The plug-in is installed successfully, please enter the settings to fill in the access key';

 }

public static function render($contents, $class){

//do something

 }

 }

We can see from the code that when the plug-in is activated, the system binds the render method of the plug-in class BaiduSubmitTest_Plugin to the interface of finishPublish! Since finishPublish will pass two parameters, the render method must also accept two parameters.

At this point, as long as the plug-in is enabled normally, the system will automatically call the BaiduSubmitTest_Plugin:render() method after we publish an article.

Observe the source code carefully, you will find that this interface has no return value. What if there is a return value?

This situation is more complicated, so Lao Gao will leave a hole first.

Why is it called the render method?

Lao Gao copied and pasted it from hello world, and the name has not been changed.

What to do next

Now that the mount point is fixed, the next step is to execute our core logic code.

Let’s leave it to the next article!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1007643.htmlTechArticleTypecho plug-in writing tutorial (4): Plug-in mounting This article mainly introduces the typecho plug-in writing tutorial (4) : Plug-in mounting, this article explains how to find the plug-in point and mount the plug-in...
Statement:
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