Typecho Plugin Authoring Tutorial (ii): Write a new plugin, Typecho plugin _php tutorial

Source: Internet
Author: User

Typecho Plugin Authoring Tutorial (ii): Write a new plugin, Typecho plugin


In the first section we understand the basic composition of a plug-in, below we need an example to practice consolidation.

True who happened, old Gao is recently revised Baidu sitemap Submit plugin for Typecho, below and old high revised it!

Get ready

Do not know everyone used WP version of the Baidu structure plug-in did not? The old high is to study the plug-in, observe its API, and then write out the version of Typecho.

Why should it be revised?

Baidu Webmaster recently launched a new interface, the use of more simple, the workload is not big, simply change it!

What features does the new plugin need to implement?

1. Post real-time push
2. Push historical data
3. Site Map

Where is the interface call address (API)?

Baidu webmaster Backstage, PHP interface example:
Copy the Code code as follows:
$urls = Array (
' Http://www.example.com/1.html ',
' Http://www.example.com/2.html ',
);
$api = ' http://data.zz.baidu.com/urls?site=www.phpgao.com&token= your access key ';
$ch = Curl_init ();
$options = Array (
Curlopt_url = $api,
Curlopt_post = True,
Curlopt_returntransfer = True,
Curlopt_postfields = implode ("\ n", $urls),
Curlopt_httpheader = = Array (' Content-type:text/plain '),
);
Curl_setopt_array ($ch, $options);
$result = curl_exec ($ch);
echo $result;

Get started.

Let Old high first hello_world the code of the plug-in of the previous section, delete all comments, add their own information.
Copy the Code code as follows:
if (!defined (' __typecho_root_dir__ ')) exit;
/**
* Baidu Structured Plugin Tutorial Edition
*
* @package Baidusubmittest
* @author Old High
* @version 0.4
* @link http://www.phpgao.com/typecho_plugin_baidusubmit.html
*/
Class Baidusubmittest_plugin implements Typecho_plugin_interface
{

public static function Activate () {}

public static function Deactivate () {}

public static function config (Typecho_widget_helper_form $form) {}

public static function Personalconfig (Typecho_widget_helper_form $form) {}

public static function render () {}
}

The above code old high up a name called Naked plug-ins, meaning that nothing can do the plug-in, each time the plugin to write the old high will prepare a bare plug-in.

We'll put it in usr/plugins/baidusubmittest/plugin.php.

Go to the backstage plugin immediately,

Why Plug and Play?

Because we do not implement the plug-in method, it cannot be enabled.

The next section we make our plug-ins become plump up!

The end of this section.

http://www.bkjia.com/PHPjc/1008010.html www.bkjia.com true http://www.bkjia.com/PHPjc/1008010.html techarticle Typecho Plugin Writing tutorial (ii): Write a new plugin, Typecho plug-in the first section we understand the basic composition of a plug-in, we need an example to practice consolidation. Really who happened, ...

  • Related Article

    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.