热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

PreprocessCommentContentin?WordPress

Iveputagreatamountofeffortintomakingsurethe?commentsystemonthisblogisfast?andfeature-filled.?ThecommentsystemisAJAX-basedsoyoudontneedtoworryaboutpagerefreshes.?YoucanalsopostlinkstoGitHubgists,CodeP

Ive put a great amount of effort into making sure the?comment system on this blog is fast?and feature-filled. ?The comment system is AJAX-based so you dont need to worry about page refreshes. ?You can also post links to GitHub gists, CodeP

I’ve put a great amount of effort into making sure the?comment system on this blog is fast?and feature-filled. ?The comment system is AJAX-based so you don’t need to worry about page refreshes. ?You can also post links to GitHub gists, CodePen pens, and JSFiddle fiddles and see them rendered within the comment. ?Those tasks I accomplish?after a comment has been registered in the?system. ?But what if you want to?modify comment content before it is processed, and subsequently marked as SPAM or scrubbed? ?That’s super easy with WordPress hooks!

The PHP

The preprocess_comment hook allows us to get at the comment data before it is processed. ?Here is how I use this hook, wrapping?`text` strings in elements and encoding angle characters in

?elements:

// Manage comment submissions
function preprocess_new_comment($commentdata) {
	// Replace `code` with code
	$commentdata['comment_content'] = preg_replace("/`(.*)`/Um", "$1", $commentdata['comment_content']);
	// Ensure that code inside pre's is allowed
	preg_match_all("/(.*)<\/pre>/", $commentdata['comment_content'], $pre_matches); // $2
	foreach($pre_matches as $match) {
		$immediate_match = str_replace(array('<', '>'), array('<', '>'), $match[2]);
		$commentdata['comment_content'] = str_replace($match[2], $immediate_match, $commentdata['comment_content']);
	}
	// Return
	return $commentdata;
}
add_action('preprocess_comment', 'preprocess_new_comment');

This snippet?should be added to functions.php, as you would expect of a WordPress theme enhancement.

I love the WordPress hook system &#8212; it makes the CMS incredibly powerful and?customizable. ?I also use this hook to prevent WordPress comment SPAM. ?And since many users place HTML code in my comments, it&#8217;s important?I encode those angle characters properly. ?In the end, you never know what your user will submit and what each site will accept &#8212; use this?WordPress hook to take control!

Read the full article at: Preprocess Comment Content in WordPress

Treehouse
Wufoo

推荐阅读
  • Allegro总结:1.防焊层(SolderMask):又称绿油层,PCB非布线层,用于制成丝网印板,将不需要焊接的地方涂上防焊剂.在防焊层上预留的焊盘大小要比实际的焊盘大一些,其差值一般 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • 在springmvc框架中,前台ajax调用方法,对图片批量下载,如何弹出提示保存位置选框?Controller方法 ... [详细]
  • 本文介绍了前端人员必须知道的三个问题,即前端都做哪些事、前端都需要哪些技术,以及前端的发展阶段。初级阶段包括HTML、CSS、JavaScript和jQuery的基础知识。进阶阶段涵盖了面向对象编程、响应式设计、Ajax、HTML5等新兴技术。高级阶段包括架构基础、模块化开发、预编译和前沿规范等内容。此外,还介绍了一些后端服务,如Node.js。 ... [详细]
  • 本文介绍了如何使用jQuery和AJAX来实现动态更新两个div的方法。通过调用PHP文件并返回JSON字符串,可以将不同的文本分别插入到两个div中,从而实现页面的动态更新。 ... [详细]
  • 本文介绍了DataTables插件的官方网站以及其基本特点和使用方法,包括分页处理、数据过滤、数据排序、数据类型检测、列宽度自动适应、CSS定制样式、隐藏列等功能。同时还介绍了其易用性、可扩展性和灵活性,以及国际化和动态创建表格的功能。此外,还提供了参数初始化和延迟加载的示例代码。 ... [详细]
  • 工作经验谈之-让百度地图API调用数据库内容 及详解
    这段时间,所在项目中要用到的一个模块,就是让数据库中的内容在百度地图上展现出来,如经纬度。主要实现以下几点功能:1.读取数据库中的经纬度值在百度上标注出来。2.点击标注弹出对应信息。3 ... [详细]
  • 前言:关于跨域CORS1.没有跨域时,ajax默认是带cookie的2.跨域时,两种解决方案:1)服务器端在filter中配置详情:http:blog.csdn.netwzl002 ... [详细]
  • 有关phpfgetss()函数的文章推荐10篇
    有关phpfgetss()函数的文章推荐10篇:了解如何使用PHP的各种文件函数。查看诸如fopen、fclose和feof之类的基本文件函数;了解诸如fgets、fgetss和f ... [详细]
  • 导读:在编程的世界里,语言纷繁多样,而大部分真正广泛流行的语言并不是那些学术界的产物,而是在通过自由发挥设计出来的。和那些 ... [详细]
  • 本文内容为asp.net微信公众平台开发的目录汇总,包括数据库设计、多层架构框架搭建和入口实现、微信消息封装及反射赋值、关注事件、用户记录、回复文本消息、图文消息、服务搭建(接入)、自定义菜单等。同时提供了示例代码和相关的后台管理功能。内容涵盖了多个方面,适合综合运用。 ... [详细]
  • 如何实现织梦DedeCms全站伪静态
    本文介绍了如何通过修改织梦DedeCms源代码来实现全站伪静态,以提高管理和SEO效果。全站伪静态可以避免重复URL的问题,同时通过使用mod_rewrite伪静态模块和.htaccess正则表达式,可以更好地适应搜索引擎的需求。文章还提到了一些相关的技术和工具,如Ubuntu、qt编程、tomcat端口、爬虫、php request根目录等。 ... [详细]
  • Monkey《大话移动——Android与iOS应用测试指南》的预购信息发布啦!
    Monkey《大话移动——Android与iOS应用测试指南》的预购信息已经发布,可以在京东和当当网进行预购。感谢几位大牛给出的书评,并呼吁大家的支持。明天京东的链接也将发布。 ... [详细]
  • GetWindowLong函数
    今天在看一个代码里头写了GetWindowLong(hwnd,0),我当时就有点费解,靠,上网搜索函数原型说明,死活找不到第 ... [详细]
author-avatar
蜡烛8882007
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有