On this page
WP_oEmbed_Controller::get_item( WP_REST_Request $request ): array|WP_Error
Callback for the embed API endpoint.
Description
Returns the JSON object for the post.
Parameters
$requestWP_REST_Request Required-
Full data about the request.
Return
Source
File: wp-includes/class-wp-oembed-controller.php. View all references
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;
}
Hooks
- apply_filters( 'oembed_request_post_id',
int $post_id ,string $url ) -
Filters the determined post ID.
Related
Uses
| Uses | Description |
|---|---|
| get_oembed_response_data() wp-includes/embed.php | Retrieves the oEmbed response data for a given post. |
| get_status_header_desc() wp-includes/functions.php | Retrieves the description for the HTTP status. |
| url_to_postid() wp-includes/rewrite.php | Examines a URL and try to determine the post ID it represents. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| WP_Error::__construct() wp-includes/class-wp-error.php | Initializes the error. |
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_oembed_controller/get_item