rest_url example


    protected function prepare_links( $location ) {
        $base = sprintf( '%s/%s', $this->namespace, $this->rest_base );

        // Entity meta.         $links = array(
            'self'       => array(
                'href' => rest_url( trailingslashit( $base ) . $location->name ),
            ),
            'collection' => array(
                'href' => rest_url( $base ),
            ),
        );

        $locations = get_nav_menu_locations();
        $menu      = isset( $locations[ $location->name ] ) ? $locations[ $location->name ] : 0;
        if ( $menu ) {
            $path = rest_get_route_for_term( $menu );
            if ( $path ) {
                

        do_action( 'rest_after_insert_nav_menu_item', $nav_menu_item$request, true );

        $post = get_post( $nav_menu_item_id );
        wp_after_insert_post( $post, false, null );

        $response = $this->prepare_item_for_response( $post$request );
        $response = rest_ensure_response( $response );

        $response->set_status( 201 );
        $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $nav_menu_item_id ) ) );

        return $response;
    }

    /** * Updates a single nav menu item. * * @since 5.9.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */
'sendToEditor'           => wp_create_nonce( 'media-send-to-editor' ),
            'setAttachmentThumbnail' => wp_create_nonce( 'set-attachment-thumbnail' ),
        ),
        'post'              => array(
            'id' => 0,
        ),
        'defaultProps'      => $props,
        'attachmentCounts'  => array(
            'audio' => ( $show_audio_playlist ) ? 1 : 0,
            'video' => ( $show_video_playlist ) ? 1 : 0,
        ),
        'oEmbedProxyUrl'    => rest_url( 'oembed/1.0/proxy' ),
        'embedExts'         => $exts,
        'embedMimes'        => $ext_mimes,
        'contentWidth'      => $content_width,
        'months'            => $months,
        'mediaTrash'        => MEDIA_TRASH ? 1 : 0,
        'infiniteScrolling' => ( $infinite_scrolling ) ? 1 : 0,
    );

    $post = null;
    if ( isset( $args['post'] ) ) {
        $post             = get_post( $args['post'] );
        

    public static function from_url( $url ) {
        $bits         = parse_url( $url );
        $query_params = array();

        if ( ! empty( $bits['query'] ) ) {
            wp_parse_str( $bits['query']$query_params );
        }

        $api_root = rest_url();
        if ( get_option( 'permalink_structure' ) && str_starts_with( $url$api_root ) ) {
            // Pretty permalinks on, and URL is under the API root.             $api_url_part = substr( $urlstrlen( untrailingslashit( $api_root ) ) );
            $route        = parse_url( $api_url_part, PHP_URL_PATH );
        } elseif ( ! empty( $query_params['rest_route'] ) ) {
            // ?rest_route=... set directly.             $route = $query_params['rest_route'];
            unset( $query_params['rest_route'] );
        }

        $request = false;
        
__( 'The page number requested is larger than the number of pages available.' ),
                array( 'status' => 400 )
            );
        }

        $response = rest_ensure_response( $posts );

        $response->header( 'X-WP-Total', (int) $total_posts );
        $response->header( 'X-WP-TotalPages', (int) $max_pages );

        $request_params = $request->get_query_params();
        $collection_url = rest_url( rest_get_route_for_post_type_items( $this->post_type ) );
        $base           = add_query_arg( urlencode_deep( $request_params )$collection_url );

        if ( $page > 1 ) {
            $prev_page = $page - 1;

            if ( $prev_page > $max_pages ) {
                $prev_page = $max_pages;
            }

            $prev_link = add_query_arg( 'page', $prev_page$base );
            $response->link_header( 'prev', $prev_link );
        }
if ( in_array( 'date_floating', $fields, true ) ) {
            $data['date_floating'] = $status->date_floating;
        }

        $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
        $data    = $this->add_additional_fields_to_object( $data$request );
        $data    = $this->filter_response_by_context( $data$context );

        $response = rest_ensure_response( $data );

        $rest_url = rest_url( rest_get_route_for_post_type_items( 'post' ) );
        if ( 'publish' === $status->name ) {
            $response->add_link( 'archives', $rest_url );
        } else {
            $response->add_link( 'archives', add_query_arg( 'status', $status->name, $rest_url ) );
        }

        /** * Filters a post status returned from the REST API. * * Allows modification of the status data right before it is returned. * * @since 4.7.0 * * @param WP_REST_Response $response The response object. * @param object $status The original post status object. * @param WP_REST_Request $request Request used to generate the response. */

    protected function prepare_links( $prepared ) {
        $id_base = ! empty( $prepared['id_base'] ) ? $prepared['id_base'] : $prepared['id'];

        return array(
            'self'                      => array(
                'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $prepared['id'] ) ),
            ),
            'collection'                => array(
                'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
            ),
            'about'                     => array(
                'href'       => rest_url( sprintf( 'wp/v2/widget-types/%s', $id_base ) ),
                'embeddable' => true,
            ),
            'https://api.w.org/sidebar' => array(
                'href' => rest_url( sprintf( 'wp/v2/sidebars/%s/', $prepared['sidebar'] ) ),
            ),
        );
'Cache-Control' => 'no-cache',
            'X-WP-Nonce'    => wp_create_nonce( 'wp_rest' ),
        );
        /** This filter is documented in wp-includes/class-wp-http-streams.php */
        $sslverify = apply_filters( 'https_local_ssl_verify', false );

        // Include Basic auth in loopback requests.         if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) {
            $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) );
        }

        $url = rest_url( 'wp/v2/types/post' );

        // The context for this is editing with the new block editor.         $url = add_query_arg(
            array(
                'context' => 'edit',
            ),
            $url
        );

        $r = wp_remote_get( $urlcompact( 'cookies', 'headers', 'timeout', 'sslverify' ) );

        
