namespace WPForms\Tasks\Actions;
* Class EntryEmailsMetaCleanupTask.
class EntryEmailsMetaCleanupTask extends Task {
* Action name for this task.
const ACTION = 'wpforms_process_entry_emails_meta_cleanup';
public function __construct() {
parent::__construct( self::ACTION );
* Initialize the task with all the proper checks.
// Register the action handler.
$tasks = wpforms()->obj( 'tasks' );
$email_async = wpforms_setting( 'email-async' );
// Add new if none exists.
if ( $tasks->is_scheduled( self::ACTION ) !== false ) {
// Cancel scheduled action if email async option is not set.
// Do not schedule action if email async option is not set.
// phpcs:disable WPForms.PHP.ValidateHooks.InvalidHookName
* Filters the email cleanup task interval.
* @param int $interval Interval in seconds.
$interval = (int) apply_filters( 'wpforms_tasks_entry_emails_meta_cleanup_interval', DAY_IN_SECONDS );
// phpcs:enable WPForms.PHP.ValidateHooks.InvalidHookName
$this->recurring( strtotime( 'tomorrow' ), $interval )
private function hooks() {
add_action( self::ACTION, [ $this, 'process' ] );
* Perform the cleanup action: remove outdated meta for entry emails task.
* @param int $meta_id ID for meta information for a task.
public function process( $meta_id ) {
$meta = $task_meta->get( (int) $meta_id );
// We should actually receive something.
if ( empty( $meta ) || empty( $meta->data ) ) {
list( $interval ) = $meta->data;
$task_meta->clean_by( EntryEmailsTask::ACTION, (int) $interval );