wordpress允许投稿_在WordPress注释中允许更多HTML标签

wordpress允许投稿

WordPress allows a select few HTML tags within the content of post comments.  This is an awesome feature, of course, because it prevents XSS security holes and other malicious code from being injected by spammers, hackers, and jerks.  Unfortunately there are many other tags that bloggers may want to support;  for example, tech bloggers may want to support PRE tags so commenters can post code.  Luckily it's quite easy to allow more tags within your WordPress comments:

WordPress允许在评论内容中选择一些HTML标记。 当然,这是一个了不起的功能,因为它可以防止XSS安全漏洞和其他恶意代码被垃圾邮件发送者,黑客和抽搐者注入。 不幸的是,博客作者可能还希望支持许多其他标签。 例如,科技博客作者可能希望支持PRE标签,以便评论者可以发布代码。 幸运的是,在WordPress注释中允许添加更多标签非常容易:


// Create function which allows more tags within comments
function allow_pres() {
	global $allowedtags;
	$allowedtags['pre'] = array('class'=>array());
}

// Add WordPress hook to use the function
add_action('comment_post', 'allow_pres');


The global $allowedtags variable holds an array of allowed comment tags, so adding the pre key will allow PRE elements within comments.  The class key within the pre array allows the class attribute for any PRE tags posted within the comment, so not only can you allow additional HTML tags, but you can also specify allowed attributes too!  This function is added to the comment_post hook (same hook that AJAX comments use) so as to only add desired tags when a comment is posted.

全局$allowedtags变量包含允许的注释标签数组,因此添加pre键将允许在注释内使用PRE元素。 pre数组中的class键允许注释中发布的任何PRE标签的class属性,因此,您不仅可以允许其他HTML标签,还可以指定允许的属性! 该函数被添加到comment_post挂钩(与AJAX注释使用的挂钩相同),以便仅在发布注释时添加所需的标签。

翻译自: https://davidwalsh.name/wordpress-comment-tags

wordpress允许投稿

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值