昨晚在研究评论结构时,网站右键查看源代码,无意间发现自己的管理员用户名被暴露了…
修复方法
方法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程序都得进行这样的修改。
希望高手能提供更好的方法!
一日程新手WP建站指南(https://www.yiricheng.cn/),为广大编程爱好者提供零基础快速搭建博客网站的方法,分享计算机网络、HTML、CSS、JavaScript、PHP、响应式设计以及Python自动化办公的博客文章,另有各类小工具、电子书、免费教程。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。