Disable the Theme and Plugin Editors (and More)

It can be very risky to use the built-in theme and plugin editors – especially it you (or your client) don’t really know what you’re doing. Fortunately we can disable that pretty easily.

define( 'DISALLOW_FILE_EDIT', true );

Or, take it a step further and disable update abilities too

define( 'DISALLOW_FILE_MODS', true );

More Sorting Options for the Media Library

If you work with a lot of PDFs in WordPress, you may find the lack of a “view PDFs” link annoying, especially considering that you can separate image and audio attachments easily.

Fortunately, you can fix that.

add_filter('post_mime_types', 'add_post_mime_type');
function add_post_mime_type( $post_mime_types ) {
	//$post_mime_types['application'] = array(__('Doc'), __('Manage Doc'), _n_noop('Doc <span class="count">(%s)</span>', 'Doc <span class="count">(%s)</span>'));
	$post_mime_types['application/pdf'] = array(__('PDF'), __('Manage PDF'), _n_noop('PDF <span class="count">(%s)</span>', 'PDF <span class="count">(%s)</span>'));
	$post_mime_types['application/msword'] = array(__('DOC'), __('Manage DOC'), _n_noop('DOC <span class="count">(%s)</span>', 'DOC <span class="count">(%s)</span>'));
	return $post_mime_types;
}

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.

Manipulate get_bloginfo() Output

If you want to change the output of anything the get_bloginfo() returns, there’s a couple of filters that make it simple:

(I’m going to leave the practical application brainstorming up to you)

For text:

add_filter( 'bloginfo', 'be_excited', 10, 2 );
function be_excited( $output, $show ) {
    if ( 'name' == $show )
        $output .= ' OMG BBQ!!! FTW';
    return $output;
}

For URLs: change the filter hook to bloginfo_url

Change “Register” Link to “Sign Up”

Very similar to a previous post about the “Log In” links, but for the “Register” link. If you think your users would be more comfortable with different verbiage, then make your users comfortable:

add_filter( 'register', 'reg2sign' );
function reg2sign( $link ) {
	$link = str_replace( '>Register<', '>Sign Up<', $link );
	return $link;
}