mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-05 05:04:31 +00:00
Embeds: Improve performance when embedding a post from the current site.
When the post being embedded is from the same site, there's no reason to do an HTTP request for it. The data can be fetched directly using `get_oembed_response_data()`. Fixes #36767 for trunk. git-svn-id: https://develop.svn.wordpress.org/trunk@37708 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1079,3 +1079,35 @@ function the_embed_site_title() {
|
||||
*/
|
||||
echo apply_filters( 'embed_site_title_html', $site_title );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the oEmbed result before any HTTP requests are made.
|
||||
*
|
||||
* If the URL belongs to the current site, the result is fetched directly instead of
|
||||
* going through the oEmbed discovery process.
|
||||
*
|
||||
* @since 4.5.3
|
||||
*
|
||||
* @param null|string $result The UNSANITIZED (and potentially unsafe) HTML that should be used to embed. Default null.
|
||||
* @param string $url The URL that should be inspected for discovery `<link>` tags.
|
||||
* @param array $args oEmbed remote get arguments.
|
||||
* @return null|string The UNSANITIZED (and potentially unsafe) HTML that should be used to embed.
|
||||
* Null if the URL does not belong to the current site.
|
||||
*/
|
||||
function wp_filter_pre_oembed_result( $result, $url, $args ) {
|
||||
$post_id = url_to_postid( $url );
|
||||
|
||||
/** This filter is documented in wp-includes/class-wp-oembed-controller.php */
|
||||
$post_id = apply_filters( 'oembed_request_post_id', $post_id, $url );
|
||||
|
||||
$width = isset( $args['width'] ) ? $args['width'] : 0;
|
||||
|
||||
$data = get_oembed_response_data( $post_id, $width );
|
||||
$data = _wp_oembed_get_object()->data2html( (object) $data, $url );
|
||||
|
||||
if ( ! $data ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user