Free & Easy Auto-Updating Spam Filter for WordPress

Wp Settings Filter Spam With Blacklist Txt Updateblacklistwithuserkeyspreserved Snipsnip Pro Code Snippet

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.

What it does…

More specifically, this code fetches an updated blacklist from a URL (https://github.com/splorp/wordpress-comment-blacklist) daily and refreshes the website’s 'disallowed keys' option, which blocks the processing of any keys listed on the blacklist. The function maintains any user-defined keys, allowing site operators to permanently block specific keys.

Why it does it…

This automated approach is particularly beneficial for large sites where certain types of input can be undesirable or potentially harmful. Regular updates improve resistance against spam and harmful content, and also, preserving user-defined blacklist keys ensures that website operators can continually identify specific unwanted inputs.

How it does it…

The PHP class 'UpdateBlacklistWithUserKeysPreserved' is first defined and executed. The default configurations for enabling/disabling the update task and the scheduled update time are set.

  • In the constructor function, the update task is either initiated or canceled based on the $enableTask variable.
  • If the update task is enabled, the schedule_update_event method is triggered to set up a update_disallowed_keys_daily_event, and the update_disallowed_keys function is immediately activated. If the task is disabled, any existing scheduled event for the update_disallowed_keys_daily_event is stopped.
  • The schedule_update_event function sets up a scheduled task (via wp_schedule_event) to trigger a update_disallowed_keys_daily_event action.
  • The update_disallowed_keys function fetches and processes the updated blacklist from the URL, maintains any user-defined keys found in the old list, and finally saves the new list into the disallowed_keys option.

Use the JSON file for easily importing into your CodeSnippetsPro plugin. Use the PHP file or just copy/paste the code sample into your functions.php if you’re not using CodeSnippetsPro.

Related Snips

Leave a Reply

Your email address will not be published. Required fields are marked *