This is a smart automated feature for website operators using WordPress and Code Snippets Pro ❤️ plugin. It allows for daily updates of the 'disallowed keys'
option which essentially forms a blacklist for unwelcome keys while ensuring that user-defined keys are preserved even after updates.
Free & Easy Auto-Updating Spam Filter for WordPress

See the code…
<?php
if (!class_exists('UpdateBlacklistWithUserKeysPreserved')) {
// WP Settings - Filter Spam with blacklist.txt - UpdateBlacklistWithUserKeysPreserved [SnipSnip.pro] - https://snipsnip.pro/s/770
class UpdateBlacklistWithUserKeysPreserved {
// Config: Set to true to enable updating task, false to disable
private $enableTask = true;
// Config: Schedule task to run on following time
private $scheduled_Hour = '4am';
// Divider
private $divider = "\n** Add custom filters above this line. Everything below will be auto-updated daily at ";
public function __construct() {
// Append additional instruction to divider
$this->divider .= $this->scheduled_Hour . ". **\n** This auto-updating feature is controlled by a script in the site's Code Snippets Pro plugin. **"
. "\n** Code from: https://SnipSnip.pro/s/770 -- Blacklist from: https://github.com/splorp/wordpress-comment-blacklist **\n";
if ($this->enableTask) {
add_action('wp', array($this, 'schedule_update_event'));
add_action('update_disallowed_keys_daily_event', array($this, 'update_disallowed_keys'));
$this->update_disallowed_keys(); // run the task immediately
} else {
// Unschedules the scheduled cron job when $enableTask is set to false
if (wp_next_scheduled('update_disallowed_keys_daily_event')) {
wp_clear_scheduled_hook('update_disallowed_keys_daily_event');
}
}
}
// Schedule an action if it's not already scheduled
public function schedule_update_event() {
if (wp_next_scheduled('update_disallowed_keys_daily_event')) {
wp_clear_scheduled_hook('update_disallowed_keys_daily_event');
}
$nextTime = strtotime('next day ' . $this->scheduled_Hour);
wp_schedule_event($nextTime, 'daily', 'update_disallowed_keys_daily_event');
}
// Update 'disallowed_keys' option daily
public function update_disallowed_keys() {
$response = wp_remote_get('https://raw.githubusercontent.com/splorp/wordpress-comment-blacklist/master/blacklist.txt');
if (!is_wp_error($response) && $response['response']['code'] == 200) {
$blacklist = wp_remote_retrieve_body($response);
$old_blacklist = get_option('disallowed_keys', ''); // get old blacklist
$old_blacklist_array = explode($this->divider, $old_blacklist);
// check if old blacklist had user keys
if (count($old_blacklist_array) > 1) {
$user_keys = $old_blacklist_array[0];
$new_blacklist = $user_keys . $this->divider . $blacklist;
} else {
$new_blacklist = $old_blacklist . $this->divider . $blacklist;
}
update_option('disallowed_keys', $new_blacklist);
}
}
}
// Instantiate the class
new UpdateBlacklistWithUserKeysPreserved();
}