I realize modifying the core files is frowned against but I strongly believe that the WP core SHOULD NOT rely on external links. In my situation, I'm behind the Great Chinese Firewall, the gravatar sites are blocked. This causes a lag in my page load times. I have a patch in place but I'd like to remove it from my install altogether.
4 Answers
I still think Rarst's answer is better and that there is no need to remove Gravatar links in the core WordPress files, but ...
The files you are looking for are:
/wp-admin/credits.php
/wp-admin/options-discussion.php
/wp-content/plugins/akismet/akismet.js
/wp-includes/pluggable.php
/wp-includes/post-template.php
Since you may need to do this every time WordPress updates, you could search the WordPress files for the word 'gravatar'. Most good text editors make it possible to search across all files in a directory and its sub directories. You only need to search in PHP and JavaScript files.
Here is the results I get:
----------------------------------------
Find 'gravatar' in 'C:\WordPress\WordPress\wp-admin\credits.php' (11/19/2013 4:11:29 AM; 11/19/2013 4:11:29 AM):
C:\WordPress\WordPress\wp-admin\credits.php(113): $gravatar = is_ssl() ? 'https://secure.gravatar.com/avatar/' : 'http://0.gravatar.com/avatar/';
C:\WordPress\WordPress\wp-admin\credits.php(149): echo '<img src="' . $gravatar . $person_data[1] . '?s=' . $size . '" class="gravatar" alt="' . esc_attr( $person_data[0] ) . '" /></a>' . "\n\t";
Found 'gravatar' 5 time(s).
----------------------------------------
Find 'gravatar' in 'C:\WordPress\WordPress\wp-admin\options-discussion.php' (11/19/2013 4:11:50 AM; 11/19/2013 4:11:50 AM):
C:\WordPress\WordPress\wp-admin\options-discussion.php(176): <?php // the above would be a good place to link to codex documentation on the gravatar functions, for putting it in themes. anything like that? ?>
C:\WordPress\WordPress\wp-admin\options-discussion.php(221): 'gravatar_default' => __('Gravatar Logo'),
Found 'gravatar' 3 time(s).
----------------------------------------
Find 'gravatar' in 'C:\WordPress\WordPress\wp-content\plugins\akismet\akismet.js' (8/2/2013 9:33:47 AM; 8/2/2013 9:33:47 AM):
C:\WordPress\WordPress\wp-content\plugins\akismet\akismet.js(92): // It changes based on if there is a gravatar present
Found 'gravatar' 1 time(s).
----------------------------------------
Find 'gravatar' in 'C:\WordPress\WordPress\wp-includes\pluggable.php' (11/19/2013 4:12:12 AM; 11/19/2013 4:12:12 AM):
C:\WordPress\WordPress\wp-includes\pluggable.php(1675): $host = 'https://secure.gravatar.com';
C:\WordPress\WordPress\wp-includes\pluggable.php(1678): $host = sprintf( "http://%d.gravatar.com", ( hexdec( $email_hash[0] ) % 2 ) );
C:\WordPress\WordPress\wp-includes\pluggable.php(1680): $host = 'http://0.gravatar.com';
C:\WordPress\WordPress\wp-includes\pluggable.php(1684): $default = "$host/avatar/ad516503a11cd5ca435acc9bb6523536?s={$size}"; // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com')
C:\WordPress\WordPress\wp-includes\pluggable.php(1687): elseif ( !empty($email) && 'gravatar_default' == $default )
C:\WordPress\WordPress\wp-includes\pluggable.php(1689): elseif ( 'gravatar_default' == $default )
Found 'gravatar' 6 time(s).
----------------------------------------
Find 'gravatar' in 'C:\WordPress\WordPress\wp-includes\post-template.php' (11/19/2013 4:12:26 AM; 11/19/2013 4:12:26 AM):
C:\WordPress\WordPress\wp-includes\post-template.php(1357): * @return string gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'.
C:\WordPress\WordPress\wp-includes\post-template.php(1370): $gravatar = get_avatar( $revision->post_author, 24 );
C:\WordPress\WordPress\wp-includes\post-template.php(1379): $gravatar,
Found 'gravatar' 3 time(s).
Search complete, found 'gravatar' 18 time(s). (5 file(s)).
I searched on the trunk version of WordPress. You would need to search on a local copy of the WordPress files on your web server.
This search indicates that only the \wp-admin\credits.php
file needs to be changed. The get_avatar()
function is not used there. To make the least impact, you might just change the urls used in line 113:
$gravatar = is_ssl() ? 'https://secure.gravatar.com/avatar/' : 'http://0.gravatar.com/avatar/';
To urls that are local:
$gravatar = is_ssl() ? 'https://example.com/avatar/' : 'http://example.com/avatar/';
-
2-1 for modifying/removing core files. Pluggable functions are there for a reason. Nov 21, 2013 at 12:57
You can simply disable gravatars in Settings
> Discussion
> Avatar Display
.
On technical side avatar links are produced by get_avatar()
, which passes output through filter of same name and so can be easily hooked into without any need to edit core files.
Also note that whole function itself is pluggable, meaning it can be completely overridden by being redeclared in a plugin or theme:
function get_avatar() {
return ''; // Put your return value here, such as a default image
}
By placing this function declaration in a plugin, the core get_avatar()
will not be declared, and you will have completely bypassed the external call to gravatar.com
.
-
Unfortunatly, avatars have to be completely disabled via settings route. Not what I want. I have already filtered, as mentioned in my post, but this isn't good enough. I want to completely remove anything to do with gravatar.– TwiftyNov 20, 2013 at 20:59
-
1@Waldermort I am not sure why you are set on "completely" and what do you mean by it. Filter allows you to changed output to anything completely arbitrary, so does overriding function with pluggable version.– RarstNov 20, 2013 at 21:18
-
@Rarst this no longer works, it actually causes a Fatal Error: Cannot redeclare get_avatar() (previously declared in /path/wp-includes/pluggable.php:2197)– user2015Aug 10, 2015 at 1:50
-
@Piet I was slightly wrong, theme won't work. Need to do it from mu-plugin or plugin, which are before pluggable include.– RarstAug 10, 2015 at 7:33
-
@Rarst cool to know that it works from mu-plugin level! Alternatively I added the complete filter below.– user2015Aug 10, 2015 at 8:12
I can understand that you don't want to remove support for avatars entirely. In this case, I'd recommend using a plugin such as WP User Avatar or Simple Local Avatars. Those will allow your users to upload their own avatars to your WordPress site instead of using Gravatar.
-
the Gravatars used inside the Dashboard are then still loaded and still causing the pageload to lag, because these calls first have to time out. Same goes for everything loaded from Google (in the Dashboard), such as the Open Sans font. Running sites from inside the GFW (Great FireWall of China) is much more problematic than you think.– user2015Aug 10, 2015 at 1:53
The filter to disable the call to Gravatar.com completely is:
add_filter( 'get_avatar', 'so_disable_gravatars', 10, 2 );
function so_disable_gravatars( $avatar ) {
$avatar = '';
return $avatar;
}