WP_oEmbed_Controller::get_item()publicWP 4.4.0

Callback for the embed API endpoint.

Returns the JSON object for the post.

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

Хуки из метода

Возвращает

Массив|WP_Error. oEmbed response data or WP_Error on failure.

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

$WP_oEmbed_Controller = new WP_oEmbed_Controller();
$WP_oEmbed_Controller->get_item( $request );
$request(WP_REST_Request) (обязательный)
Full data about the request.

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

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

Код WP_oEmbed_Controller::get_item() WP 6.4.3

public function get_item( $request ) {
	$post_id = url_to_postid( $request['url'] );

	/**
	 * Filters the determined post ID.
	 *
	 * @since 4.4.0
	 *
	 * @param int    $post_id The post ID.
	 * @param string $url     The requested URL.
	 */
	$post_id = apply_filters( 'oembed_request_post_id', $post_id, $request['url'] );

	$data = get_oembed_response_data( $post_id, $request['maxwidth'] );

	if ( ! $data ) {
		return new WP_Error( 'oembed_invalid_url', get_status_header_desc( 404 ), array( 'status' => 404 ) );
	}

	return $data;
}