^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_current_screen()用法示例

get_current_screen()

Get the current screen object


描述


返回值

(WP_Screen|null) Current screen object or null when screen not defined.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包


源代码

File: wp-admin/includes/screen.php

function get_current_screen() {
	global $current_screen;

	if ( ! isset( $current_screen ) )
		return null;

	return $current_screen;
}

更新日志

Version 描述
3.1.0 Introduced.

相关函数

Used By

  • wp-admin/includes/ajax-actions.php:
    wp_ajax_search_install_plugins()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_search_plugins()
  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::render_view_mode()
  • wp-admin/includes/screen.php:
    add_screen_option()
  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::get()
  • wp-admin/includes/deprecated.php:
    screen_layout()
  • wp-admin/includes/deprecated.php:
    screen_options()
  • wp-admin/includes/deprecated.php:
    screen_meta()
  • wp-admin/includes/dashboard.php:
    wp_add_dashboard_widget()
  • wp-admin/includes/dashboard.php:
    wp_dashboard()
  • wp-admin/includes/dashboard.php:
    wp_dashboard_setup()
  • wp-admin/includes/list-table.php:
    _get_list_table()
  • wp-admin/includes/template.php:
    iframe_header()
  • wp-admin/includes/template.php:
    add_meta_box()
  • wp-admin/includes/template.php:
    do_meta_boxes()
  • wp-admin/includes/template.php:
    remove_meta_box()
  • wp-admin/includes/template.php:
    do_accordion_sections()
  • wp-admin/includes/meta-boxes.php:
    post_comment_meta_box()
  • wp-admin/includes/meta-boxes.php:
    page_attributes_meta_box()
  • wp-admin/custom-header.php:
    Custom_Image_Header::help()
  • wp-admin/custom-background.php:
    Custom_Background::admin_load()
  • wp-includes/functions.php:
    wp_auth_check_load()
  • wp-includes/admin-bar.php:
    wp_admin_bar_edit_menu()
  • Show 18 more used by
    Hide more used by


  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 2You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Another Example:

    
    <?php
    
    add_action( 'current_screen', 'wpdocs_this_screen' );
    
    /**
     * Run code on the admin widgets page
     */
    function wpdocs_this_screen() {
        $currentScreen = get_current_screen();
        if( $currentScreen->id === "widgets" ) {
            // Run some code, only on the admin widgets page
        }
    }
    
    ?>
    
    
  2. This function is useful to figure out which screen you’re on in the Dashboard,

    
    add_action('trashed_post', 'trash_wpcrm_contact');
    function trash_wpcrm_contact($post_id){
        $screen = get_current_screen();
        if('wpcrm-contact' != $screen->post_type){ //this is not our custom post, so let's exit
          return;
        }
        ....
    }
    

    Another useful attribute of the WP_Screen object returned by this function is the $screen->base attribute which is set to 'post' for any custom post edit screen, and is set to 'edit' for the custom post admin table page, which is very handy when loading custom css/scripts for additional function on those pages.

    Default Usage
    This example shows how you would add contextual help to an admin page you’ve created with the add_options_page() function. Here, we assume that your admin page has a slug of my_admin_page and exists under the Options tab.

    The get_current_screen() function is used in this example.

    
    <?php 
    add_action('admin_menu', 'wpdocs_admin_add_page');
    
    /**
     * Add an admin page
     */
    function wpdocs_admin_add_page() {
    	global $wpdocs_admin_page;
    	$wpdocs_admin_page = add_options_page(__('Wpdocs Admin Page', 'wpdocs_textdomain'),
    		__('Wpdocs Admin Page', 'wpdocs_textdomain'),
    		'manage_options', 'wpdocs_textdomain', 'wpdocs_admin_page');
    
    	// Adds my_help_tab when my_admin_page loads
    	add_action('load-'.$wpdocs_admin_page, 'wpdocs_admin_add_help_tab');
    }
    
    /**
     * Add a contextual help tab to the Wpdocs Admin Page
     */
    function wpdocs_admin_add_help_tab () {
        global $wpdocs_admin_page;
        $screen = get_current_screen();
    
        /*
         * Check if current screen is Wpdocs Admin Page
         * Don't add help tab if it's not
         */
        if ( $screen->id != $wpdocs_admin_page )
            return;
    
        // Add my_help_tab if current screen is My Admin Page
        $screen->add_help_tab( array(
            'id' => 'wpdocs_help_tab',
            'title' => __('Wpdocs Help Tab'),
            'content' => '<p>'
    		. __( 'Descriptive content that will show in Wpdocs Help Tab body goes here.', 'wpdocs_textdomain' )
    		. '</p>',
        ) );
    }
    ?>
    
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