Skip to content

Instantly share code, notes, and snippets.

@Zodiac1978
Last active July 12, 2020 20:06
Show Gist options
  • Save Zodiac1978/ea33dea19cd533d33a6bac2b13b46b2e to your computer and use it in GitHub Desktop.
Save Zodiac1978/ea33dea19cd533d33a6bac2b13b46b2e to your computer and use it in GitHub Desktop.
Comments blocked by the blocklist should be spam and not trash. Companion plugin for Antispam Bee.
<?php
/**
* Plugin Name: Blocklist to spam
* Description: Comments blocked by the blocklist should be spam and not trash.
* Plugin URI: https://torstenlandsiedel.de
* Version: 1.0
* Author: Torsten Landsiedel
* Author URI: http://torstenlandsiedel.de
* Licence: GPL 2
* License URI: http://opensource.org/licenses/GPL-2.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Comments blocked by the blocklist should be spam and not trash.
*
* @param int|string|WP_Error $approved The approval status. Accepts 1, 0, 'spam', 'trash', or WP_Error.
* @param array $commentdata Comment data.
* @return int|string|WP_Error The approval status. Accepts 1, 0, 'spam', 'trash', or WP_Error.
*/
function move_blocklist_from_trash_to_spam( $approved, $commentdata ) {
// If the approval status is trash, then change to spam.
if ( 'trash' === $approved ) {
$approved = 'spam';
}
return $approved;
}
add_filter( 'pre_comment_approved', 'move_blocklist_from_trash_to_spam', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment