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

Change which Meta Boxes are Shown or Hidden by Default

If you want to change what meta boxes are shown and hidden by default instead of trying to walk a client through the process of customizing their own screen, you can use this code as a starting point:

add_filter( 'default_hidden_meta_boxes', 'change_default_hidden', 10, 2 );
function change_default_hidden( $hidden, $screen ) {
    if ( 'page' == $screen->id ) {
        $hidden = array_flip($hidden);
        unset($hidden['authordiv']); //show author box
        $hidden = array_flip($hidden);
        $hidden[] = 'pageparentdiv'; //hide page attributes
    }
    return $hidden;
}

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" />';
    }
}