WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Платформа для конвертации и монетизации трафика
функция не описана

WP_REST_Block_Directory_Controller::prepare_item_for_response() public WP 5.5.0

Parse block metadata for a block, and prepare it for an API repsonse.

{} Это метод класса: WP_REST_Block_Directory_Controller{}

Хуков нет.

Возвращает

WP_Error/WP_REST_Response. Response object on success, or WP_Error object on failure.

Использование

$WP_REST_Block_Directory_Controller = new WP_REST_Block_Directory_Controller();
$WP_REST_Block_Directory_Controller->prepare_item_for_response( $plugin, $request );
$plugin(массив) (обязательный)
The plugin metadata.
$request(WP_REST_Request) (обязательный)
Request object.

Список изменений

С версии 5.5.0 Введена.

Код WP_REST_Block_Directory_Controller::prepare_item_for_response() WP 5.5.3

<?php
public function prepare_item_for_response( $plugin, $request ) {
	// There might be multiple blocks in a plugin. Only the first block is mapped.
	$block_data = reset( $plugin['blocks'] );

	// A data array containing the properties we'll return.
	$block = array(
		'name'                => $block_data['name'],
		'title'               => ( $block_data['title'] ? $block_data['title'] : $plugin['name'] ),
		'description'         => wp_trim_words( $plugin['description'], 30, '...' ),
		'id'                  => $plugin['slug'],
		'rating'              => $plugin['rating'] / 20,
		'rating_count'        => intval( $plugin['num_ratings'] ),
		'active_installs'     => intval( $plugin['active_installs'] ),
		'author_block_rating' => $plugin['author_block_rating'] / 20,
		'author_block_count'  => intval( $plugin['author_block_count'] ),
		'author'              => wp_strip_all_tags( $plugin['author'] ),
		'icon'                => ( isset( $plugin['icons']['1x'] ) ? $plugin['icons']['1x'] : 'block-default' ),
		'last_updated'        => gmdate( 'Y-m-d\TH:i:s', strtotime( $plugin['last_updated'] ) ),
		'humanized_updated'   => sprintf(
			/* 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 );
	$response->add_links( $this->prepare_links( $plugin ) );

	return $response;
}