Typecho plugin compilation tutorial (2): write a new plugin, typecho plugin _ PHP Tutorial

Source: Internet
Author: User
Tutorial on writing typecho plug-ins (2): write a new plug-in, typecho plug-in. Tutorial on compiling typecho plug-ins (II): write a new plug-in. Section 1 of the typecho plug-in describes the basic components of a plug-in. below we need to consolidate it with an example. Coincidentally, the typecho plug-in compilation tutorial (2): write a new plug-in, typecho plug-in

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.

Plugin (2): write a new plug-in. the first section of the typecho plug-in describes the basic structure of a plug-in. below we need an example to practice and consolidate it. Coincidentally ,...

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.