WP_oEmbed_Controller::get_item() WordPress Method

The WP_oEmbed_Controller::get_item() method is used to retrieve an oEmbed response for a given URL. The method first tries to fetch the response from the oEmbed provider, and if that fails, it will try to generate the response from the post_ID and post_type.

WP_oEmbed_Controller::get_item( WP_REST_Request $request ) #

Callback for the embed API endpoint.


Description

Returns the JSON object for the post.


Top ↑

Parameters

$request

(WP_REST_Request)(Required)Full data about the request.


Top ↑

Return

(array|WP_Error) oEmbed response data or WP_Error on failure.


Top ↑

Source

File: wp-includes/class-wp-oembed-controller.php

	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;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.