From 48b78d3772625943d7980924b2a71366aa6b7132 Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Thu, 28 Nov 2024 08:26:56 -0500 Subject: [PATCH] No need to manually load translations anymore --- includes/class-sensei.php | 20 ++++---- tests/unit-tests/test-class-sensei.php | 64 -------------------------- 2 files changed, 11 insertions(+), 73 deletions(-) diff --git a/includes/class-sensei.php b/includes/class-sensei.php index 955079274c..cd61b40d1d 100644 --- a/includes/class-sensei.php +++ b/includes/class-sensei.php @@ -511,13 +511,6 @@ private function __construct( $main_plugin_file_name, $args ) { * @since 1.9.0 */ protected function init() { - - // Localisation. - $this->load_plugin_textdomain(); - add_action( 'init', array( $this, 'load_localisation' ), 0 ); - add_action( 'update_option_WPLANG', array( $this, 'maybe_initiate_rewrite_rules_flush_after_language_change' ), 10, 2 ); - add_action( 'upgrader_process_complete', array( $this, 'maybe_initiate_rewrite_rules_flush_on_translation_update' ), 10, 2 ); - $this->initialize_cache_groups(); $this->initialize_global_objects(); $this->initialize_cli(); @@ -530,11 +523,14 @@ protected function init() { * @internal * * @since 4.20.2 + * @deprecated $$next-version$$ * * @param mixed $old_value Old value. * @param mixed $new_value New value. */ public function maybe_initiate_rewrite_rules_flush_after_language_change( $old_value, $new_value ) { + _deprecated_function( __METHOD__, '$$next-version$$' ); + if ( $old_value !== $new_value ) { $this->initiate_rewrite_rules_flush(); } @@ -546,11 +542,14 @@ public function maybe_initiate_rewrite_rules_flush_after_language_change( $old_v * @internal * * @since 4.20.2 + * @deprecated $$next-version$$ * * @param WP_Upgrader $upgrader_object Upgrader object. * @param array $options Options. */ public function maybe_initiate_rewrite_rules_flush_on_translation_update( $upgrader_object, $options ) { + _deprecated_function( __METHOD__, '$$next-version$$' ); + if ( 'translation' === $options['type'] ) { $this->initiate_rewrite_rules_flush(); } @@ -986,9 +985,10 @@ public function register_widgets() { * * @access public * @since 1.0.0 - * @return void + * @deprecated $$next-version$$ */ public function load_localisation() { + _deprecated_function( __METHOD__, '$$next-version$$' ); load_plugin_textdomain( 'sensei-lms', false, dirname( plugin_basename( $this->main_plugin_file_name ) ) . '/lang/' ); } @@ -998,9 +998,11 @@ public function load_localisation() { * * @access public * @since 1.0.0 - * @return void + * @deprecated $$next-version$$ */ public function load_plugin_textdomain() { + _deprecated_function( __METHOD__, '$$next-version$$' ); + $domain = 'sensei-lms'; if ( is_admin() ) { diff --git a/tests/unit-tests/test-class-sensei.php b/tests/unit-tests/test-class-sensei.php index 1167bc409f..34d9bf91e9 100644 --- a/tests/unit-tests/test-class-sensei.php +++ b/tests/unit-tests/test-class-sensei.php @@ -210,70 +210,6 @@ public function testConstructor_Always_InitializesClockProperty() { $this->assertInstanceOf( Clock_Interface::class, $sensei->clock ); } - public function testConstruct_Always_AddsActionOnUpdateOptionWplang() { - /* Arrange. */ - $sensei = Sensei(); - - /* Assert. */ - $this->assertSame( 10, has_action( 'update_option_WPLANG', [ $sensei, 'maybe_initiate_rewrite_rules_flush_after_language_change' ] ) ); - } - - public function testConstruct_Always_AddsActionOnUpgraderProcessComplete() { - /* Arrange. */ - $sensei = Sensei(); - - /* Assert. */ - $this->assertSame( 10, has_action( 'upgrader_process_complete', [ $sensei, 'maybe_initiate_rewrite_rules_flush_on_translation_update' ] ) ); - } - - public function testMaybeInitiateRewriteRulesFlushAfterLanguageChange_WhenLanguageChanged_UpdatesOption() { - /* Arrange. */ - $sensei = Sensei(); - update_option( 'sensei_flush_rewrite_rules', '0' ); - - /* Act. */ - $sensei->maybe_initiate_rewrite_rules_flush_after_language_change( 'a', 'b' ); - - /* Assert. */ - $this->assertSame( '1', get_option( 'sensei_flush_rewrite_rules' ) ); - } - - public function testMaybeInitiateRewriteRulesFlushAfterLanguageChange_WhenLanguageNotChanged_DoesntUpdateOption() { - /* Arrange. */ - $sensei = Sensei(); - update_option( 'sensei_flush_rewrite_rules', '0' ); - - /* Act. */ - $sensei->maybe_initiate_rewrite_rules_flush_after_language_change( 'a', 'a' ); - - /* Assert. */ - $this->assertSame( '0', get_option( 'sensei_flush_rewrite_rules' ) ); - } - - public function testMaybeInitiateRewriteRulesFlushOnTranslationUpdate_WhenNonTranslationUpdate_DoesntUpdateOption() { - /* Arrange. */ - $sensei = Sensei(); - update_option( 'sensei_flush_rewrite_rules', '0' ); - - /* Act. */ - $sensei->maybe_initiate_rewrite_rules_flush_on_translation_update( new stdClass(), array( 'type' => 'a' ) ); - - /* Assert. */ - $this->assertSame( '0', get_option( 'sensei_flush_rewrite_rules' ) ); - } - - public function testMaybeInitiateRewriteRulesFlushOnTranslationUpdate_WhenTranslationUpdate_UpdatesOption() { - /* Arrange. */ - $sensei = Sensei(); - update_option( 'sensei_flush_rewrite_rules', '0' ); - - /* Act. */ - $sensei->maybe_initiate_rewrite_rules_flush_on_translation_update( new stdClass(), array( 'type' => 'translation' ) ); - - /* Assert. */ - $this->assertSame( '1', get_option( 'sensei_flush_rewrite_rules' ) ); - } - /** * Create courses and comments for the course. *