143 | | /** @var WP_REST_Server $wp_rest_server */ |
144 | | global $wp_rest_server; |
145 | | |
146 | | /** |
147 | | * Filter the REST Server Class. |
148 | | * |
149 | | * This filter allows you to adjust the server class used by the API, using a |
150 | | * different class to handle requests. |
151 | | * |
152 | | * @since 4.4.0 |
153 | | * |
154 | | * @param string $class_name The name of the server class. Default 'WP_REST_Server'. |
155 | | */ |
156 | | $wp_rest_server_class = apply_filters( 'wp_rest_server_class', 'WP_REST_Server' ); |
157 | | $wp_rest_server = new $wp_rest_server_class; |
158 | | |
159 | | /** |
160 | | * Fires when preparing to serve an API request. |
161 | | * |
162 | | * Endpoint objects should be created and register their hooks on this action rather |
163 | | * than another action to ensure they're only loaded when needed. |
164 | | * |
165 | | * @since 4.4.0 |
166 | | * |
167 | | * @param WP_REST_Server $wp_rest_server Server object. |
168 | | */ |
169 | | do_action( 'rest_api_init', $wp_rest_server ); |
| 143 | // Initialize the server. |
| 144 | $server = rest_get_server(); |
278 | | return $wp_rest_server->dispatch( $request ); |
| 252 | return rest_get_server()->dispatch( $request ); |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Get the current REST server instance. |
| 257 | * |
| 258 | * Instantiates a new instance if none exists already. |
| 259 | * |
| 260 | * @since 4.5.0 |
| 261 | * |
| 262 | * @global WP_REST_Server $wp_rest_server REST server instance. |
| 263 | * |
| 264 | * @return WP_REST_Server REST server instance. |
| 265 | */ |
| 266 | function rest_get_server() { |
| 267 | /* @var WP_REST_Server $wp_rest_server */ |
| 268 | global $wp_rest_server; |
| 269 | |
| 270 | if ( empty( $wp_rest_server ) ) { |
| 271 | /** |
| 272 | * Filter the REST Server Class. |
| 273 | * |
| 274 | * This filter allows you to adjust the server class used by the API, using a |
| 275 | * different class to handle requests. |
| 276 | * |
| 277 | * @since 4.5.0 |
| 278 | * |
| 279 | * @param string $class_name The name of the server class. Default 'WP_REST_Server'. |
| 280 | */ |
| 281 | $wp_rest_server_class = apply_filters( 'wp_rest_server_class', 'WP_REST_Server' ); |
| 282 | $wp_rest_server = new $wp_rest_server_class; |
| 283 | |
| 284 | /** |
| 285 | * Fires when preparing to serve an API request. |
| 286 | * |
| 287 | * Endpoint objects should be created and register their hooks on this action rather |
| 288 | * than another action to ensure they're only loaded when needed. |
| 289 | * |
| 290 | * @since 4.5.0 |
| 291 | * |
| 292 | * @param WP_REST_Server $wp_rest_server Server object. |
| 293 | */ |
| 294 | do_action( 'rest_api_init', $wp_rest_server ); |
| 295 | } |
| 296 | |
| 297 | return $wp_rest_server; |