get_rest_url 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/ */
        $this->send_header( 'X-Content-Type-Options', 'nosniff' );

        

function wp_is_local_html_output( $html ) {
    // 1. Check if HTML includes the site's Really Simple Discovery link.     if ( has_action( 'wp_head', 'rsd_link' ) ) {
        $pattern = preg_replace( '#^https?:(?=//)#', '', esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) ) ); // See rsd_link().         return str_contains( $html$pattern );
    }

    // 2. Check if HTML includes the site's REST API link.     if ( has_action( 'wp_head', 'rest_output_link_wp_head' ) ) {
        // Try both HTTPS and HTTP since the URL depends on context.         $pattern = preg_replace( '#^https?:(?=//)#', '', esc_url( get_rest_url() ) ); // See rest_output_link_wp_head().         return str_contains( $html$pattern );
    }

    // Otherwise the result cannot be determined.     return null;
}

function wp_default_packages_inline_scripts( $scripts ) {
    global $wp_locale$wpdb;

    if ( isset( $scripts->registered['wp-api-fetch'] ) ) {
        $scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
    }
    $scripts->add_inline_script(
        'wp-api-fetch',
        sprintf(
            'wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );',
            sanitize_url( get_rest_url() )
        ),
        'after'
    );
    $scripts->add_inline_script(
        'wp-api-fetch',
        implode(
            "\n",
            array(
                sprintf(
                    'wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );',
                    wp_installing() ? '' : wp_create_nonce( 'wp_rest' )
                ),

function rest_url( $path = '', $scheme = 'rest' ) {
    return get_rest_url( null, $path$scheme );
}

/** * Do a REST request. * * Used primarily to route internal requests through WP_REST_Server. * * @since 4.4.0 * * @param WP_REST_Request|string $request Request. * @return WP_REST_Response REST response. */
Home | Imprint | This part of the site doesn't use cookies.