Typecho plug-in writing tutorial (4): plug-in mounting, typecho mounting_PHP tutorial

WBOY
Release: 2016-07-13 09:52:25
Original
911 people have browsed it

Typecho plug-in writing tutorial (4): plug-in mounting, typecho mounting

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

The file path is 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!
Copy code 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 following code.

How to mount

The code is as follows, some are omitted.
Copy code 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 finishPublish interface! Since finishPublish will pass two parameters, the render method must also accept two parameters.

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

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

This situation is more complicated, 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.

Lao Gao, let’s leave it to the next article!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1008006.htmlTechArticletypecho plug-in writing tutorial (4): plug-in mounting, typecho mounting Finally, after being able to save the configuration information, We can start writing the mounting function of the plug-in. First we need to know...
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