> Argument schemas. */ public static function run_args(): array { return [ 'fresh' => Controller::bool_arg( false ), ]; } /** * Argument schema of `POST /audit/fix/{id}`. * * @return array> Argument schemas. */ public static function fix_args(): array { return [ 'id' => [ 'type' => 'string', 'required' => true, 'pattern' => '^[a-z0-9_]+$', 'maxLength' => 64, 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg', ], ]; } /** * Runs the audit. * * @param WP_REST_Request $request The request. * @return array The audit result. */ public function run( WP_REST_Request $request ): array { // A fresh run settles which sitemap address answers on its way past the // flush — see `Runner::run()`, which is the only place that ordering is // safe to decide. return Runner::run( (bool) $request->get_param( 'fresh' ) ); } /** * Applies one fix and re-runs the audit. * * @param WP_REST_Request $request The request. * @return array|WP_Error Keys `fix` and `audit`, or a 400 carrying the reason. */ public function fix( WP_REST_Request $request ) { $result = Fixes::apply( (string) $request->get_param( 'id' ) ); if ( empty( $result['ok'] ) ) { return new WP_Error( 'acid_aeo_fix_failed', (string) ( $result['message'] ?? __( 'The fix could not be applied.', 'acid-aeo' ) ), [ 'status' => 400 ] ); } Controller::forget_derived_data(); return [ 'fix' => $result, 'audit' => Runner::run( true ), ]; } }