From 295e48baa932bcbd194808b961031f13004784cd Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Thu, 13 Oct 2016 22:28:28 +0000 Subject: [PATCH] Multisite: Maintain switched state in site icon/logo functions. Adjusts `get_custom_logo()`, `get_site_icon_url()`, and `has_custom_logo()` so that when called in a switched state, the original switched stack is not adjusted. Props achbed, flixos90. Fixes #38253. Built from https://develop.svn.wordpress.org/trunk@38786 git-svn-id: http://core.svn.wordpress.org/trunk@38729 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/general-template.php | 20 ++++++++++++++------ wp-includes/version.php | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 75a4bdf5bd..23b2f1c5ab 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -783,8 +783,11 @@ function get_bloginfo( $show = '', $filter = 'raw' ) { * @return string Site Icon URL. */ function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) { - if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) { + $switched_blog = false; + + if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) { switch_to_blog( $blog_id ); + $switched_blog = true; } $site_icon_id = get_option( 'site_icon' ); @@ -798,7 +801,7 @@ function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) { $url = wp_get_attachment_image_url( $site_icon_id, $size_data ); } - if ( is_multisite() && ms_is_switched() ) { + if ( $switched_blog ) { restore_current_blog(); } @@ -848,13 +851,16 @@ function has_site_icon( $blog_id = 0 ) { * @return bool Whether the site has a custom logo or not. */ function has_custom_logo( $blog_id = 0 ) { - if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) { + $switched_blog = false; + + if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) { switch_to_blog( $blog_id ); + $switched_blog = true; } $custom_logo_id = get_theme_mod( 'custom_logo' ); - if ( is_multisite() && ms_is_switched() ) { + if ( $switched_blog ) { restore_current_blog(); } @@ -871,9 +877,11 @@ function has_custom_logo( $blog_id = 0 ) { */ function get_custom_logo( $blog_id = 0 ) { $html = ''; + $switched_blog = false; - if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) { + if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) { switch_to_blog( $blog_id ); + $switched_blog = true; } $custom_logo_id = get_theme_mod( 'custom_logo' ); @@ -896,7 +904,7 @@ function get_custom_logo( $blog_id = 0 ) { ); } - if ( is_multisite() && ms_is_switched() ) { + if ( $switched_blog ) { restore_current_blog(); } diff --git a/wp-includes/version.php b/wp-includes/version.php index d5ebfa7d99..8b2b051cf6 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-alpha-38785'; +$wp_version = '4.7-alpha-38786'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.