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

Source: Internet
Author: User

This article mainly introduces the Typecho plug-in writing tutorial (ii): Write a new plug-in, this article is the second article of the series, the need for friends can refer to the next

In the first section we understand the basic composition of a plugin, we need an example to practice consolidating.

Really got, the old high recently is the revision Baidu Sitemap submission plug-in for Typecho, below and old Gao together revision!

Get ready

Do not know that you have used WP version of the Baidu structural plug-ins do not? The old high is to study the plug-in, observe its API, and then wrote the Typecho version.

Why should it be revised?

Baidu Webmaster recently introduced a new interface, using more simple, the workload is not big, simply change it!

What functionality does the new plug-in need to implement?

1. The article real-time push to send

2. Push historical data

3. Site Map

Where is the interface invocation address (API)?

Baidu webmaster background, PHP interface examples:

The code is 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 Gao first the previous section of the Hello_world plug-in code pirated, delete all comments, add their own information.

The code is as follows:

if (!defined (' __typecho_root_dir__ ')) exit;

/**

* Baidu Structured Plug-in tutorial version

*

* @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 is called bare plugin, meaning is what can not do plug-ins, every time write plug-ins when the old high will prepare a bare plug-ins.

We put it in the usr/plugins/baidusubmittest/plugin.php

Go to the back office immediately, as shown

Why is Plug and play?

Because we do not have a way to implement plug-ins, we cannot enable it.

In the next section we let our plug-ins become plump!

End of this section.

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.