在没有角色用户的情况下禁用wordpress注释中的链接

问题描述 投票:0回答:1

我们最近决定禁用评论中所有处于活动状态的链接,但我们希望注册用户(作者,编辑者,作者)发布的链接保持活动状态。

我们将此功能添加到functions.php中,但是它已禁用注释中的所有链接,包括我们注册用户发布的链接。

add_filter ('pre_comment_content', 'wp_specialchars'); // disable HTML in comments
remove_filter ('comment_text', 'make_clickable', 9); // autolinks in comments

我们如何禁用所有链接,仅使贡献者,编辑者,作者的链接保持活动状态?

wordpress comments
1个回答
0
投票

如果作者的角色不在您设置的允许角色中,则可以添加自定义功能来剥离标签。

add_filter ('pre_comment_content', 'custom_comments_links'); 

function custom_comments_links($comment_content){
   global $authordata;

   $allowed_roles = array ( 'contributor', 'editor', 'author');
   if(!array_intersect($authordata->roles, $allowed_roles)){
       $comment_content = strip_tags($comment_content, '<p><div><span>');
   }
   return $comment_content;
}

© www.soinside.com 2019 - 2024. All rights reserved.