Typecho Plugin Authoring Tutorial (iv): Plugin mount _php Tutorial

Source: Internet
Author: User

Typecho Plugin Authoring Tutorial (iv): plug-in Mount


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 plug-in method, the need for friends can refer to the next

Finally, with the ability to save the configuration information, we can begin to write the plugin's mount function.

First we need to know that the system for us in each of the key links are reserved plug-in points to us, the system runs to the plug-in point, will detect whether there is a plug-in hanging at this point, and then execute the plug-in logic!

The plugin's job is to find the right 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 Old Heights.

Official plug-in interface and feature List

Our plugin needs to execute the logic 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 for us passed two parameters, one is the content of the publication, the other is the class itself. With the class itself, we can call his public method at will in the plugin!

The code is as follows:

Article completion publishing plug-in interface

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

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

How to Mount

The code is as follows, with ellipsis.

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 settings to fill in the access key ';

}

...

...

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

Do something

}

}

With the code we see, when the plugin is activated, the system binds the render method of the plug-in class Baidusubmittest_plugin 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 normally enabled, the Baidusubmittest_plugin:render () method is automatically called when we post an article.

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

The situation is more complicated and the old one has to leave a hole.

Why is the Render method called?

Old Gao copied and pasted from Hello World, and 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 your old job for the next article!

http://www.bkjia.com/PHPjc/1007643.html www.bkjia.com true http://www.bkjia.com/PHPjc/1007643.html techarticle Typecho Plug-in writing tutorial (iv): plug-in Mount 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 ...

  • 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.