From 742fc18cca0d6b918538f99c12a2fa79c22b7049 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 26 Sep 2017 08:40:47 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@41600 git-svn-id: http://core.svn.wordpress.org/trunk@41435 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/embed.php | 30 ++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/wp-includes/embed.php b/wp-includes/embed.php index 05f0114c9b..8ca7f80d5b 100644 --- a/wp-includes/embed.php +++ b/wp-includes/embed.php @@ -1071,6 +1071,32 @@ function the_embed_site_title() { * Null if the URL does not belong to the current site. */ function wp_filter_pre_oembed_result( $result, $url, $args ) { + if ( is_multisite() ) { + $url_parts = wp_parse_args( wp_parse_url( $url ), array( + 'host' => '', + 'path' => '/', + ) ); + + $qv = array( 'domain' => $url_parts['host'], 'path' => '/' ); + + // In case of subdirectory configs, set the path. + if ( ! is_subdomain_install() ) { + $path = explode( '/', ltrim( $url_parts['path'], '/' ) ); + $path = reset( $path ); + + if ( $path ) { + $qv['path'] = get_network()->path . $path . '/'; + } + } + + $sites = get_sites( $qv ); + $site = reset( $sites ); + + if ( $site && (int) $site->blog_id !== get_current_blog_id() ) { + switch_to_blog( $site->blog_id ); + } + } + $post_id = url_to_postid( $url ); /** This filter is documented in wp-includes/class-wp-oembed-controller.php */ @@ -1085,6 +1111,10 @@ function wp_filter_pre_oembed_result( $result, $url, $args ) { $data = get_oembed_response_data( $post_id, $width ); $data = _wp_oembed_get_object()->data2html( (object) $data, $url ); + if ( is_multisite() && ms_is_switched() ) { + restore_current_blog(); + } + if ( ! $data ) { return $result; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 33e90c6a59..0571f764fe 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-alpha-41599'; +$wp_version = '4.9-alpha-41600'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.