Detailed explanation of the use of Get_current_screen () function in WordPress development _javascript Skills

Source: Internet
Author: User

The Get_current_screen () function is a function that we rarely use but is super practical, and if you're working on a theme and don't know where the document should be, you should look at the function that started with WordPress 3.0, This function allows us to get a Wp_screen object and use the member method of the object to hang our custom Help menu in the background (the feature is perfected after version 3.3).

If you do not like the study of WordPress is too thorough, then you can now take the soy sauce bottle, go ahead to soy sauce.

Introduction
first of all, Get_current_screen () is very simple, just return an object, so this article mainly describes, get the operation of the object.

Describe

It is simple to use
$screen = Get_current_screen ();
At this point $screen an instantiated object

Application examples
Let's take a simple example where the process code can be shown but may not have any meaning in the timing application, just for example.
Although has been very concise, but still very winding, karma bless you can understand.

 function Xz_theme_options_add_page () {$theme _page = add_theme_page (//////If successful, return the hook label, otherwise return FALSE to variable $theme_page.) ' Theme Settings ',//page Titlee ' theme Settings ',//The name shown in the Background menu ' edit_theme_options ',//Option placement ' theme_options ',//alias, that is, get transfer parameters ' xz_the
 Me_op_page '//display function called by content; if (! $theme _page) return;//build failure then jump out of function add_action ("load-$theme _page", ' xz_help ');//Hang Help menu in Theme Settings add_action (' Admin_m
Enu ', ' xz_theme_options_add_page ');
 
Load Xz_theme_options_add_page function Xz_theme_op_page () {//Edit page display function echo "I am the topic edit Page" when loading the background menu;} function Xz_help () {$help = ' here is the help to display the contents of the middle position <ol><li>A</li><li>B</li> <li>c</l
 
 I><li>d</li></ol> ';
 
 $sidebar = ' Here is the position to help the right-hand column show '; $screen = Get_current_screen ()//first lead, get Object $screen->add_help_tab (//Registration with Member Method help tab ' title ' => ' Xiang sub theme Help ',/
 Left column label name ' ID ' => ' theme-options-help ',//does not explain ' content ' => $help,//set label corresponding content);
$screen->set_help_sidebar ($sidebar);//method can only be used once, whichever is the last call. }

 

Effect
If there is no accident, the above toss, you have the theme of the initial help interface.
Click on the location of the image below

Customize Help Button location

Click on the following figure

customizing Help

Summarize
the Set_help_sidebar ()//method can only be used once, whichever is the last call. Here you can add some of your API addresses or ads or something like that.
Add_help_tab () method can be used more than once, each time the label will be one more, of course, you have to set the corresponding $help value.

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.