Add Links to the Admin Bar

It can be really useful to add some custom links to the Admin Bar. Like, perhaps to the hidden-yet-awesome options.php page.

add_action( 'admin_bar_menu', 'additional_admin_bar_menu', 70 );
function additional_admin_bar_menu( $wp_admin_bar ) {
    if ( current_user_can('manage_options') )
    $wp_admin_bar->add_menu( array( 'id' => 'all-settings', 'title' => __('All Settings'), 'href' => admin_url('options.php') ) );
}

If you want to add a sub-menu item, you must add a “parent” parameter, and its value should match the ID of the parent element.

add_action( 'admin_bar_menu', 'additional_admin_bar_menu_child', 70 );
function additional_admin_bar_menu_child( $wp_admin_bar ) {
        $wp_admin_bar->add_menu( array( 'parent' => 'all-settings', 'id' => 'google', 'title' => __('Google'), 'href' => 'http://google.com' ) );
}

Override Rich Edit Setting

It’s very easy to override the user-selected rich edit setting. Whether they’ve selected to show it or hide it, it can be reversed in a single line of code:

Always show:

add_filter( 'user_can_richedit', '__return_true' );

Always hide:

add_filter( 'user_can_richedit', '__return_false' );

Of course, if you’re going to overwrite this setting, it would make sense to also hide the user’s checkbox for this option.

add_action( 'admin_print_styles-profile.php', 'hide_rich_edit_option' );
add_action( 'admin_print_styles-user-edit.php', 'hide_rich_edit_option' );
function hide_rich_edit_option() {
    ?><style type="text/css">
    label[for=rich_editing] input { display: none; }
    label[for=rich_editing]:before { content: 'This option has been disabled (Formerly: ' }
    label[for=rich_editing]:after { content: ')'; }
    </style><?php
}

You can probably remove it more fully with Javascript, but I’ll leave that up to you.

Swap Color Schemes When Switching Between Network and Site Admins

I wanted to find a way to make it just a little bit more obvious when I switched between the network and site admins. But I didn’t want to have to do a lot of actual customizing. So using built in styles, I found I could just swap the color schemes.

add_action( 'admin_print_styles', 'admin_color_swap', 99 );
function admin_color_swap() {
    if ( is_network_admin() ) {
        global $current_user;
        get_currentuserinfo();
        $selected = $current_user->admin_color;
        $swapped = array( 'fresh' => 'classic', 'classic' => 'fresh' );
        $new = $swapped[$selected];        
        echo '<link rel="stylesheet" type="text/css" href="/wp-admin/css/colors-'.$new.'.css" />';
    }
}