WordPress开发者和主题制作者的搜索引擎



rest_send_cors_headers ›

Since4.4.0
已弃用n/a
rest_send_cors_headers ( $value )
参数:
  • (mixed) $value Response data.
    Required: Yes
返回:
  • (mixed) Response data.
定义在:
文档:

Sends Cross-Origin Resource Sharing headers with API requests.



源码

function rest_send_cors_headers( $value ) {
	$origin = get_http_origin();

	if ( $origin ) {
		// Requests from file:// and data: URLs send "Origin: null"
		if ( 'null' !== $origin ) {
			$origin = esc_url_raw( $origin );
		}
		header( 'Access-Control-Allow-Origin: ' . $origin );
		header( 'Access-Control-Allow-Methods: OPTIONS, GET, POST, PUT, PATCH, DELETE' );
		header( 'Access-Control-Allow-Credentials: true' );
		header( 'Vary: Origin' );
	}

	return $value;
}