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

WP_REST_Themes_Controller::prepare_item_for_response() public WP 5.0.0

Prepares a single theme output for response.

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

Хуки из метода
Возвращает

WP_REST_Response. Response object.

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

$WP_REST_Themes_Controller = new WP_REST_Themes_Controller();
$WP_REST_Themes_Controller->prepare_item_for_response( $theme, $request );
$theme(WP_Theme) (обязательный)
Theme object.
$request(WP_REST_Request) (обязательный)
Request object.

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

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

Код WP_REST_Themes_Controller::prepare_item_for_response() WP 5.5.3

<?php
public function prepare_item_for_response( $theme, $request ) {
	$data   = array();
	$fields = $this->get_fields_for_response( $request );

	if ( rest_is_field_included( 'stylesheet', $fields ) ) {
		$data['stylesheet'] = $theme->get_stylesheet();
	}

	if ( rest_is_field_included( 'template', $fields ) ) {
		/**
		 * Use the get_template() method, not the 'Template' header, for finding the template.
		 * The 'Template' header is only good for what was written in the style.css, while
		 * get_template() takes into account where WordPress actually located the theme and
		 * whether it is actually valid.
		 */
		$data['template'] = $theme->get_template();
	}

	$plain_field_mappings = array(
		'requires_php' => 'RequiresPHP',
		'requires_wp'  => 'RequiresWP',
		'textdomain'   => 'TextDomain',
		'version'      => 'Version',
	);

	foreach ( $plain_field_mappings as $field => $header ) {
		if ( rest_is_field_included( $field, $fields ) ) {
			$data[ $field ] = $theme->get( $header );
		}
	}

	if ( rest_is_field_included( 'screenshot', $fields ) ) {
		// Using $theme->get_screenshot() with no args to get absolute URL.
		$data['screenshot'] = $theme->get_screenshot() ? $theme->get_screenshot() : '';
	}

	$rich_field_mappings = array(
		'author'      => 'Author',
		'author_uri'  => 'AuthorURI',
		'description' => 'Description',
		'name'        => 'Name',
		'tags'        => 'Tags',
		'theme_uri'   => 'ThemeURI',
	);

	foreach ( $rich_field_mappings as $field => $header ) {
		if ( rest_is_field_included( "{$field}.raw", $fields ) ) {
			$data[ $field ]['raw'] = $theme->display( $header, false, true );
		}

		if ( rest_is_field_included( "{$field}.rendered", $fields ) ) {
			$data[ $field ]['rendered'] = $theme->display( $header );
		}
	}

	if ( rest_is_field_included( 'theme_supports', $fields ) ) {
		foreach ( get_registered_theme_features() as $feature => $config ) {
			if ( ! is_array( $config['show_in_rest'] ) ) {
				continue;
			}

			$name = $config['show_in_rest']['name'];

			if ( ! rest_is_field_included( "theme_supports.{$name}", $fields ) ) {
				continue;
			}

			if ( ! current_theme_supports( $feature ) ) {
				$data['theme_supports'][ $name ] = $config['show_in_rest']['schema']['default'];
				continue;
			}

			$support = get_theme_support( $feature );

			if ( isset( $config['show_in_rest']['prepare_callback'] ) ) {
				$prepare = $config['show_in_rest']['prepare_callback'];
			} else {
				$prepare = array( $this, 'prepare_theme_support' );
			}

			$prepared = $prepare( $support, $config, $feature, $request );

			if ( is_wp_error( $prepared ) ) {
				continue;
			}

			$data['theme_supports'][ $name ] = $prepared;
		}
	}

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

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

	/**
	 * 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.
	 */
	return apply_filters( 'rest_prepare_theme', $response, $theme, $request );
}