Describes how to use the get_current_screen () function in WordPress development and the preferencescreen function.

Source: Internet
Author: User

Describes how to use the get_current_screen () function in WordPress development and the preferencescreen function.

The get_current_screen () function is a very useful function. If you are working on a topic but do not know where to put the document, then you should take a look at this function, which is only started from WordPress 3.0. This function allows us to get a WP_Screen object, add a custom help menu in the background using the member method of this object (this function has been improved after version 3.3 ).

If you do not like to study WordPress too thoroughly, you can take a soy sauce bottle and tap it forward.

Introduction
First, get_current_screen () is very simple, but returns an object. Therefore, this article mainly describes the operations after obtaining the object.

Description

// It is easy to use $ screen = get_current_screen (); // $ screen is the instantiated object at this time.

Application Instance
Let's take a simple example. Although the process code can be displayed, it may not make any sense in the time application, just as an example.
Although it is already very simple, it is still very difficult, thanks to the blessing you can understand.

Function xz_theme_options_add_page () {$ theme_page = add_theme_page (// If successful, the hook tag is returned. Otherwise, the false variable $ theme_page is returned. 'Theme settings', // Titlee 'Theme settings', // The name 'edit _ theme_options 'displayed in the background menu ', // The Position of the Option 'Theme _ options', // alias, that is, the parameter 'xz _ theme_op_page 'transmitted by get // display the function called by the content); if (! $ Theme_page) return; // If creation fails, the add_action ("load-$ theme_page", 'xz _ help') function is displayed '); // mount the Help menu in topic settings} add_action ('admin _ menu ', 'xz _ theme_options_add_page'); // load the xz_theme_options_add_page function xz_theme_op_page () when loading the background menu () {// The editing page displays the function echo "I Am a topic editing page";} function xz_help () {$ help = 'Here is the content displayed in the help Center <ol> <li> A </li> <li> B </li> <li> C </li> <li> D </li> </ol> '; $ sidebar = 'here is the position to help the right sidebar display '; $ screen = get_current_screen (); // The first main character, get the object $ screen-> add_help_tab (array (// use the member method to register the help Tab 'title' => 'xiang subtopic help ', // The Name Of The left sidebar tag 'id' => 'Theme-options-help', // do not explain 'content' => $ help, // set the content of the tag); $ screen-> set_help_sidebar ($ sidebar); // The method can only be used once, and the last call prevails .}

Effect
If there is no accident, after the above ups and downs, you have to have a preliminary help interface on the topic.
Click position

Customize the Help button location

As shown in figure

Custom help

Summary
Set_help_sidebar () // The method can only be used once. The last call prevails. Here you can add something like your api address or advertisement.
The add_help_tab () method can be used multiple times. Each time a tag is used, there will be one more. Of course, you need to set the corresponding $ help value.

Articles you may be interested in:
  • Use of PHP functions for debugging thumbnails in WordPress
  • Detailed description of PHP functions that call comment templates and output comments cyclically in WordPress
  • PHP function parsing for writing custom storage fields in WordPress
  • Describes the PHP functions used to create and add filters in WordPress.

Related Article

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.