Typecho Plugin Authoring Tutorial (iv): Plug-in mount

Source: Internet
Author: User

This article mainly introduces the Typecho plug-in writing tutorial (four): Plug-in mount, this article explains how to find the plug-in point and mount the plug-in method, the need for friends can refer to the

Finally, after being able to save the configuration information, we can start to write the plug-in's Mount function.

First we need to know that the system for us in all the key links are reserved for the plug-in point to us, the system runs to the plug-in point, will detect whether there are plug-ins hanging at this point, and then implement the logic of Plug-ins!

The plug-in's job is to find the right plug-in point, hang up, and then execute its own logic.

Plug-in point, plug hook, plugin interface ... In the old high here is a concept

The official plugin interface and function list

Our plug-ins need to execute the logic here, Widget_contents_post_edit class of Finishpublish method

File path var/widget/contents/post/edit.php:736, as you can see, the interface passed us two parameters, one is the content of the publication, the other is the class itself. With the class itself, we can arbitrarily call his public method in the plugin!

The code is as follows:

Article finished publishing plugin interface

$this->pluginhandle ()->finishpublish ($contents, $this);

There is also a page publishing interface, which is mentioned in the following code.

How to Mount

Code as follows, there are omitted.

The code is as follows:

  

Class Baidusubmittest_plugin implements Typecho_plugin_interface

{

public static function activate () {

Mount an 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 ' plugin installed successfully, please enter the set Fill entry key ';

}

...

...

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

Do something

}

}

There is code we see that when plug-ins are activated, the system binds the plug-in class Baidusubmittest_plugin render method to the Finishpublish interface! Because Finishpublish passes two parameters, So the Render method also accepts two parameters.

At this point, as long as the plug-in is properly enabled, when we post an article, the system will automatically call the Baidusubmittest_plugin:render () method.

Careful observation of the source code, you will find that this interface does not return a value, what if there is a return value?

This situation is more complicated, the old Gao leave a pit first.

Why is it called the Render method?

Old Gao copied and pasted from Hello World, has not changed its name.

What to do next

The mount point is done, and the next step is to execute our core logic code.

Keep it to the next post!

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.