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.