昨晚在研究评论结构时,网站右键查看源代码,无意间发现自己的管理员用户名被暴露了…
修复方法
方法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程序都得进行这样的修改。
希望高手能提供更好的方法!
阅读全文
评论前必须登录!
立即登录 注册