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 ')?> "/></P></FORM></DIV><?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