rest_send_cors_headers

Sends Cross-Origin Resource Sharing headers with API requests.

Description

rest_send_cors_headers( (mixed) $value ); 

Parameters (1)

0. $value (mixed)
Response data.

Usage

  1. if ( !function_exists( 'rest_send_cors_headers' ) ) { 
  2. require_once ABSPATH . WPINC . '/rest-api.php'; 
  3.  
  4. // Response data. 
  5. $value = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = rest_send_cors_headers($value); 
  9.  

Defined (1)

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

/wp-includes/rest-api.php  
  1. function rest_send_cors_headers( $value ) { 
  2. $origin = get_http_origin(); 
  3.  
  4. if ( $origin ) { 
  5. header( 'Access-Control-Allow-Origin: ' . esc_url_raw( $origin ) ); 
  6. header( 'Access-Control-Allow-Methods: OPTIONS, GET, POST, PUT, PATCH, DELETE' ); 
  7. header( 'Access-Control-Allow-Credentials: true' ); 
  8. header( 'Vary: Origin' ); 
  9.  
  10. return $value;