Title: rest_send_cors_headers
Published: December 9, 2015
Last modified: August 20, 2026

---

# rest_send_cors_headers( mixed $value ): mixed

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/rest_send_cors_headers/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/rest_send_cors_headers/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/rest_send_cors_headers/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/rest_send_cors_headers/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/rest_send_cors_headers/?output_format=md#changelog)

Sends Cross-Origin Resource Sharing headers with API requests.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/rest_send_cors_headers/?output_format=md#parameters)󠁿

 `$value`mixedrequired

Response data.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/rest_send_cors_headers/?output_format=md#return)󠁿

 mixed Response data.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/rest_send_cors_headers/?output_format=md#source)󠁿

    ```php
    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 = sanitize_url( $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', false );
    	} elseif ( ! headers_sent() && 'GET' === $_SERVER['REQUEST_METHOD'] && ! is_user_logged_in() ) {
    		header( 'Vary: Origin', false );
    	}

    	return $value;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/rest-api.php#L805)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/rest-api.php#L805-L822)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/rest_send_cors_headers/?output_format=md#related)󠁿

| Uses | Description | 
| [get_http_origin()](https://developer.wordpress.org/reference/functions/get_http_origin/)`wp-includes/http.php` |

Gets the HTTP Origin of the current request.

  | 
| [is_user_logged_in()](https://developer.wordpress.org/reference/functions/is_user_logged_in/)`wp-includes/pluggable.php` |

Determines whether the current visitor is a logged in user.

  | 
| [sanitize_url()](https://developer.wordpress.org/reference/functions/sanitize_url/)`wp-includes/formatting.php` |

Sanitizes a URL for database or redirect usage.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/rest_send_cors_headers/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/rest_send_cors_headers/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/rest_send_cors_headers/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Frest_send_cors_headers%2F)
before being able to contribute a note or feedback.