WordPress plugin Development (II) HELLO World Improved version

Source: Internet
Author: User

In the previous article WordPress plugin developed (a) Hello world, demonstrating the simplest implementation of Hello World, just adding the Hello World character after each post, and the characters are also written dead.

What if the user needs to enter some text and then display it at the back of each article?

First of all, there is a menu in the background, click on the menu to display a page, in the page has an input box, the user input is finished, click Save, Save the content to the database, display each article, extract the saved information to the page can be.

Implementation ideas
When activating a plug-in, use the Add_option function to add a field to the wp_options, which prevents the plugin from being deleted using the Delete_option function.
Add a plugin menu to the WordPress Background Settings menu and use the Add_options_page function when adding menus
When you click on the menu, a Submit button appears on the page and an input box in the page.

Code implementation:

<?PHP/*Plugin name:hello-worldplugin uri:http://1100w.com/description: The simplest plug-in implementation, append Hello worldversion to each post: 1.0author:1100wauthor URI:HTTP://1100W.COMLICENSE:GPL*/Add_filter (' The_content ', ' Hello_world ');/*Runs When plugin is activated*/Register_activation_hook (__file__, ' Hello_world_install '); /*Runs on plugin deactivation*/Register_deactivation_hook (__file__, ' Hello_world_remove ' );functionHello_world_install () {add_option ("Hello_world_data", ' Default ', ' ', ' yes ');}functionHello_world_remove () {delete_option (' Hello_world_data ');}if(Is_admin ()) {/*Call the HTML code*/Add_action (' Admin_menu ', ' Hello_world_admin_menu '); functionHello_world_admin_menu () {Add_options_page (' Hello world ', ' Hello World ', ' Administrator ', ' Hello-world ', ' hello_world_html_page '); }}? ><?PHPfunctionHello_world_html_page () {><div>value= "<?php echo get_option (' Hello_world_data ');?>"/>(ex. Hello world) </td></tr></table><input type= "hidden" name= "action" value= "Update"/><input Type= "hidden" name= "page_options" value= "Hello_world_data"/><p><input type= "Submit" value= "<?php _e ( ' Save changes ')?> "/&GT;&LT;/P&GT;&LT;/FORM&GT;&LT;/DIV&GT;&LT;?php}? ><?PHP//Callback functionfunctionHello_world ($content){     //Checking if on post page.     if(Is_single ()) {return $content. ' ; }     Else {         return $content; }}?>

Show effect

WordPress plugin Development (II) HELLO World Improved version

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.