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

WP_REST_Templates_Controller::prepare_item_for_database() protected WP 5.8.0

Prepares a single template for create or update.

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

Хуков нет.

Возвращает

stdClass. Changes to pass to wp_update_post.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->prepare_item_for_database( $request );
$request(WP_REST_Request) (обязательный)
Request object.

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

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

Код WP_REST_Templates_Controller::prepare_item_for_database() WP 5.8.1

protected function prepare_item_for_database( $request ) {
	$template = $request['id'] ? get_block_template( $request['id'], $this->post_type ) : null;
	$changes  = new stdClass();
	if ( null === $template ) {
		$changes->post_type   = $this->post_type;
		$changes->post_status = 'publish';
		$changes->tax_input   = array(
			'wp_theme' => isset( $request['theme'] ) ? $request['theme'] : wp_get_theme()->get_stylesheet(),
		);
	} elseif ( 'custom' !== $template->source ) {
		$changes->post_name   = $template->slug;
		$changes->post_type   = $this->post_type;
		$changes->post_status = 'publish';
		$changes->tax_input   = array(
			'wp_theme' => $template->theme,
		);
	} else {
		$changes->post_name   = $template->slug;
		$changes->ID          = $template->wp_id;
		$changes->post_status = 'publish';
	}
	if ( isset( $request['content'] ) ) {
		$changes->post_content = $request['content'];
	} elseif ( null !== $template && 'custom' !== $template->source ) {
		$changes->post_content = $template->content;
	}
	if ( isset( $request['title'] ) ) {
		$changes->post_title = $request['title'];
	} elseif ( null !== $template && 'custom' !== $template->source ) {
		$changes->post_title = $template->title;
	}
	if ( isset( $request['description'] ) ) {
		$changes->post_excerpt = $request['description'];
	} elseif ( null !== $template && 'custom' !== $template->source ) {
		$changes->post_excerpt = $template->description;
	}

	return $changes;
}