get_charset_collate(); $scans = $wpdb->prefix . 'accscan_scans'; dbDelta( "CREATE TABLE $scans ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, started_at datetime NOT NULL, finished_at datetime DEFAULT NULL, status varchar(20) NOT NULL DEFAULT 'running', urls_count int(11) NOT NULL DEFAULT 0, urls_done int(11) NOT NULL DEFAULT 0, score int(11) DEFAULT NULL, counts longtext DEFAULT NULL, PRIMARY KEY (id) ) $charset;" ); $issues = $wpdb->prefix . 'accscan_issues'; dbDelta( "CREATE TABLE $issues ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, scan_id bigint(20) unsigned NOT NULL, rule_id varchar(120) NOT NULL, impact varchar(20) NOT NULL DEFAULT 'moderate', page_url varchar(500) NOT NULL, page_title varchar(300) NOT NULL DEFAULT '', post_type varchar(60) NOT NULL DEFAULT '', target varchar(500) NOT NULL DEFAULT '', html_snippet text DEFAULT NULL, failure_summary text DEFAULT NULL, signature char(32) NOT NULL, PRIMARY KEY (id), KEY scan_id (scan_id), KEY signature (signature) ) $charset;" ); if ( false === get_option( 'accscan_settings', false ) ) { add_option( 'accscan_settings', array( 'post_types' => array( 'page', 'post', 'product' ), 'wcag_level' => 'wcag21aa', 'schedule' => 'off', ) ); } } register_activation_hook( __FILE__, 'accscan_activate' ); /** * Remove the weekly scan event on deactivation. */ function accscan_deactivate() { wp_clear_scheduled_hook( 'accscan_weekly_scan' ); } register_deactivation_hook( __FILE__, 'accscan_deactivate' ); /** * Boot the admin. */ function accscan_boot() { if ( is_admin() ) { AccScan_Admin::instance(); } } add_action( 'plugins_loaded', 'accscan_boot' ); /** * Weekly scheduled scan marker. A full rendered-DOM scan needs a real * browser context, so the cron run records a reminder scan entry that * prompts the admin to run the check from the dashboard. The schedule * exists so site owners build the habit; the scan itself is one click. */ function accscan_cron_reminder() { global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Insert of two fixed values into the plugin's own table; no user input. $wpdb->insert( $wpdb->prefix . 'accscan_scans', array( 'started_at' => current_time( 'mysql' ), 'status' => 'reminder', ), array( '%s', '%s' ) ); } add_action( 'accscan_weekly_scan', 'accscan_cron_reminder' ); /** * Keep the cron schedule in sync with the saved setting. */ function accscan_sync_schedule() { $settings = get_option( 'accscan_settings', array() ); $schedule = isset( $settings['schedule'] ) ? $settings['schedule'] : 'off'; if ( 'weekly' === $schedule ) { if ( ! wp_next_scheduled( 'accscan_weekly_scan' ) ) { wp_schedule_event( time() + WEEK_IN_SECONDS, 'weekly', 'accscan_weekly_scan' ); } } else { wp_clear_scheduled_hook( 'accscan_weekly_scan' ); } } add_action( 'admin_init', 'accscan_sync_schedule' );