get_http_origin example



/** * Sends Cross-Origin Resource Sharing headers with API requests. * * @since 4.4.0 * * @param mixed $value Response data. * @return mixed Response data. */
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() ) {
        

function is_allowed_http_origin( $origin = null ) {
    $origin_arg = $origin;

    if ( null === $origin ) {
        $origin = get_http_origin();
    }

    if ( $origin && ! in_array( $originget_allowed_http_origins(), true ) ) {
        $origin = '';
    }

    /** * Change the allowed HTTP origin result. * * @since 3.4.0 * * @param string $origin Origin URL if allowed, empty string if not. * @param string $origin_arg Original origin string passed into is_allowed_http_origin function. */
Home | Imprint | This part of the site doesn't use cookies.