Make WordPress Core


Ignore:
Timestamp:
06/15/2016 11:22:52 AM (8 years ago)
Author:
swissspidy
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/embed.php

    r37549 r37708  
    10801080    echo apply_filters( 'embed_site_title_html', $site_title );
    10811081}
     1082
     1083/**
     1084 * Filters the oEmbed result before any HTTP requests are made.
     1085 *
     1086 * If the URL belongs to the current site, the result is fetched directly instead of
     1087 * going through the oEmbed discovery process.
     1088 *
     1089 * @since 4.5.3
     1090 *
     1091 * @param null|string $result The UNSANITIZED (and potentially unsafe) HTML that should be used to embed. Default null.
     1092 * @param string      $url    The URL that should be inspected for discovery `<link>` tags.
     1093 * @param array       $args   oEmbed remote get arguments.
     1094 * @return null|string The UNSANITIZED (and potentially unsafe) HTML that should be used to embed.
     1095 *                     Null if the URL does not belong to the current site.
     1096 */
     1097function wp_filter_pre_oembed_result( $result, $url, $args ) {
     1098    $post_id = url_to_postid( $url );
     1099
     1100    /** This filter is documented in wp-includes/class-wp-oembed-controller.php */
     1101    $post_id = apply_filters( 'oembed_request_post_id', $post_id, $url );
     1102
     1103    $width = isset( $args['width'] ) ? $args['width'] : 0;
     1104
     1105    $data = get_oembed_response_data( $post_id, $width );
     1106    $data = _wp_oembed_get_object()->data2html( (object) $data, $url );
     1107
     1108    if ( ! $data ) {
     1109        return $result;
     1110    }
     1111
     1112    return $data;
     1113}
Note: See TracChangeset for help on using the changeset viewer.