query( $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared "DELETE FROM {$table} WHERE captured_at < DATE_SUB(UTC_TIMESTAMP(), INTERVAL %d DAY)", $days ) ); return (int) $deleted; } /** * Schedule the daily prune event. * * Safe to call on re-activation — no-op when already scheduled. * Side effects: Adds a WP-Cron daily event. * * @return void */ public static function schedule(): void { if ( ! wp_next_scheduled( self::PRUNE_HOOK ) ) { wp_schedule_event( time(), 'daily', self::PRUNE_HOOK ); } } /** * Remove the prune cron schedule. * * Called on deactivation and uninstall. * Side effects: Removes the WP-Cron event. * * @return void */ public static function clear_schedule(): void { $timestamp = wp_next_scheduled( self::PRUNE_HOOK ); if ( false !== $timestamp ) { wp_unschedule_event( $timestamp, self::PRUNE_HOOK ); } wp_clear_scheduled_hook( self::PRUNE_HOOK ); } }