get_queue()->is_enabled() || Tasks::is_scheduled( self::ACTION ) !== false ) { return; } // Schedule the task. $this->recurring( strtotime( 'now' ), DAY_IN_SECONDS ) ->unique() ->register(); } /** * Perform email sending. * * @since 4.0.0 */ public function process() { $queue = wp_mail_smtp()->get_queue(); $attachments = new Attachments(); // Cleanup processed emails. $queue->cleanup(); // Cleanup older-than-a-month attachments. $attachments->delete_attachments( null, new DateTime( '1 month ago', new DateTimeZone( 'UTC' ) ) ); if ( ! $queue->is_enabled() ) { // If the query has been disabled in the meanwhile, // and there aren't any emails left, // cancel the cleanup task. $queued_emails_count = $queue->count_queued_emails(); $processed_emails_count = $queue->count_processed_emails(); if ( $queued_emails_count === 0 && $processed_emails_count === 0 ) { // Cleanup any remaining, older-than-an-hour attachments. $attachments->delete_attachments( null, new DateTime( '1 hour ago', new DateTimeZone( 'UTC' ) ) ); $this->cancel_force(); } } } }