Make item checked by default for all users in “Screen Options” pane

When you are in the dashboard, the options checked and unchecked in the “Screen Options” pane seem to me to be completely random and arbitrary and cause lots of confusion when something doesn’t show up that you need that “should” be there but isn’t. Is there some way to influence which of these options are checked, and make that stick for all users?

Related posts

Leave a Reply

3 comments

  1. mike23’s link gives the hint to the following function:

    // add_action('user_register', 'wpse20505_set_user_metaboxes');
    add_action('admin_init', 'wpse20505_set_user_metaboxes');
    function wpse20505_set_user_metaboxes($user_id=NULL) {
        $meta_key['hidden'] = 'metaboxhidden_dashboard';
        $meta_value = array(
            'dashboard_incoming_links',
            'dashboard_plugins',
            'dashboard_primary',
            'dashboard_quick_press',
            'dashboard_recent_comments',
            'dashboard_recent_drafts',
            'dashboard_right_now',
            'dashboard_secondary'
        );
        $blogusers = get_users('blog_id=1');
        foreach ($blogusers as $user) {
            // this conditional will check if the user already set his preferences and may be removed if wanted
            if ( ! get_user_meta( $user->ID, $meta_key['hidden'], true) ) {
                update_user_meta( $user->ID, $meta_key['hidden'], $meta_value );
            }
        }
    }
    

    The admin_init need to be run only once, and then user_register may be enabled to configure the dashboard for new users.

    The meta_value array contains all the widgets and may be customized to your needs.

  2. 1) Copy this codes and paste it in your editor and save it as enable_custom_field.php. Then, create a folder named “Enable Custom Field By Default” and put that PHP file in this folder. Like this, your created with your own plugin. Just put this folder in your plugin folder and activate it in your admin page.

    <?php 
    /* 
    Plugin Name: Enable Custom Fields per Default
    Version:     1.0
    Required:    3.1
    Author:      Thomas Scholz
    Author URI:  http://toscho.de
    License:     GPL
    */
    ! defined( 'ABSPATH' ) and exit;
    add_filter( 'default_hidden_meta_boxes', 'enable_custom_fields_per_default', 20, 1 );
    
    /**
     * Removes custom fields from the default hidden elements.
     *
     * The original ( wp-admin/includes/template.php#get_hidden_meta_boxes() ):
     * array(
     *      'slugdiv',
     *      'trackbacksdiv',
     *      'postcustom',      <-- we need this
     *      'postexcerpt',
     *      'commentstatusdiv',
     *      'commentsdiv',
     *      'authordiv',
     *      'revisionsdiv'
     * )
     *
     * It has no effect if the user has decided to hide the box.
     * This option is saved in "metaboxhidden_{$screen->id}"
     *
     * @param  array $hidden
     * @return array $hidden
     */
    function enable_custom_fields_per_default( $hidden )
    {
        foreach ( $hidden as $i => $metabox )
        {
            if ( 'postcustom' == $metabox )
            {
                unset ( $hidden[$i] );
            }
        }
        return $hidden;
    }
    ?>
    

    2) I have tried this one by creating new user in my admin page and logged in with that user. Custom fields are there in my page’s edit section. It worked like a charm.