0

Just for repetition's sake, I want to do the following: I need to set custom fields and the excerpt metaboxes for WP default Posts post type when a new user is created. I know that by default WP doesn't show them but would like it to. I will be removing the Screen Options tab so the user won't be able to disable them.

I know this question has been asked for different scenarios and I have tried using and changing the code that I found here and on the web that help manipulate this but without much luck (eg: How to set default screen options?). Obviously I've tried on different installs but it doesn't work. Is there another way of doing this?

2
  • I ended up injecting a jquery script into the header and using css to display the metaboxes. However, I will leave this open for another day or so before turning it as an answer. I still think there should be a better way to do this.
    – george.n
    Jul 16, 2012 at 11:24
  • Is this a duplicate of How to activate “custom fields” section in WP3?
    – fuxia
    Jul 28, 2012 at 19:48

1 Answer 1

1
+50

Based on this Answer by t31os.

Here, all meta boxes are being set to invisible, so simply remove from the array the ones that are meant to be visible.

add_action('user_register', 'wpse_58645_set_user_metaboxes');

function wpse_58645_set_user_metaboxes( $user_id ) 
{
    update_user_meta( 
        $user_id, 
        'metaboxhidden_post', 
        array( 
            'authordiv',
            'categorydiv',
            'commentstatusdiv',
            'formatdiv',
            'postcustom',
            'postexcerpt',
            'postimagediv',
            'slugdiv',
            'tagsdiv-post_tag',
            'trackbacksdiv',
        ) 
    );
}

For registered users, running an admin_init only once will do, but this is just the concept:

$blogusers = get_users('blog_id=1');

foreach ( $blogusers as $user ) 
{
    if ( !get_user_meta( $user->ID, 'metaboxhidden_post', true ) ) 
    {
        update_user_meta( $user->ID, 'metaboxhidden_post', $meta_value );
    }
}
1
  • 4
    Anonymous down-votes without explanation should require a comment by default. Its not what you would call constructive feedback. Reeks of someone being too afraid to publicly critique another. Above all, it potentially provides a misleading indication to the validity of the answer and that's not good for anyone.
    – Adam
    Jul 29, 2012 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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