Removing meta-boxes from the post/page admin screens
I use WP as a framework for CMS applications.
i have long wanted to be able to remove some of the more obscure meta boxes from the post/page admin screens, for certain installations. Prompted by an immediate need, I came up with the following. Currently there is no admin screen, the user will have to remove items from the $boxes array in order to keep them on the page.
I will submit this to wp.org for better peer-review but for the moment, here you go …
<?php /* Plugin Name: removeMetaBoxes Plugin URI: http://rathercurious.net Description: Allows core meta boxes to be removed Author: Justin Adie Version: 1.0 Author URI: http://rathercurious.net */ class removeMetas{ public function __construct(){ add_action('do_meta_boxes', array($this, 'removeMetaBoxes'), 10, 3); } public function removeMetaBoxes($type, $context, $post){ /** * usages * remove_meta_box($id, $page, $context) * add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default') */ $boxes = array( 'slugdiv', 'postexcerpt', 'passworddiv', 'categorydiv', 'tagsdiv', 'trackbacksdiv', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv', 'postcustom'); foreach ($boxes as $box){ foreach (array('link', 'post', 'page') as $page){ foreach (array('normal', 'advanced', 'side') as $context){ remove_meta_box($box, $type, $context); } } } } } $removeMetas = new removeMetas(); ?> |
Excellent little plugin. You should market this to WordPress MU users as well, as one I wanted the ability to hide options from other users.
Really excellent.
I’ll throw in my cents: it would make sense, if the (planned) interface was able to remove metaboxes added by plugins, too. E.g. I use mappress to add some Google maps, but the client doesn’t need to see its interface on every post or page, just because i don’t want to hardcode those maps into a template for every page that needs one.
Anyway, thanks a lot!
the problem is that we don’t know what the other metaboxes are called. i’ll play around to see whether i could build an options page to display those plugins that _want_ to put their metabox on the post screen. the issue is whether there is a hook at the right moment to nip it in the bud.
i’m swamped at the moment, so don’t expect anything in the near future!
i see, no problem. as this is of more interest for admins than end-users, i think looking for the ids with firebug and pasting them to a a text field would suffice.