rest_get_server

Retrieves the current REST server instance.

Description

(WP_REST_Server) rest_get_server(); 

Instantiates a new instance if none exists already.

Returns (WP_REST_Server)

REST server instance.


Usage

  1. if ( !function_exists( 'rest_get_server' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/vendor/wp-rest-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = rest_get_server(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/vendor/wp-rest-functions.php  
  1. function rest_get_server() { 
  2. /** @var WP_REST_Server $wp_rest_server */ 
  3. global $wp_rest_server; 
  4.  
  5. if ( empty( $wp_rest_server ) ) { 
  6. /** 
  7. * Filter the REST Server Class. 
  8. * This filter allows you to adjust the server class used by the API, using a 
  9. * different class to handle requests. 
  10. * @since 4.4.0 
  11. * @param string $class_name The name of the server class. Default 'WP_REST_Server'. 
  12. */ 
  13. $wp_rest_server_class = apply_filters( 'wp_rest_server_class', 'WP_REST_Server' ); 
  14. $wp_rest_server = new $wp_rest_server_class; 
  15.  
  16. /** 
  17. * Fires when preparing to serve an API request. 
  18. * Endpoint objects should be created and register their hooks on this action rather 
  19. * than another action to ensure they're only loaded when needed. 
  20. * @since 4.4.0 
  21. * @param WP_REST_Server $wp_rest_server Server object. 
  22. */ 
  23. do_action( 'rest_api_init', $wp_rest_server ); 
  24.  
  25. return $wp_rest_server;