Skip to content

Instantly share code, notes, and snippets.

@norcross
Created March 28, 2016 19:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norcross/0a5b72c0ba6c8b16d32c to your computer and use it in GitHub Desktop.
Save norcross/0a5b72c0ba6c8b16d32c to your computer and use it in GitHub Desktop.
Remove user avatars from the admin user table
<?php
add_filter( 'pre_get_avatar', 'rkv_remove_avatar_from_list', 10, 3 );
/**
* Remove the avatars from just the admin user list table.
*
* @param string $avatar HTML for the user's avatar. Default null.
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
* user email, WP_User object, WP_Post object, or WP_Comment object.
* @param array $args Arguments passed to get_avatar_url(), after processing.
*
* @return string An empty string.
*/
function rkv_remove_avatar_from_list( $avatar, $id_or_email, $args ) {
// Do our normal thing on non-admin or our screen function is missing.
if ( ! is_admin() || ! function_exists( 'get_current_screen' ) ) {
return $avatar;
}
// Get my current screen.
$screen = get_current_screen();
// Bail without the object.
if ( empty( $screen ) || ! is_object( $screen ) || empty( $screen->base ) || 'users' !== $screen->base ) {
return $avatar;
}
// Return an empty string.
return '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment