WordPress.org

Support

Support » Plugins and Hacks » Hacks » How to remove Browse Happy widget from WP 3.2 dashboard

How to remove Browse Happy widget from WP 3.2 dashboard

  • If you’re not using your browser’s latest version, WP 3.2+ will show you a special notice in the dashboard. This is fine, but in some cases you may want to hide it (i.e. in a client’s website). This is how you do it (paste it in a plugin or in your theme’s functions.php file):

    function remove_browse_happy() {
       global $wp_meta_boxes;
       unset($wp_meta_boxes['dashboard']['normal']['high']['dashboard_browser_nag']);
    }
    add_action('wp_dashboard_setup', 'remove_browse_happy');

    You can also remove more dashboard widgets this way. If you don’t have enough data to use the unset function, you can try with remove_meta_box:

    function remove_dashboard_widgets() {
       global $wp_meta_boxes;
       unset($wp_meta_boxes['dashboard']['normal']['high']['dashboard_browser_nag']); //Browse Happy
       remove_meta_box( 'dashboard_right_now', 'dashboard', 'core' ); //Right now
       unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); //Recent comments
       unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); //Incoming links
       remove_meta_box( 'dashboard_plugins', 'dashboard', 'core' ); //Plugins
       remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' ); //QuickPress
       remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' ); //Recent drafts
       remove_meta_box( 'dashboard_primary', 'dashboard', 'side' ); //Official WordPress blog
       remove_meta_box( 'dashboard_secondary', 'dashboard', 'side' ); //Other WordPress news
       //This also works for widgets inserted by plugins
       remove_meta_box( 'icl_dashboard_widget', 'dashboard', 'side' ); //WPML
       remove_meta_box( 'w3tc_pagespeed', 'dashboard', 'core' ); //W3 Total Cache
    }
    add_action('wp_dashboard_setup', 'remove_dashboard_widgets');

    You can improve this by hiding widgets from non-admins only:

    function remove_dashboard_widgets() {
       global $current_user;
       //This is hidden from everyone
       if ($current_user->user_level < 8) {
          //This is hidden from non-administrators
       }
    }
    add_action('wp_dashboard_setup', 'remove_dashboard_widgets');

    Or, if you’re running Multisite, you can put this code in a must-use plugin (mu-plugins folder) and use it to hide widgets from specific sites:

    function remove_dashboard_widgets() {
       global $blog_id;
       //This is hidden from everyone
       if ($blog_id != 15) {
          //This is hidden from all sites but the one with ID 15
       }
       //Main blog has to be checked differently
       if (!is_main_blog()) {
       //This is hidden from all sites but the main one
       }
    }
    add_action('wp_dashboard_setup', 'remove_dashboard_widgets');

    As you see, you can play with this a lot.

    Hope it helps!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Brilliant!
    Thank you for that.

    One thing :

    ‘User Levels were finally deprecated in version 3.0. ‘

    http://codex.wordpress.org/Roles_and_Capabilities#User_Levels

    How about:

    if ( current_user_can( 'administrator' ) ) {
        // whatever
    }

    That’s not better unfortunately, current_user_can should take(and was intended to take) a capability, not a role name, despite the fact it works.

    You’re right about user levels.

    According to the function reference, current_user_can may take a role as a parameter. But in order to achieve the same thing using capabilities, we could do something like this:

    if (current_user_can('manage_network')) {
       //whatever
    }
    
    if (current_user_can('activate_plugins')) {
       //whatever
    }

    In the examples, we assume manage_network is a superadmin capability and activate_plugins is a site admin capability. We could replace those two with any other which suit the specific needs of the case.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to remove Browse Happy widget from WP 3.2 dashboard’ is closed to new replies.
Skip to toolbar