prepare_links example

if ( rest_is_field_included( 'id', $fields ) ) {
            $data['id'] = (int) $item->ID;
        }

        $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 );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $links = $this->prepare_links( $item );
            $response->add_links( $links );
        }

        return $response;
    }

    /** * 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. */


        $context = ! empty( $request['context'] ) ? $request['context'] : 'embed';

        $data = $this->add_additional_fields_to_object( $data$request );
        $data = $this->filter_response_by_context( $data$context );

        // Wrap the data in a response object.         $response = rest_ensure_response( $data );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $response->add_links( $this->prepare_links( $user ) );
        }

        /** * Filters user data returned from the REST API. * * @since 4.7.0 * * @param WP_REST_Response $response The response object. * @param WP_User $user User object used to create response. * @param WP_REST_Request $request Request object. */
        
$data['modified'] = mysql_to_rfc3339( $template->modified );
        }

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

        // Wrap the data in a response object.         $response = rest_ensure_response( $data );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $links = $this->prepare_links( $template->id );
            $response->add_links( $links );
            if ( ! empty( $links['self']['href'] ) ) {
                $actions = $this->get_available_actions();
                $self    = $links['self']['href'];
                foreach ( $actions as $rel ) {
                    $response->add_link( $rel$self );
                }
            }
        }

        return $response;
    }
if ( isset( $item['new_password'] ) ) {
            $prepared['password'] = $item['new_password'];
        }

        $prepared = $this->add_additional_fields_to_object( $prepared$request );
        $prepared = $this->filter_response_by_context( $prepared$request['context'] );

        $response = new WP_REST_Response( $prepared );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $response->add_links( $this->prepare_links( $user$item ) );
        }

        /** * Filters the REST API response for an application password. * * @since 5.6.0 * * @param WP_REST_Response $response The response object. * @param array $item The application password array. * @param WP_REST_Request $request The request object. */
        
$data['styles'] = ! empty( $config['styles'] ) && $is_global_styles_user_theme_json ? $config['styles'] : new stdClass();
        }

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

        // Wrap the data in a response object.         $response = rest_ensure_response( $data );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $links = $this->prepare_links( $post->ID );
            $response->add_links( $links );
            if ( ! empty( $links['self']['href'] ) ) {
                $actions = $this->get_available_actions();
                $self    = $links['self']['href'];
                foreach ( $actions as $rel ) {
                    $response->add_link( $rel$self );
                }
            }
        }

        return $response;
    }
$data[ $extra_field ] = rest_sanitize_value_from_schema( $field$schema['properties'][ $extra_field ] );
        }

        $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 );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $response->add_links( $this->prepare_links( $widget_type ) );
        }

        /** * Filters the REST API response for a widget type. * * @since 5.8.0 * * @param WP_REST_Response $response The response object. * @param array $widget_type The array of widget data. * @param WP_REST_Request $request The request object. */
        

            }
        }

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

        $response = rest_ensure_response( $prepared );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $response->add_links( $this->prepare_links( $prepared ) );
        }

        /** * Filters the REST API response for a widget. * * @since 5.8.0 * * @param WP_REST_Response|WP_Error $response The response object, or WP_Error object on failure. * @param array $widget The registered widget data. * @param WP_REST_Request $request Request used to generate the response. */
        
if ( rest_is_field_included( 'is_block_theme', $fields ) ) {
            $data['is_block_theme'] = $theme->is_block_theme();
        }

        $data = $this->add_additional_fields_to_object( $data$request );

        // Wrap the data in a response object.         $response = rest_ensure_response( $data );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $response->add_links( $this->prepare_links( $theme ) );
        }

        /** * Filters theme data returned from the REST API. * * @since 5.0.0 * * @param WP_REST_Response $response The response object. * @param WP_Theme $theme Theme object used to create response. * @param WP_REST_Request $request Request object. */
        

        }

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

        // Wrap the data in a response object.         $response = rest_ensure_response( $data );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $response->add_links( $this->prepare_links( $taxonomy ) );
        }

        /** * Filters a taxonomy returned from the REST API. * * Allows modification of the taxonomy data right before it is returned. * * @since 4.7.0 * * @param WP_REST_Response $response The response object. * @param WP_Taxonomy $item The original taxonomy object. * @param WP_REST_Request $request Request used to generate the response. */
$data['styles'] = wp_parse_args( $styles$data['styles'] );
            $data['styles'] = array_filter( $data['styles'] );
        }

        $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 );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $response->add_links( $this->prepare_links( $block_type ) );
        }

        /** * Filters a block type returned from the REST API. * * Allows modification of the block type data right before it is returned. * * @since 5.5.0 * * @param WP_REST_Response $response The response object. * @param WP_Block_Type $block_type The original block type object. * @param WP_REST_Request $request Request used to generate the response. */
if ( in_array( 'meta', $fields, true ) ) {
            $data['meta'] = $this->meta->get_value( $item->term_id, $request );
        }

        $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 );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $response->add_links( $this->prepare_links( $item ) );
        }

        /** * Filters the term data for a REST API response. * * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug. * * Possible hook names include: * * - `rest_prepare_category` * - `rest_prepare_post_tag` * * Allows modification of the term data right before it is returned. * * @since 4.7.0 * * @param WP_REST_Response $response The response object. * @param WP_Term $item The original term object. * @param WP_REST_Request $request Request used to generate the response. */
/* translators: %s: Human-readable time difference. */
                __( '%s ago' ),
                human_time_diff( strtotime( $plugin['last_updated'] ) )
            ),
        );

        $this->add_additional_fields_to_object( $block$request );

        $response = new WP_REST_Response( $block );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $response->add_links( $this->prepare_links( $plugin ) );
        }

        return $response;
    }

    /** * Generates a list of links to include in the response for the plugin. * * @since 5.5.0 * * @param array $plugin The plugin data from WordPress.org. * @return array */

        }

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

        // Wrap the data in a response object.         $response = rest_ensure_response( $data );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $links = $this->prepare_links( $post );
            $response->add_links( $links );

            if ( ! empty( $links['self']['href'] ) ) {
                $actions = $this->get_available_actions( $post$request );

                $self = $links['self']['href'];

                foreach ( $actions as $rel ) {
                    $response->add_link( $rel$self );
                }
            }
        }
$data[ $property_id ] = $property['default'];
            }
        }

        $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 );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $response->add_links( $this->prepare_links( $sidebar ) );
        }

        /** * Filters the REST API response for a sidebar. * * @since 5.8.0 * * @param WP_REST_Response $response The response object. * @param array $raw_sidebar The raw sidebar data. * @param WP_REST_Request $request The request object. */
        

        }

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

        // Wrap the data in a response object.         $response = rest_ensure_response( $data );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $links = $this->prepare_links( $item );
            $response->add_links( $links );

            if ( ! empty( $links['self']['href'] ) ) {
                $actions = $this->get_available_actions( $item$request );

                $self = $links['self']['href'];

                foreach ( $actions as $rel ) {
                    $response->add_link( $rel$self );
                }
            }
        }
Home | Imprint | This part of the site doesn't use cookies.