disconnect( Accessibit_Api_Client::REVOKE_TIMEOUT ); return 'network_error' !== ( $result['code'] ?? '' ); } } if ( ! function_exists( 'accessibit_delete_options' ) ) { /** * Delete every option the plugin writes, on the current site. * * The option list lives INSIDE a function, and that is the whole point. * WordPress runs this file with `include` from inside * `uninstall_plugin()`, so anything assigned at the top level here is local * to THAT function: a file-scope `$accessibit_options` read back through * `global` resolved to null, the foreach walked nothing, and uninstall left * every option in place. `hardening.spec.ts` and the multisite leg are what * caught it. * * A function rather than a `const` for the same reason one step on: a * function declaration is global wherever the file is included, while a * top-level `const` is too but warns "already defined" if the file is ever * included twice. `function_exists` makes that harmless either way. * * `accessibit_running_job` is the id of a scan this install was watching so * the Accessibility screen could reattach after a reload. */ function accessibit_delete_options(): void { foreach ( array( 'accessibit_settings', 'accessibit_running_job' ) as $accessibit_option ) { delete_option( $accessibit_option ); } // The statement block's lookup throttle (ACC-404), and its pending // cron event: the hook it names is gone with the plugin. delete_transient( 'accessibit_statement_lookup' ); delete_transient( 'accessibit_domain_verification' ); wp_clear_scheduled_hook( 'accessibit_statement_look_up' ); // A Connect started and not finished leaves its state for 30 minutes, // per user (`Accessibit_Admin::CONNECT_STATE_PREFIX`). Only someone who // could press Connect has one: this site's administrators, and on a // network its super admins, who need not be members of it (ACC-411). $accessibit_user_ids = get_users( array( 'capability' => 'manage_options', 'fields' => 'ID', ) ); if ( is_multisite() ) { foreach ( get_super_admins() as $accessibit_login ) { $accessibit_user = get_user_by( 'login', $accessibit_login ); if ( $accessibit_user ) { $accessibit_user_ids[] = $accessibit_user->ID; } } } foreach ( array_unique( array_map( 'intval', $accessibit_user_ids ) ) as $accessibit_user_id ) { delete_transient( 'accessibit_connect_state_' . $accessibit_user_id ); delete_transient( 'accessibit_otp_attempt_' . $accessibit_user_id ); } } } // Every site's options go first and the keys after. Revoking inside the loop // made each site wait on the one before, so on a large network whose requests // were blocked the request timed out partway, leaving the rest with their // options and live keys (ACC-613). $accessibit_revokers = array(); // Settings are per-site options, so on a network install every site in the // network holds its own copy. Walk them in batches rather than loading every // site of a large network at once. if ( is_multisite() ) { $accessibit_offset = 0; do { $accessibit_site_ids = get_sites( array( 'fields' => 'ids', 'number' => 200, 'offset' => $accessibit_offset, ) ); foreach ( $accessibit_site_ids as $accessibit_site_id ) { switch_to_blog( $accessibit_site_id ); // Per site, because the key is per site: every blog on a network // holds its own options row and therefore its own connection. $accessibit_revokers[] = accessibit_revoker(); accessibit_delete_options(); restore_current_blog(); } $accessibit_offset += 200; $accessibit_batch = count( $accessibit_site_ids ); } while ( 200 === $accessibit_batch ); } else { $accessibit_revokers[] = accessibit_revoker(); accessibit_delete_options(); } // From the start of the request, which may have deleted other plugins first. $accessibit_started = isset( $_SERVER['REQUEST_TIME_FLOAT'] ) ? (float) $_SERVER['REQUEST_TIME_FLOAT'] : microtime( true ); $accessibit_web = 'cli' !== PHP_SAPI; $accessibit_unanswered = 0; foreach ( array_filter( $accessibit_revokers ) as $accessibit_revoker ) { if ( ! Accessibit_Api_Client::keep_revoking( $accessibit_unanswered, microtime( true ) - $accessibit_started, $accessibit_web ) ) { break; } $accessibit_unanswered = accessibit_revoke_key( $accessibit_revoker ) ? 0 : $accessibit_unanswered + 1; }