WordPress函数:get_current_screen 获取当前屏幕对象

江河/ 2023年11月07日/ WordPress/ 浏览 769

函数原型:


get_current_screen(): WP_Screen|null


获取当前屏幕对象


函数源码:


function get_current_screen() {
	global $current_screen;

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

	return $current_screen;
}


使用举例:


    /**
     * Check whether the get_current_screen function exists
     * because it is loaded only after 'admin_init' hook.
     */
    if ( function_exists( 'get_current_screen' ) ) {
        $current_screen = get_current_screen();
        // Do your thing.
    }


文件名,screen id 对应关系:


PAGE               $SCREEN_ID           FILE

-----------------  -------------------  -----------------------

Media Library      upload               upload.php

Comments           edit-comments        edit-comments.php

Tags               edit-post_tag        edit-tags.php

Plugins            plugins              plugins.php

Links              link-manager         link-manager.php

Users              users                users.php

Posts              edit-post            edit.php

Pages              edit-page            edit.php

Edit Site: Themes  site-themes-network  network/site-themes.php

Themes             themes-network       network/themes

Users              users-network        network/users

Edit Site: Users   site-users-network   network/site-users

Sites              sites-network        network/sites


发表评论

暂无评论,抢个沙发...

客服 工单