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;
}

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;
}

Remove Special Characters From Uploaded Files

This is probably more practical if you deal with a lot of special characters, perhaps in foreign languages. But if you want to make sure particular characters are removed from file name when uploaded, you can. As always, WordPress makes this easy.

add_filter( 'sanitize_file_name_chars', 'add_chars_to_filter', 10, 2 );
function add_chars_to_filter ( $special_chars, $filename_raw ) {
	$special_chars[] = 'e';
	return $special_chars;
}

This particular is example is useless as-is, unless you have something against our favorite vowel ‘e.’

Change the Virtual Robots.txt File

Did you know that WordPress will create a robots.txt file for you – well, sorta…

If you don’t create an actual robots.txt file, WordPress will create a virtual one for you, meaning that if yoursite.com/robots.txt is requested, WordPress will serve up robots.txt page, even though it doesn’t actually exist on your server.

Now that we’ve got that covered. How can you edit your virtual robots file? Easy

add_filter( 'robots_txt', 'robots_mod', 10, 2 );
function robots_mod( $output, $public ) {
	$output .= "Disallow: /topsecret/\n";
	return $output;
}