From 64ca037991d250a83c04307bc9cc781c80cb1b72 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 25 Jan 2024 07:53:17 +0000 Subject: [PATCH] I18N: Rename `WP_Translation_Controller::instance()` method to `get_instance()`. This improves consistency as `get_instance()` is more commonly used in core. See #59656. Built from https://develop.svn.wordpress.org/trunk@57350 git-svn-id: http://core.svn.wordpress.org/trunk@56856 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-locale-switcher.php | 2 +- wp-includes/l10n.php | 4 ++-- .../l10n/class-wp-translation-controller.php | 22 +++++++++++++------ wp-includes/version.php | 2 +- wp-settings.php | 2 +- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/wp-includes/class-wp-locale-switcher.php b/wp-includes/class-wp-locale-switcher.php index b3e163014a..9f1c4831ed 100644 --- a/wp-includes/class-wp-locale-switcher.php +++ b/wp-includes/class-wp-locale-switcher.php @@ -283,7 +283,7 @@ class WP_Locale_Switcher { $wp_locale = new WP_Locale(); - WP_Translation_Controller::instance()->set_locale( $locale ); + WP_Translation_Controller::get_instance()->set_locale( $locale ); /** * Fires when the locale is switched to or restored. diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 632f432f62..228c40757c 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -797,7 +797,7 @@ function load_textdomain( $domain, $mofile, $locale = null ) { $locale = determine_locale(); } - $i18n_controller = WP_Translation_Controller::instance(); + $i18n_controller = WP_Translation_Controller::get_instance(); // Ensures the correct locale is set as the current one, in case it was filtered. $i18n_controller->set_locale( $locale ); @@ -911,7 +911,7 @@ function unload_textdomain( $domain, $reloadable = false ) { // Since multiple locales are supported, reloadable text domains don't actually need to be unloaded. if ( ! $reloadable ) { - WP_Translation_Controller::instance()->unload_textdomain( $domain ); + WP_Translation_Controller::get_instance()->unload_textdomain( $domain ); } if ( isset( $l10n[ $domain ] ) ) { diff --git a/wp-includes/l10n/class-wp-translation-controller.php b/wp-includes/l10n/class-wp-translation-controller.php index 616dce5793..b44384c013 100644 --- a/wp-includes/l10n/class-wp-translation-controller.php +++ b/wp-includes/l10n/class-wp-translation-controller.php @@ -42,20 +42,28 @@ final class WP_Translation_Controller { protected $loaded_files = array(); /** - * Returns the WP_Translation_Controller singleton. + * Container for the main instance of the class. + * + * @since 6.5.0 + * @var WP_Translation_Controller|null + */ + private static $instance = null; + + /** + * Utility method to retrieve the main instance of the class. + * + * The instance will be created if it does not exist yet. * * @since 6.5.0 * * @return WP_Translation_Controller */ - public static function instance(): WP_Translation_Controller { - static $instance; - - if ( ! $instance ) { - $instance = new self(); + public static function get_instance(): WP_Translation_Controller { + if ( null === self::$instance ) { + self::$instance = new self(); } - return $instance; + return self::$instance; } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index fdd3acfd2e..35be8eec63 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5-alpha-57349'; +$wp_version = '6.5-alpha-57350'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-settings.php b/wp-settings.php index 28bcdded99..e30eeb493b 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -622,7 +622,7 @@ $GLOBALS['wp_locale'] = new WP_Locale(); $GLOBALS['wp_locale_switcher'] = new WP_Locale_Switcher(); $GLOBALS['wp_locale_switcher']->init(); -WP_Translation_Controller::instance()->set_locale( $locale ); +WP_Translation_Controller::get_instance()->set_locale( $locale ); // Load the functions for the active theme, for both parent and child theme if applicable. foreach ( wp_get_active_and_valid_themes() as $theme ) {