避免你的wordpress管理员用户名暴露

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

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

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

修复方法

方法1:直接修改Wordpress程序

① 然后,查了下代码,查到了这个函数comment_class(),进一步发现是被这个函数get_comment_class()(大约在wp-includes\comment-template.php 的419行)暴露管理员的登录用户名... 该函数内容如下:

function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
 global $comment_alt, $comment_depth, $comment_thread_alt;
 
 $comment = get_comment($comment_id);
 
 $classes = array();
 
 // Get the comment type (comment, trackback),
 $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
 
 // Add classes for comment authors that are registered users.
 if ( $comment->user_id > 0 && $user = get_userdata( $comment->user_id ) ) {
 $classes[] = 'byuser';
 $classes[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id );
 // For comment authors who are the author of the post
 if ( $post = get_post($post_id) ) {
 if ( $comment->user_id === $post->post_author ) {
 $classes[] = 'bypostauthor';
 }
 }
 }
 
 if ( empty($comment_alt) )
 $comment_alt = 0;

我们的管理员用户名正是被其中的第14行暴露的... 在此,我们只需将这一行中的$user->user_nicename改为$user->user_id即可安全的隐藏管理员的登录名了~ 也隐藏了注册用户的登录用户名了!取而代之显示的是注册用户(包括管理员)的ID。从此再也不用担心网页中会暴露诸位站长的登录用户名了~

然后查到了这个函数body_class(),进一步发现是被这个函数get_body_class()(大约在wp-includes\post-template.php 的634行)暴露管理员的登录用户名... 该函数部分内容如下:

elseif ( is_author() ) {
 $author = $wp_query->get_queried_object();
 $classes[] = 'author';
 if ( isset( $author->user_nicename ) ) {
 $classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID );
 $classes[] = 'author-' . $author->ID;
 }
}

其中该函数的第5行也暴露了博主的登录名,将这一行删掉或注释掉即可成功解决~

友情提示:此方法是直接修改的wordpress的源程序,所以每次更新wordpress程序都得进行这样的修改。希望高手能提供更好的方法!

 

 

阅读全文
 收藏 (0) 打赏

您可以选择一种方式赞助本站

支付宝扫一扫赞助

微信钱包扫描赞助

未经允许不得转载:轻语博客 » 避免你的wordpress管理员用户名暴露
分享到: 生成海报
qux主题真好用,功能强大,界面美观,还一直在更新.....

热门推荐

评论 抢沙发

评论前必须登录!

立即登录   注册

本站承接WordPress主题开发,主题定制,功能开发

QQ咨询轻语云
切换注册

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

切换登录

注册

我们将发送一封验证邮件至你的邮箱, 请正确填写以完成账号注册和激活

微信扫一扫关注
如已关注,请回复“登录”二字获取验证码