This article mainly introduces the typecho plug-in compiling tutorial (4): plug-in mounting. This article explains how to find plug-in points and mount the plug-in. For more information, see, after saving the configuration information, we can start to compile the plug-in mounting function.
First, we need to know that the system reserves a plug-in point for us in all key links. when the system runs the plug-in point, it will detect whether there is a plug-in hanging on this point, then execute the plug-in logic!
The plug-in job is to find a proper plug-in point, mount it, and then execute its own logic.
Plug-in point, plug-in Hook, plug-in interface... Old Master is a concept.
Official plug-in interface and function list
Here, the finishPublish method of the Widget_Contents_Post_Edit class is the logic to be executed by our plug-in.
File path var/Widget/Contents/Post/Edit. php: 736. we can see that the interface passes two parameters for us, one is the published content, and the other is the class itself. With the class itself, we can freely call its public methods in the plug-in!
The code is as follows:
// Post plug-in completion 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, which is omitted.
The code is as follows:
<? Php
Class BaiduSubmitTest_Plugin implements Typecho_Plugin_Interface
{
Public static function activate (){
// Mount the publishing article and page interface
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 'plugin installed successfully. enter the settings and enter the accesskey ';
}
...
...
Public static function render ($ contents, $ class ){
// Do something
}
}
Code shows 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.
Now, as long as the plug-in is enabled properly, after an article is published, the system will automatically call the BaiduSubmitTest_Plugin: render () method.
When you carefully observe the source code, you will find that this interface has no return value. what if there is a return value?
This situation is complicated.
Why is it the render method?
The old master copied and pasted from hello world and never changed its name.
What to do next
The Mount point is done. The next step is to execute our core logic code.
Old Master will stay in the next article!