$request Submitted fields, i.e. $_POST. * @return bool|WP_Error True when flipped, otherwise why not. */ public function toggle( array $request ): bool|WP_Error { if ( ! current_user_can( 'manage_options' ) ) { return new WP_Error( 'shiftora_debug_forbidden', __( 'You do not have permission to change this setting.', 'shiftora' ) ); } if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( (string) ( $request['_wpnonce'] ?? '' ) ) ), self::NONCE_ACTION ) ) { return new WP_Error( 'shiftora_debug_forbidden', __( 'This request could not be verified. Please reload the page and try again.', 'shiftora' ), [ 'status' => 403 ] ); } $next = ! ShiftoraDebug::enabled(); // Stored as '0' rather than deleted so the option is always visibly set. update_option( ShiftoraDebug::OPTION, $next ? '1' : '0' ); ShiftoraDebug::flush(); return true; } }