避免暴露你的 WordPress 管理员登录用户名

人生在世,想美好的事情,就会找到快乐,走向成功;想失意的事情,就会走向失望的深渊,无力面对生活和失败。

昨晚在研究评论结构时,网站右键查看源代码,无意间发现自己的管理员用户名被暴露了...

图1 评论中暴露登录用户名

图2 用户页面中也暴露登录用户名

要彻底隐藏用户名,目前需要走两个步骤:

步骤1:将作者存档链接中的用户名更改为用户ID

详细方法可以参看大学之前的文章:https://www.wpdaxue.com/use-user-id-for-author-slug.html

龙笑天下网已经通过这个方法隐藏存档链接中管理员用户名,没想到管理员用户名还是以另一种方式暴露了... 不过还好,非常隐蔽~~然后查看了下其它几个wordpress的博客,他们也全部中招了(话说,各位博主的管理员登录用户名真的好复杂啊!)!看来是 wordpress的通病了!大家赶紧自查下哦~所以看下步骤2。

注:虽然我们还可以将作者归档链接中的用户名改为用户昵称,但是由于我们更多地使用中文作为昵称,会导致链接地址可能出现一些问题,所以不推荐。

步骤2:去除 comment_class() 和body_class()输出的用户名

11月04日经过张戈的提醒和龙砚庭博主文章的提示,得到了一个基本完美的解决方案:也就是将comment_class()函数里输出的comment-author-test10这个class去掉,也将body_class()函数里输出的author-test10这个类似的class去掉。因为这个是通过functions.php来解决的,所以不用担心wordpress程序升级的问题。方法是,将以下代码加入functions.php中,即可完事!

1
2
3
4
5
6
7
8
9
10
11
12
13
/**
 *(全网独家)如何正确的避免你的 WordPress 管理员登录用户名被暴露 - 龙笑天下
 * http://www.ilxtx.com/further-hide-your-wordpress-admin-username.html
 * 说明:直接去掉函数 comment_class() 和 body_class() 中输出的 "comment-author-" 和 "author-"
 */
function lxtx_comment_body_class($content){ 
    $pattern = "/(.*?)([^>]*)author-([^>]*)(.*?)/i";
    $replacement = '$1$4';
    $content = preg_replace($pattern, $replacement, $content);  
    return $content;
}
add_filter('comment_class', 'lxtx_comment_body_class');
add_filter('body_class', 'lxtx_comment_body_class');

/** *(全网独家)如何正确的避免你的 WordPress 管理员登录用户名被暴露 - 龙笑天下 * http://www.ilxtx.com/further-hide-your-wordpress-admin-username.html * 说明:直接去掉函数 comment_class() 和 body_class() 中输出的 "comment-author-" 和 "author-" */ function lxtx_comment_body_class($content){ $pattern = "/(.*?)([^>]*)author-([^>]*)(.*?)/i"; $replacement = '$1$4'; $content = preg_replace($pattern, $replacement, $content); return $content; } add_filter('comment_class', 'lxtx_comment_body_class'); add_filter('body_class', 'lxtx_comment_body_class');

comment_class()body_class()过滤的结果分别是:

1
2
3
4
5
// comment_class()过滤后的结果如下,去掉了原有class里的comment-author-test10,请和上面的图1比较
class="comment byuser  bypostauthor odd alt thread-odd thread-alt depth-1"

// body_class()过滤后的结果如下,去掉了原有class里的author-test10和author-1,请和上面的图2比较
class="archive author  logged-in"

// comment_class()过滤后的结果如下,去掉了原有class里的comment-author-test10,请和上面的图1比较 class="comment byuser bypostauthor odd alt thread-odd thread-alt depth-1" // body_class()过滤后的结果如下,去掉了原有class里的author-test10和author-1,请和上面的图2比较 class="archive author logged-in"

好了,到这里就OK啦!

原文:http://www.ilxtx.com/further-hide-your-wordpress-admin-username.html

本文避免暴露你的 WordPress 管理员登录用户名到此结束。智者总是有成功的密码,能译出密码的人,心是成功的智者。小编再次感谢大家对我们的支持!

您可能有感兴趣的文章
WordPress站点Gravatar头像前后台不显示的如何解决办法

WordPress主题需要支持https吗?WordPress站点如何如何实现https?

WordPress站点的页面/标签/分类URL地址如何添加.html?

WordPress站点更换了域名后数据库应该如何操作替换新旧域名?

WordPress安装在主机空间的什么目录里面?根目录在哪里?