过滤掉 “Comment-Author-” 和 “Author-“
完美方案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 管理员登录用户名被暴露 – 龙笑天下
*
* 说明:直接去掉函数 comment_class() 和 body_class() 中输出的 “comment-author-” 和 “author-“
*/
functionlxtx_remove_comment_body_author_class($content){
$pattern=“/(.*?)([^>]*)author-([^>]*)(.*?)/i”;
$replacement=‘$1$4’;
$content=preg_replace($pattern,$replacement,$content);
return$content;
}
add_filter(‘comment_class’,‘lxtx_remove_comment_body_author_class’);
add_filter(‘body_class’,‘lxtx_remove_comment_body_author_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”
|
20161122:才发现其实老外早在 2010 年就发现了这个漏洞…
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
/**
*(全网独家)如何正确的避免你的 WordPress 管理员登录用户名被暴露 – 龙笑天下
*
* 说明:直接去掉函数 comment_class() 和 body_class() 中输出的 “comment-author-” 和 “author-“
*/
functionlxtx_remove_comment_body_author_class($classes){
foreach($classesas$key=>$class){
if(strstr($class,“comment-author-“)||strstr($class,“author-“)){
unset($classes[$key]);
}
}
return$classes;
}
add_filter(‘comment_class’,‘lxtx_remove_comment_body_author_class’);
add_filter(‘body_class’,‘lxtx_remove_comment_body_author_class’);
|