set_current_screen example



$hook_suffix = '';
if ( isset( $page_hook ) ) {
    $hook_suffix = $page_hook;
} elseif ( isset( $plugin_page ) ) {
    $hook_suffix = $plugin_page;
} elseif ( isset( $pagenow ) ) {
    $hook_suffix = $pagenow;
}

set_current_screen();

// Handle plugin admin pages. if ( isset( $plugin_page ) ) {
    if ( $page_hook ) {
        /** * Fires before a particular screen is loaded. * * The load-* hook fires in a number of contexts. This hook is for plugin screens * where a callback is provided when the screen is registered. * * The dynamic portion of the hook name, `$page_hook`, refers to a mixture of plugin * page information including: * 1. The page type. If the plugin page is registered as a submenu page, such as for * Settings, the page type would be 'settings'. Otherwise the type is 'toplevel'. * 2. A separator of '_page_'. * 3. The plugin basename minus the file extension. * * Together, the three parts form the `$page_hook`. Citing the example above, * the hook name used would be 'load-settings_page_pluginbasename'. * * @see get_plugin_page_hook() * * @since 2.1.0 */

global $title$hook_suffix$current_screen$wp_locale$pagenow,
    $update_title$total_update_count$parent_file$typenow;

// Catch plugins that include admin-header.php before admin.php completes. if ( empty( $current_screen ) ) {
    set_current_screen();
}

get_admin_page_title();
$title = strip_tags( $title );

if ( is_network_admin() ) {
    /* translators: Network admin screen title. %s: Network title. */
    $admin_title = sprintf( __( 'Network Admin: %s' )get_network()->site_name );
} elseif ( is_user_admin() ) {
    /* translators: User dashboard screen title. %s: Network title. */
    $admin_title = sprintf( __( 'User Dashboard: %s' )get_network()->site_name );
}


/** * Set the current screen object * * @since 3.0.0 * * @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen, * or an existing screen object. */
function set_current_screen( $hook_name = '' ) {
    WP_Screen::get( $hook_name )->set_current_screen();
}
/** * Handles dashboard widgets via AJAX. * * @since 3.4.0 */
function wp_ajax_dashboard_widgets() {
    require_once ABSPATH . 'wp-admin/includes/dashboard.php';

    $pagenow = $_GET['pagenow'];
    if ( 'dashboard-user' === $pagenow || 'dashboard-network' === $pagenow || 'dashboard' === $pagenow ) {
        set_current_screen( $pagenow );
    }

    switch ( $_GET['widget'] ) {
        case 'dashboard_primary':
            wp_dashboard_primary();
            break;
    }
    wp_die();
}

/** * Handles Customizer preview logged-in status via AJAX. * * @since 3.4.0 */

    public function admin_body_classes( $classes ) {
        if ( ! $this->switch_should_render() ) {
            return $classes;
        }

        global $current_screen;
        if ( empty( $current_screen ) ) {
            set_current_screen();
        }

        if ( $current_screen->is_block_editor() ) {
            $should_respect_color_scheme = get_theme_mod( 'respect_user_color_preference', false );
            $background_color            = get_theme_mod( 'background_color', 'D1E4DD' );

            if ( $should_respect_color_scheme && Twenty_Twenty_One_Custom_Colors::get_relative_luminance_from_hex( $background_color ) > 127 ) {
                $classes .= ' twentytwentyone-supports-dark-theme';
            }
        }

        
Home | Imprint | This part of the site doesn't use cookies.