WP_REST_Attachments_Controller::prepare_linksprotectedWP 6.9.0

Prepares attachment links for the request.

Метод класса: WP_REST_Attachments_Controller{}

Хуков нет.

Возвращает

Массив. Links for the given attachment.

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

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

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

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

Код WP_REST_Attachments_Controller::prepare_links() WP 6.9

protected function prepare_links( $post ) {
	$links = parent::prepare_links( $post );

	if ( ! empty( $post->post_parent ) ) {
		$post = get_post( $post->post_parent );

		if ( ! empty( $post ) ) {
			$links['https://api.w.org/attached-to'] = array(
				'href'       => rest_url( rest_get_route_for_post( $post ) ),
				'embeddable' => true,
				'post_type'  => $post->post_type,
				'id'         => $post->ID,
			);
		}
	}

	return $links;
}