如果你的评论列表li标签里面有comment_class的输出可以使用此方法来修正此安全问题。
因为这个class输出会暴露诸如管理员或注册用户的用户名,引起不必要的安全问题。
以下代码加入到主题的functions.php里面
/**
* Change_comment_or_body_classes
* @ For change username to nicename or userid
* @ inlojv.com / Since Rainbow 1.0.8
*/function inlojv_change_comment_or_body_classes($classes, $comment_id){
global $wp_query;
$comment = get_comment( $comment_id );
$user = get_userdata( $comment->user_id );
$comment_author = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id );
$author = $wp_query->get_queried_object();
$archive_author = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID );
foreach( $classes as $key => $class ) {
switch( $class ) {
case $comment_author:
// $classes[$key] = 'comment-author-' . sanitize_html_class( $comment->comment_author, $comment->user_id );
$classes[$key] = 'comment-author-' . sanitize_html_class( $comment->user_id );
break;
case $archive_author:
// $classes[$key] = 'author-' . sanitize_html_class( get_the_author_meta( 'display_name' ), $author->ID );
$classes[$key] = 'author-' . sanitize_html_class( $author->ID );
break;
}
}
return $classes;}add_filter( 'comment_class', 'inlojv_change_comment_or_body_classes', 10, 4 );add_filter( 'body_class', 'inlojv_change_comment_or_body_classes', 10, 4 );
注:注释的两行代码为昵称替换,不了解可以不理会。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
