is_store_api_request() ) { return true; } } } // Fallback for older WooCommerce versions and edge execution paths: // Store API requests may be routed either via pretty permalinks (/wp-json/wc/store/...) // or via the rest_route query param (?rest_route=/wc/store/...). // In some internal execution paths, REST_REQUEST may not be set when this code runs, // so we also check the explicit route. $rest_route = ''; if ( isset( $GLOBALS['wp'] ) && is_object( $GLOBALS['wp'] ) && isset( $GLOBALS['wp']->query_vars['rest_route'] ) ) { $rest_route = (string) $GLOBALS['wp']->query_vars['rest_route']; } // phpcs:disable WordPress.Security.NonceVerification.Recommended if ( '' === $rest_route && isset( $_GET['rest_route'] ) ) { $rest_route = sanitize_text_field( wp_unslash( $_GET['rest_route'] ) ); } // phpcs:enable WordPress.Security.NonceVerification.Recommended if ( '' !== $rest_route && false !== strpos( $rest_route, '/wc/store/' ) ) { return true; } if ( ! ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) { return false; } if ( ! isset( $_SERVER['REQUEST_URI'] ) ) { return false; } $request_uri = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ); // Store API routes are under /wc/store/... return false !== strpos( $request_uri, '/wc/store/' ); } }