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