namespace WPForms\Tasks\Actions;
class PurgeSpamTask extends Task {
* Action name for this task.
const ACTION = 'wpforms_process_purge_spam';
protected $log_title = 'Purge Spam';
public function __construct() {
parent::__construct( self::ACTION );
* Filter the interval for the purge spam task, in seconds.
* @param int $interval Interval in seconds.
$this->interval = (int) apply_filters( 'wpforms_tasks_actions_purge_spam_task_interval', DAY_IN_SECONDS );
$this->tasks = wpforms()->obj( 'tasks' );
// Do not add a new one if scheduled.
if ( $this->tasks->is_scheduled( self::ACTION ) !== false ) {
if ( $this->interval <= 0 ) {
public function hooks() {
add_action( self::ACTION, [ $this, 'process' ] );
private function add_scan_task() {
if ( $this->interval <= 0 ) {
$this->tasks->create( self::ACTION )
->recurring( time(), $this->interval )
public function process() {
$entry_obj = wpforms()->obj( 'entry' );
$entry_obj->purge_spam();
$this->log( 'Purge spam completed.' );