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 <code>preprocess_comment hook allows us to get at the comment data before it is processed. ?here is how i use this hook, wrapping?<code>`text` strings in <code><code> elements and encoding angle characters in <code><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false;"></code>?elements:</p> <pre class="brush:php;toolbar:false;">// 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'); </pre>
全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号