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.

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?

share|improve this question

3 Answers 3

Possibly already answered here : How to set default screen options?

share|improve this answer
    
Thanks, I'll look at that. At first glance I'm not really following what that answer is saying, but hopefully it will answer my question. I'll update once I find out... –  cmcculloh Jun 28 '11 at 17:41

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.

share|improve this answer

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.

share|improve this answer
    
This code from another answer would not make the options stick. Why didn’t you just link to that answer? –  toscho Dec 21 '12 at 9:54
    
Actually i thought to link only.But, then i thought somebody will be unaware of using this code in their own plugin.So, to be clear, i did like that. –  Vijaya Narayanasamy Dec 21 '12 at 10:53

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.