get_current_screen() inside add_action(‘admin_menu’)

I am successfully using get_current_screen(); to get the post_type to decide whether to manipulate a meta box or not.

I also need to use it in:

Read More
add_action('admin_menu', 'infographicMetaBox');

function infographicMetaBox() {
    // ...
    $screen = get_current_screen();
    if('post' != $screen->post_type)
        return;
    // ...
}

however it doesn’t seem to be available in that hook function (maybe being called to early?).

Related posts

2 comments

  1. I don’t know exactly what you are trying to accomplish but you seem to be dealing with meta boxes. If so there are a number of meta box specific hooks.

    do_action('add_meta_boxes', $post_type, $post);
    do_action('add_meta_boxes_' . $post_type, $post);
    
    do_action('do_meta_boxes', $post_type, 'normal', $post);
    do_action('do_meta_boxes', $post_type, 'advanced', $post);
    do_action('do_meta_boxes', $post_type, 'side', $post);
    

    http://core.trac.wordpress.org/browser/tags/3.5.1/wp-admin/edit-form-advanced.php#L165

    As well as the admin_head* hooks

    do_action("admin_head-$hook_suffix");
    do_action('admin_head');
    

    http://core.trac.wordpress.org/browser/tags/3.5.1/wp-admin/admin-header.php#L68

    All of which run after global $current_screen is set here: http://core.trac.wordpress.org/browser/tags/3.5.1/wp-admin/admin-header.php#L18

Comments are closed.