From a02d79cf731483952be1ea2aaff91c018ba060df Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 25 Aug 2016 19:08:38 +0000 Subject: [PATCH] Site Icon: There is no good reason for `class-wp-site-icon.php` to drop a global instance of itself whenever the file is loaded. The lone use of the `global` instance of `WP_Site_Icon` is in an AJAX action that provides virtually no way to override - the file is loaded immediately before the `global` is used. Let us remove the `$wp_site_icon` global. I will fall on the sword if this comes back to bite us (waiting with bated breath). See #37699. git-svn-id: https://develop.svn.wordpress.org/trunk@38355 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/ajax-actions.php | 4 +--- src/wp-admin/includes/class-wp-site-icon.php | 5 ----- tests/phpunit/tests/general/template.php | 11 ++++++----- tests/phpunit/tests/image/site_icon.php | 16 +++++++++++----- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index dc965d63cc..37fdc72067 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -3162,8 +3162,6 @@ function wp_ajax_press_this_add_category() { * Ajax handler for cropping an image. * * @since 4.3.0 - * - * @global WP_Site_Icon $wp_site_icon */ function wp_ajax_crop_image() { $attachment_id = absint( $_POST['id'] ); @@ -3184,7 +3182,7 @@ function wp_ajax_crop_image() { switch ( $context ) { case 'site-icon': require_once ABSPATH . '/wp-admin/includes/class-wp-site-icon.php'; - global $wp_site_icon; + $wp_site_icon = new WP_Site_Icon(); // Skip creating a new attachment if the attachment is a Site Icon. if ( get_post_meta( $attachment_id, '_wp_attachment_context', true ) == $context ) { diff --git a/src/wp-admin/includes/class-wp-site-icon.php b/src/wp-admin/includes/class-wp-site-icon.php index 3afc83def7..a54c60b704 100644 --- a/src/wp-admin/includes/class-wp-site-icon.php +++ b/src/wp-admin/includes/class-wp-site-icon.php @@ -240,8 +240,3 @@ class WP_Site_Icon { return $value; } } - -/** - * @global WP_Site_Icon $wp_site_icon - */ -$GLOBALS['wp_site_icon'] = new WP_Site_Icon; diff --git a/tests/phpunit/tests/general/template.php b/tests/phpunit/tests/general/template.php index d189cc9449..275b61f759 100644 --- a/tests/phpunit/tests/general/template.php +++ b/tests/phpunit/tests/general/template.php @@ -1,13 +1,15 @@ wp_site_icon = $GLOBALS['wp_site_icon']; + $this->wp_site_icon = new WP_Site_Icon(); } function tearDown() { diff --git a/tests/phpunit/tests/image/site_icon.php b/tests/phpunit/tests/image/site_icon.php index be75830966..bdd9822661 100644 --- a/tests/phpunit/tests/image/site_icon.php +++ b/tests/phpunit/tests/image/site_icon.php @@ -1,27 +1,33 @@ wp_site_icon = $GLOBALS['wp_site_icon']; + $this->wp_site_icon = new WP_Site_Icon(); } function tearDown() { - $this->site_icon = null; + $this->_remove_custom_logo(); $this->remove_added_uploads(); parent::tearDown(); } + function _remove_custom_logo() { + remove_theme_mod( 'custom_logo' ); + } + function test_intermediate_image_sizes() { $image_sizes = $this->wp_site_icon->intermediate_image_sizes( array() );