Tutorial on writing typecho plug-ins (2): write a new plug-in
This article mainly introduces the typecho plug-in compiling tutorial (2): write a new plug-in. This is the second article in the series. For more information, see
In section 1, we understand the basic structure of a plug-in. Below we need an instance to practice consolidation.
Coincidentally, the old master is revising Baidu sitemap to submit the plug-in for typecho. Let's revise it with the old master!
Preparation
I wonder if Baidu structured plug-ins that have used the WP version have been used by everyone? Lao Gao studied the plug-in, observed its API, and then wrote the typecho version.
Why do we need a new version?
Baidu webmasters recently launched a new interface, which is easier to use and has a low workload. Just change the interface!
What functions do new plug-ins need to implement?
1. Real-time article push
2. Push historical data
3. Site Map
Where is the interface call address (API?
Baidu webmaster background, PHP interface instance:
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 accesskey ';
$ 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;
Start
Let the old master pirate the code of the previous HELLO_WORLD plug-in, delete all comments, and add their own information.
The Code is as follows:
If (! Defined ('_ TYPECHO_ROOT_DIR _') exit;
/**
* Tutorial version of Baidu structured plug-in
*
* @ Package BaiduSubmitTest
* @ Author
* @ 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 has a plug-in named "Naked plug-in", which means that no plug-in can be used. Every time you write a plug-in, the old master will prepare a bare plug-in.
We put it in usr/plugins/BaiduSubmitTest/Plugin. php
Go to the background plug-in now,
Why is plug-and-play?
We cannot enable the plug-in because we have no method to implement the plug-in.
In the next section, we will enrich our plug-ins!
This section is complete.