[wp-hackers] Closed Metaboxes

Nathan Rice ncrice at gmail.com
Tue Apr 13 03:44:55 UTC 2010

Perfect. This should definitely help. Thanks!

Nathan Rice
WordPress and Web Development
www.nathanrice.net | twitter.com/nathanrice

On Mon, Apr 12, 2010 at 1:50 PM, rovo89 <lists at robv.de> wrote:

> Is there any way to have custom metaboxes be closed by default?
> Closed metaboxes are handled by the function postbox_classes(), which has
> not filters itself. However, it uses get_user_option(), so you can do the
> following:
> function myclosedmetaboxes($result) {
>    $closedMetaboxes = array('your_closed_metabox');
>    if ( !is_array(result) )
>        return $closedMetaboxes;
>    else
>        return array_merge($result, $closedMetaboxes);
> }
> add_filter('get_user_option_closedpostboxes_yourposttype',
> 'myclosedmetaboxes');
> yourposttype is the same as the $page parameter of add_meta_box. The array
> defines the metaboxes which are always closed when the user enters the
> editing page.
> If you want to be a bit more user friendly and keep the open/closed state
> of the metaboxes, just return $result instead of the merged array. The
> metabox will then be hidden by default for new users, but if the expand
> them, they will stay expanded. For existing users for who the open/closed
> state was already saved, the metabox will be visible by default because it
> is not in the returned array (which would also be the case if they had
> expanded it themselves). You could query all users who have these settings
> saved and add your metabox to it once to work around this.
> I hope this helps.
> Robert
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list