get_method() ); if ( in_array( $method, [ 'GET', 'HEAD', 'OPTIONS' ], true ) ) { return $result; } $route = (string) $request->get_route(); // AICOM's own REST endpoints (/wp-json/aicom/*) — the MCP entry point. if ( strpos( $route, '/aicom/' ) === 0 ) { return $result; } // This mode stops administration from outside wp-admin — a write signed in by a non-cookie method (JWT, // OAuth, Basic Auth plugins) — never the site's own features (blocking those broke CF7 forms and carts). // Visitors: an anonymous write can only do what any visitor may — submit a form (Contact Form 7 drops // the nonce on purpose), comment, use the WooCommerce cart and checkout — each limited by its own route. if ( ! is_user_logged_in() ) { return $result; } // Signed-in users in their browser: the login cookie. Some routes keep that user signed in without a // wp_rest nonce and guard themselves with their own (WooCommerce Store API — a customer's cart and // checkout); everywhere else WordPress already treats a cookie without a valid nonce as anonymous. $cookie_user = wp_validate_auth_cookie( '', 'logged_in' ); if ( $cookie_user && (int) $cookie_user === get_current_user_id() ) { return $result; } // Gutenberg and wp-admin attach a wp_rest nonce; verify it. $nonce = $request->get_header( 'x_wp_nonce' ); if ( $nonce && wp_verify_nonce( $nonce, 'wp_rest' ) ) { return $result; } return new WP_Error( 'aicom_lockdown_rest_blocked', __( 'REST writes signed in from outside the site are disabled — site is in AICOM-only mode. Use the AICOM MCP endpoint or the wp-admin interface.', 'aicom' ), [ 'status' => 403 ] ); } }