get_compact_response_links example


    public function prepare_response_for_collection( $response ) {
        if ( ! ( $response instanceof WP_REST_Response ) ) {
            return $response;
        }

        $data   = (array) $response->get_data();
        $server = rest_get_server();
        $links  = $server::get_compact_response_links( $response );

        if ( ! empty( $links ) ) {
            $data['_links'] = $links;
        }

        return $data;
    }

    /** * Filters a response based on the context defined in the schema. * * @since 4.7.0 * * @param array $response_data Response data to filter. * @param string $context Context defined in the schema. * @return array Filtered response. */

    public function response_to_data( $response$embed ) {
        $data  = $response->get_data();
        $links = self::get_compact_response_links( $response );

        if ( ! empty( $links ) ) {
            // Convert links to part of the data.             $data['_links'] = $links;
        }

        if ( $embed ) {
            $this->embed_cache = array();
            // Determine if this is a numeric array.             if ( wp_is_numeric_array( $data ) ) {
                foreach ( $data as $key => $item ) {
                    
Home | Imprint | This part of the site doesn't use cookies.