wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
rest_send_cors_headers › WordPress Function
Seit4.4.0
Veraltetn/v
› rest_send_cors_headers ( $value )
Parameter: |
|
Gibt zurück: |
|
Definiert in: |
|
Codex: |
Sends Cross-Origin Resource Sharing headers with API requests.
Ähnliche Funktionen: rest_send_allow_header, send_origin_headers, register_column_headers, send_nosniff_header, get_column_headers
Quellcode
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; }