Remove IM Fields From Profile Page

Need to declutter the profile options by removing the various IM fields. It’s easy

add_filter('user_contactmethods', 'remove_im_options', 10, 2); 
function remove_im_options( $user_contactmethods, $user ) {
    unset($user_contactmethods['aim']);
    unset($user_contactmethods['yim']);
    unset($user_contactmethods['jabber']);
    //$user_contactmethods = array();
    return $user_contactmethods;
}

Remove Library Tab from Post-Side Media Pop-Up

I’m working on a plugin right now where I’m having to hide or limit a lot of features depending on the current user’s capabilities. Among those limitations is media uploading and editing access. I’m using this snippet to hide the Media Library tab from the Add an Image pop-up on the edit post page.

add_filter('media_upload_tabs','no_library_tab');
function no_library_tab($tabs) {
    if (!current_user_can('promote_users')) { 
        unset($tabs['library']);
    }
    return $tabs;
}

Prevent Option From Being Updated

If you need to hand over the reins to a client, but want to make sure certain options stay unchanged, you can add this code:

add_filter( 'pre_update_option_admin_email', 'prevent_option_change', 10, 2 ); 
function prevent_option_change( $newvalue, $oldvalue ) {
    return $oldvalue;
}

In this case, I’m preserving ‘admin_email’ – just change that part of the filter hook to preserve another option.

Add Extra Content to the Widgets Admin

I don’t have a good example of why you might want or need this, but nevertheless, if you should want to add additional text to the Widgets admin, it’s pretty darn easy:

add_action( 'widgets_admin_page', 'widgets_admin_info' );
function widgets_admin_info() {
    ?>
    <p style="clear:both;">Hello there!!</p>
    <?php
}

Easier Access to Media File from Media Library

Maybe it’s just me, but sometimes I’d link to grab an image’s file URL from the Media Library, but I can’t do it easily. This little snippet will add a link to the ‘row actions’ (“Edit | Delete Permanently | View”) for the File URL (as opposed the the attachment URL you’ll get with the ‘view’ link)

add_filter ('media_row_actions','add_direct_link', 10, 3 );
function add_direct_link( $actions, $post, $detached ) {
	$actions['file_url'] = '<a href="' . wp_get_attachment_url($post->ID) . '">Actual File</a>';
	return $actions;
}

Customize Post Views

Depending on your role and capabilities, you may see something like this on your posts/pages screen “mine () | all () | published ()”

Those items are editable.

In my case, I wanted ‘authors’ to only have access to the ‘mine’ list, since ‘mine’ is default, I wanted to remove the views list entirely, but only for non-administrators.

add_filter('views_edit-post', 'only_show_mine');
function only_show_mine( $views ) {
    if (!current_user_can('promote_users')) {
        $views = array(); //remove all options
        //unset($views['all']);
        //unset($views['publish']);
    }
return $views;
}

Hide Admin Bar

If you’re one of those that don’t love the admin bar, here’s how to disable it, as well as the option to show/hide it.

add_filter('show_admin_bar', '__return_false');
add_action( 'admin_print_scripts-profile.php', 'hide_admin_bar_prefs' );
function hide_admin_bar_prefs() {
    ?><style type="text/css">.show-admin-bar {display:none;}</style><?php 
}