s = AccessIQ_Settings::instance(); add_action( 'accessiq_scheduled_scan', [ $this, 'run_scheduled_scan' ] ); add_action( 'accessiq_settings_saved', [ $this, 'reschedule' ] ); add_filter( 'cron_schedules', [ $this, 'add_schedules' ] ); $this->maybe_schedule(); } public function add_schedules( $schedules ) { $schedules['accessiq_weekly'] = [ 'interval' => WEEK_IN_SECONDS, 'display' => 'Weekly' ]; $schedules['accessiq_monthly'] = [ 'interval' => MONTH_IN_SECONDS, 'display' => 'Monthly' ]; return $schedules; } public function maybe_schedule() { if ( ! $this->s->get( 'schedule_enabled' ) ) return; if ( ! wp_next_scheduled( 'accessiq_scheduled_scan' ) ) { $freq = 'accessiq_' . $this->s->get( 'schedule_freq', 'weekly' ); wp_schedule_event( time(), $freq, 'accessiq_scheduled_scan' ); } } public function reschedule() { wp_clear_scheduled_hook( 'accessiq_scheduled_scan' ); $this->maybe_schedule(); } /** * Run scheduled scan on all published pages. */ public function run_scheduled_scan() { $pages = get_posts( [ 'post_type' => [ 'page', 'post' ], 'posts_per_page' => 20, 'post_status' => 'publish' ] ); foreach ( $pages as $page ) { // Queue scan — actual DOM scan will fire on next admin visit // (server-side full DOM scan requires headless browser; mark pages as pending) update_post_meta( $page->ID, '_accessiq_scan_pending', true ); } // Send notification email $email = $this->s->get( 'notify_email', get_option( 'admin_email' ) ); if ( $email ) { wp_mail( $email, __( 'AccessIQ — Scheduled Scan Queued', 'accessiq' ), /* translators: 1: number of pages, 2: site URL */ sprintf( __( 'A scheduled accessibility scan has been queued for %1$d pages on %2$s.', 'accessiq' ), count( $pages ), home_url() ) ); } } }