/** * Prepares the links for the request. * * @since 6.3.0 * * @param WP_Post $post the Navigation Menu post object. * @return array Links for the given request. */
    private function prepare_links( $post ) {
        return array(
            'self' => array(
                'href'       => rest_url( rest_get_route_for_post( $post->ID ) ),
                'embeddable' => true,
            ),
        );
    }
}
/** * Prepares links for the sidebar. * * @since 5.8.0 * * @param array $sidebar Sidebar. * @return array Links for the given widget. */
    protected function prepare_links( $sidebar ) {
        return array(
            'collection'               => array(
                'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
            ),
            'self'                     => array(
                'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $sidebar['id'] ) ),
            ),
            'https://api.w.org/widget' => array(
                'href'       => add_query_arg( 'sidebar', $sidebar['id']rest_url( '/wp/v2/widgets' ) ),
                'embeddable' => true,
            ),
        );
    }

    

    protected function prepare_links( $id ) {
        $base = sprintf( '%s/%s', $this->namespace, $this->rest_base );

        $links = array(
            'self' => array(
                'href' => rest_url( trailingslashit( $base ) . $id ),
            ),
        );

        if ( post_type_supports( $this->post_type, 'revisions' ) ) {
            $revisions                = wp_get_latest_revision_id_and_total_count( $id );
            $revisions_count          = ! is_wp_error( $revisions ) ? $revisions['count'] : 0;
            $revisions_base           = sprintf( '/%s/%d/revisions', $base$id );
            $links['version-history'] = array(
                'href'  => rest_url( $revisions_base ),
                'count' => $revisions_count,
            );
        }

    protected function prepare_links( WP_User $user$item ) {
        return array(
            'self' => array(
                'href' => rest_url(
                    sprintf(
                        '%s/users/%d/application-passwords/%s',
                        $this->namespace,
                        $user->ID,
                        $item['uuid']
                    )
                ),
            ),
        );
    }

    
'rest_search_invalid_page_number',
                __( 'The page number requested is larger than the number of pages available.' ),
                array( 'status' => 400 )
            );
        }

        $response = rest_ensure_response( $results );
        $response->header( 'X-WP-Total', $total );
        $response->header( 'X-WP-TotalPages', $max_pages );

        $request_params = $request->get_query_params();
        $base           = add_query_arg( urlencode_deep( $request_params )rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );

        if ( $page > 1 ) {
            $prev_link = add_query_arg( 'page', $page - 1, $base );
            $response->link_header( 'prev', $prev_link );
        }
        if ( $page < $max_pages ) {
            $next_link = add_query_arg( 'page', $page + 1, $base );
            $response->link_header( 'next', $next_link );
        }

        return $response;
    }
/** * Prepares links for the request. * * @since 5.7.0 * * @param WP_Theme $theme Theme data. * @return array Links for the given block type. */
    protected function prepare_links( $theme ) {
        $links = array(
            'self'       => array(
                'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $theme->get_stylesheet() ) ),
            ),
            'collection' => array(
                'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
            ),
        );

        if ( $this->is_same_theme( $themewp_get_theme() ) ) {
            // This creates a record for the active theme if not existent.             $id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
        } else {
            $user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme );
            

    protected function prepare_links( $term ) {
        $links = parent::prepare_links( $term );

        $locations = $this->get_menu_locations( $term->term_id );
        foreach ( $locations as $location ) {
            $url = rest_url( sprintf( 'wp/v2/menu-locations/%s', $location ) );

            $links['https://api.w.org/menu-location'][] = array(
                'href'       => $url,
                'embeddable' => true,
            );
        }

        return $links;
    }

    /** * Prepares a single term for create or update. * * @since 5.9.0 * * @param WP_REST_Request $request Request object. * @return object Prepared term data. */
Home | Imprint | This part of the site doesn't use cookies.