Make WordPress Core


Ignore:
Timestamp:
09/26/2017 08:39:57 AM (8 years ago)
Author:
swissspidy
Message:

Embeds: Improve performance when embedding a post on Multisite.

After [37798], this fixes embeds coming from a different site in the network.

Props imath.
Fixes #40673. See #36767.

File:
1 edited

Legend:

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

    r41448 r41600  
    10721072 */
    10731073function wp_filter_pre_oembed_result( $result, $url, $args ) {
     1074    if ( is_multisite() ) {
     1075        $url_parts = wp_parse_args( wp_parse_url( $url ), array(
     1076            'host'   => '',
     1077            'path'   => '/',
     1078        ) );
     1079
     1080        $qv = array( 'domain' => $url_parts['host'], 'path' => '/' );
     1081
     1082        // In case of subdirectory configs, set the path.
     1083        if ( ! is_subdomain_install() ) {
     1084            $path = explode( '/', ltrim( $url_parts['path'], '/' ) );
     1085            $path = reset( $path );
     1086
     1087            if ( $path ) {
     1088                $qv['path'] = get_network()->path . $path . '/';
     1089            }
     1090        }
     1091
     1092        $sites = get_sites( $qv );
     1093        $site  = reset( $sites );
     1094
     1095        if ( $site && (int) $site->blog_id !== get_current_blog_id() ) {
     1096            switch_to_blog( $site->blog_id );
     1097        }
     1098    }
     1099
    10741100    $post_id = url_to_postid( $url );
    10751101
     
    10861112    $data = _wp_oembed_get_object()->data2html( (object) $data, $url );
    10871113
     1114    if ( is_multisite() && ms_is_switched() ) {
     1115        restore_current_blog();
     1116    }
     1117
    10881118    if ( ! $data ) {
    10891119        return $result;
Note: See TracChangeset for help on using the changeset viewer.