哪个核心文件负责Gravatars?

时间:2013-11-20 作者:Twifty

我意识到修改核心文件是不受欢迎的,但我坚信WP核心不应该依赖外部链接。在我的情况下,我在中国防火墙后面,gravatar网站被封锁了。这会导致页面加载时间延迟。我有一个补丁,但我想从我的安装中删除它。

3 个回复
最合适的回答,由SO网友:Charles Clarkson 整理而成

我仍然认为Rarst的答案更好,并且没有必要删除核心WordPress文件中的Gravatar链接,但是。。。

您要查找的文件包括:

/wp-admin/credits.php
/wp-admin/options-discussion.php
/wp-content/plugins/akismet/akismet.js
/wp-includes/pluggable.php
/wp-includes/post-template.php
由于您可能需要在每次WordPress更新时执行此操作,因此您可以在WordPress文件中搜索单词“gravatar”。大多数优秀的文本编辑器都可以搜索目录及其子目录中的所有文件。您只需要在PHP和JavaScript文件中搜索。

以下是我得到的结果:

----------------------------------------
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(\'[email protected]\')
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)).
我搜索了WordPress的主干版本。您需要在web服务器上搜索WordPress文件的本地副本。

此搜索表明只有\\wp-admin\\credits.php 文件需要更改。这个get_avatar() 此处未使用函数。为了尽量减少影响,您可以只更改第113行中使用的URL:

$gravatar = is_ssl() ? \'https://secure.gravatar.com/avatar/\' : \'http://0.gravatar.com/avatar/\';
到本地URL:

$gravatar = is_ssl() ? \'https://example.com/avatar/\' : \'http://example.com/avatar/\';

SO网友:Rarst

您只需在中禁用gravatarsSettings > Discussion > Avatar Display.

在技术方面,头像链接由get_avatar(), 它通过相同名称的过滤器传递输出,因此可以很容易地连接到其中,而无需编辑核心文件。

还要注意,整个函数本身是可插入的,这意味着可以通过在插件或主题中重新声明来完全覆盖它:

function get_avatar() {
    return \'\'; // Put your return value here, such as a default image
}
通过将此函数声明放在插件中get_avatar() 将不会被声明,并且您将完全绕过对的外部调用gravatar.com.

SO网友:Sarah Gooding

我可以理解,你不想完全取消对头像的支持。在这种情况下,我建议使用如下插件WP User AvatarSimple Local Avatars. 这将允许你的用户将他们自己的头像上传到你的WordPress站点,而不是使用Gravatar。

结束

相关推荐

How do I accesss gravatar?

在你的档案下的政府里,我怀疑这会发生,我找不到任何与gravatar有关的东西