web/wp-includes/http.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
    17  * @since 2.7.0
    17  * @since 2.7.0
    18  * @access private
    18  * @access private
    19  *
    19  *
    20  * @return WP_Http HTTP Transport object.
    20  * @return WP_Http HTTP Transport object.
    21  */
    21  */
    22 function &_wp_http_get_object() {
    22 function _wp_http_get_object() {
    23 	static $http;
    23 	static $http;
    24 
    24 
    25 	if ( is_null($http) )
    25 	if ( is_null($http) )
    26 		$http = new WP_Http();
    26 		$http = new WP_Http();
    27 
    27 
   282 
   282 
   283 /**
   283 /**
   284  * Send Access-Control-Allow-Origin and related headers if the current request
   284  * Send Access-Control-Allow-Origin and related headers if the current request
   285  * is from an allowed origin.
   285  * is from an allowed origin.
   286  *
   286  *
       
   287  * If the request is an OPTIONS request, the script exits with either access
       
   288  * control headers sent, or a 403 response if the origin is not allowed. For
       
   289  * other request methods, you will receive a return value.
       
   290  *
   287  * @since 3.4.0
   291  * @since 3.4.0
   288  *
   292  *
   289  * @return bool|string Returns the origin URL if headers are sent. Returns false
   293  * @return bool|string Returns the origin URL if headers are sent. Returns false
   290  * if headers are not sent.
   294  * if headers are not sent.
   291  */
   295  */
   292 function send_origin_headers() {
   296 function send_origin_headers() {
   293 	$origin = get_http_origin();
   297 	$origin = get_http_origin();
   294 	if ( ! is_allowed_http_origin( $origin ) )
   298 
   295 		return false;
   299 	if ( is_allowed_http_origin( $origin ) ) {
   296 
   300 		@header( 'Access-Control-Allow-Origin: ' .  $origin );
   297 	@header( 'Access-Control-Allow-Origin: ' .  $origin );
   301 		@header( 'Access-Control-Allow-Credentials: true' );
   298 	@header( 'Access-Control-Allow-Credentials: true' );
   302 		if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] )
   299 
   303 			exit;
   300 	return $origin;
   304 		return $origin;
   301 }
   305 	}
       
   306 
       
   307 	if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) {
       
   308 		status_header( 403 );
       
   309 		exit;
       
   310 	}
       
   311 
       
   312 	return false;
       
   313 }