send_header example


        $jsonp_enabled = apply_filters( 'rest_jsonp_enabled', true );

        $jsonp_callback = false;
        if ( isset( $_GET['_jsonp'] ) ) {
            $jsonp_callback = $_GET['_jsonp'];
        }

        $content_type = ( $jsonp_callback && $jsonp_enabled ) ? 'application/javascript' : 'application/json';
        $this->send_header( 'Content-Type', $content_type . '; charset=' . get_option( 'blog_charset' ) );
        $this->send_header( 'X-Robots-Tag', 'noindex' );

        $api_root = get_rest_url();
        if ( ! empty( $api_root ) ) {
            $this->send_header( 'Link', '<' . sanitize_url( $api_root ) . '>; rel="https://api.w.org/"' );
        }

        /* * Mitigate possible JSONP Flash attacks. * * https://miki.it/blog/2014/7/8/abusing-jsonp-with-rosetta-flash/ */


    $result = _oembed_create_xml( $data );

    // Bail if there's no XML.     if ( ! $result ) {
        status_header( 501 );
        return get_status_header_desc( 501 );
    }

    if ( ! headers_sent() ) {
        $server->send_header( 'Content-Type', 'text/xml; charset=' . get_option( 'blog_charset' ) );
    }

    echo $result;

    return true;
}

/** * Creates an XML string from a given array. * * @since 4.4.0 * @access private * * @param array $data The original oEmbed response data. * @param SimpleXMLElement $node Optional. XML node to append the result to recursively. * @return string|false XML string on success, false on error. */
return true;
    }

    // Check the nonce.     $result = wp_verify_nonce( $nonce, 'wp_rest' );

    if ( ! $result ) {
        return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie check failed' ), array( 'status' => 403 ) );
    }

    // Send a refreshed nonce in header.     rest_get_server()->send_header( 'X-WP-Nonce', wp_create_nonce( 'wp_rest' ) );

    return true;
}

/** * Collects cookie authentication status. * * Collects errors from wp_validate_auth_cookie for use by rest_cookie_check_errors. * * @since 4.4.0 * * @see current_action() * @global mixed $wp_rest_auth_cookie */
Home | Imprint | This part of the site doesn't use cookies.