Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a function for getting a list of registered Meta Boxes and removing them? I see there is a method for adding, and removing.

http://codex.wordpress.org/Function_Reference/remove_meta_box

http://codex.wordpress.org/Function_Reference/add_meta_box

share|improve this question
1  
Please roll back your changes and ask a new question instead of just adding to an existing one. Getting screen options is very different than getting meta boxes. –  EAMann Jun 26 '12 at 20:24
add comment

2 Answers 2

up vote 3 down vote accepted

Not really, but you can define your own. All meta boxes are stored in the global variable $wp_meta_boxes which is a multi-dimensional array.

function get_meta_boxes( $screen = null, $context = 'advanced' ) {
    global $wp_meta_boxes;

    if ( empty( $screen ) )
        $screen = get_current_screen();
    elseif ( is_string( $screen ) )
        $screen = convert_to_screen( $screen );

    $page = $screen->id;

    return $wp_meta_boxes[$page][$context];          
}

This array will show all of the meta boxes registered for a specific screen and a specific context. You could also drill down even further because this array is also a multidimensional array that segregates meta boxes by priority and id.


So let's say you want to get an array that contains all of the meta boxes that are of "normal" priority on the admin Dashboard. You'd call the following:

$dashboard_boxes = get_meta_boxes( 'dashboard', 'normal' );

This is identical to the global array $wp_meta_boxes['dashboard']['normal'] and it also a multi-dimensional array.

Removing core meta boxes

Let's say you want to remove a bunch of meta boxes. The function above can be tweaked slightly to avail that:

function remove_meta_boxes( $screen = null, $context = 'advanced', $priority = 'default', $id ) {
    global $wp_meta_boxes;

    if ( empty( $screen ) )
        $screen = get_current_screen();
    elseif ( is_string( $screen ) )
        $screen = convert_to_screen( $screen );

    $page = $screen->id;

    unset( $wp_meta_boxes[$page][$context][$priority][$id] );
}

If you wanted to remove, say, the incoming links widget from the Dashboard, you'd call:

remove_meta_boxes( 'dashboard', 'normal', 'core', 'dashboard_incoming_links' );
share|improve this answer
add comment

On the WordPress Dashboard, there are meta boxes displayed. There is a normal column, and a side column.

I am able to obtain a list of registered meta boxes and remove them from the dashboard by using the following code:

// Remove some non-sense meta boxes
function remove_dashboard_meta_boxes(){
    global $wp_meta_boxes;
    // Dashboard core widgets :: Left Column
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
    // Additional dashboard core widgets :: Right Column
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
    // Remove the welcome panel
    update_user_meta(get_current_user_id(), 'show_welcome_panel', false);
}
add_action('wp_dashboard_setup', 'remove_dashboard_meta_boxes');

Just use print_r($wp_meta_boxes); to see a list of registered meta boxes.

share|improve this answer
1  
This code does not provide a list of available meta boxes. –  toscho Jun 26 '12 at 21:16
    
@toscho It does if you print_r($wp_meta_boxes); –  Michael Ecklund Jun 26 '12 at 23:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.