Manage sensitive keywords in WordPress comments involves more than just ensuring safety and respect; it’s also about upholding a space for comments and conversations that is filled with courtesy and quality. Furthermore, safeguarding your website against policy-violating words aids in building a positive impression not only with Google and the cybersecurity community but also in creating a better user experience for everyone who engages.
What are the sensitive keywords in Wordpress comments?
“Sensitive keywords” are words or phrases that have the potential to evoke strong emotions or controversy when used in various contexts. These words are often related to sensitive issues such as politics, religion, gender, race, sexuality, or social issues like ethics and education. Using sensitive keywords can lead to debates, conflicts, or offense to others, so it’s important to use them carefully and consider the context and communication goals.
Therefore, if your website promotes software and includes this keyword, it could be identified by the “CISA” and added to the prohibited list. Similarly, if your website displays Adsense ads, it might be viewed as a violation and consequently barred from showing ads. This explains why we is committed to managing sensitive keywords in WordPress comments.
Another example is that profanity, sexual content, biological references, political opinions, religious discussions, violent content, or racist language can all have a detrimental impact on your brand.
Failure to manage sensitive keywords in WordPress comments can result in a loss of respect and reputation, undermining professionalism and responsibility in the eyes of customers and users. This, in turn, can affect your ability to establish a trustworthy system and forge strong connections in today’s competitive market.
How to Prevent and Encode Sensitive Words in WordPress?
WordPress features a built-in comment management function, accessible through “Settings->Discussion”, where you can input banned words in both “Comment Moderation” and “Disallowed Comment Keys”. This feature is designed to sort comments containing those keywords into a pending approval section, giving you the option to approve or disallow them.
However, we have observed that when dealing with a high volume of comments, the moderation process can become time-consuming. Therefore, I will implement automatic approval for all comments containing terms like “text” and “link”, but I will apply encryption to specific sensitive words. As an illustration, the term “profanity” will be encoded within the WordPress comment as “prof****y”.
To manage sensitive keywords in WordPress comments, we opened the functions.php file and wrote the following code:
add_filter( 'preprocess_comment', 'safe_comment_content');
function safe_comment_content($commentdata) {
$manager = current_user_can('manage_options');
$moderation_keys = get_option('moderation_keys');
if (!$moderation_keys || $manager) {
return $commentdata;
}
$moderation_keys = preg_split('/\r\n|\r|\n|,/', $moderation_keys);
if (isset($commentdata['comment_content'])) {
$comment_content = $commentdata['comment_content'];
foreach ($moderation_keys as $key) {
$key_length = mb_strlen($key, 'UTF-8');
if ($key_length > 2) {
$encoded_key = mb_substr($key, 0, $key_length - 2, 'UTF-8') . '**';
$comment_content = preg_replace('/\b' . preg_quote($key) . '\b/iu', $encoded_key, $comment_content);
}
}
$commentdata['comment_content'] = $comment_content;
}
return $commentdata;
}
This code serves the purpose of encoding words from the “Comment Moderation” list. To make it effective, you should deactivate the ‘”Before a comment appears” feature located in “Settings->Discussion”. This action essentially enables automatic comment approval.
How to Add Forbidden Words and Encrypt Sensitive Keywords
To make the above code effective, we proceed to access “Settings->Discussion->Comment Moderation” and add the words that require control, as shown in the screenshot below:
These keywords will be encrypted within the body of the WordPress comment. The outcome obtained by us is as follows:
Here is a simple way to manage sensitive keywords in WordPress comments, which can be easily done without the need for a plugin. Encrypting sensitive keywords not only helps ensure the security of your website but also contributes to maintaining a respectful and inclusive online community. By taking these measures, you can protect your brand’s reputation and provide a positive user experience for all visitors.
In addition to WordPress’ built-in spam filtering, you can also leverage third-party plugins like Disqus or Vuukle for enhanced comment moderation. For even more options, check out 9+ solutions to prevent spam for WordPress here.