From 48b78d3772625943d7980924b2a71366aa6b7132 Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Thu, 28 Nov 2024 08:26:56 -0500 Subject: [PATCH 1/4] 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. * From c4c94fece356c7565f64f056fce79bb6524bfdd0 Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Thu, 28 Nov 2024 09:28:00 -0500 Subject: [PATCH 2/4] Keep logic to flush rewrite rules --- includes/class-sensei.php | 10 ++-- tests/unit-tests/test-class-sensei.php | 64 ++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/includes/class-sensei.php b/includes/class-sensei.php index cd61b40d1d..0813df9c27 100644 --- a/includes/class-sensei.php +++ b/includes/class-sensei.php @@ -511,6 +511,10 @@ private function __construct( $main_plugin_file_name, $args ) { * @since 1.9.0 */ protected function init() { + // Localization. + 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(); @@ -523,14 +527,11 @@ 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(); } @@ -542,14 +543,11 @@ 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(); } diff --git a/tests/unit-tests/test-class-sensei.php b/tests/unit-tests/test-class-sensei.php index 34d9bf91e9..1167bc409f 100644 --- a/tests/unit-tests/test-class-sensei.php +++ b/tests/unit-tests/test-class-sensei.php @@ -210,6 +210,70 @@ 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. * From 4a0ddacb510724a7f5b4fe6193e4e21dee5ece81 Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Thu, 28 Nov 2024 09:47:36 -0500 Subject: [PATCH 3/4] Fix e2e tests --- tests/e2e-playwright/pages/admin/courses/courses.ts | 2 +- tests/e2e-playwright/pages/admin/courses/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e-playwright/pages/admin/courses/courses.ts b/tests/e2e-playwright/pages/admin/courses/courses.ts index 78d2fdc6c2..88e3ee42ba 100644 --- a/tests/e2e-playwright/pages/admin/courses/courses.ts +++ b/tests/e2e-playwright/pages/admin/courses/courses.ts @@ -44,7 +44,7 @@ export default class CoursesPage extends PostType { this.wizardModal = new WizardModal( wizardLocator ); this.createCourseButton = page.locator( - 'a.page-title-action[href$="post-new.php?post_type=course"]:has-text("New Course")' + 'a.page-title-action[href$="post-new.php?post_type=course"]:has-text("New Course"):visible' ); this.publishButton = page.locator( diff --git a/tests/e2e-playwright/pages/admin/courses/index.ts b/tests/e2e-playwright/pages/admin/courses/index.ts index 3dc42b10eb..bf0221ef03 100644 --- a/tests/e2e-playwright/pages/admin/courses/index.ts +++ b/tests/e2e-playwright/pages/admin/courses/index.ts @@ -92,7 +92,7 @@ export default class CoursesPage extends PostType { this.wizardModal = new WizardModal( wizardLocator ); this.createCourseButton = page.locator( - 'a.page-title-action[href$="post-new.php?post_type=course"]:has-text("New Course")' + 'a.page-title-action[href$="post-new.php?post_type=course"]:has-text("New Course"):visible' ); this.courseOutlineBlock = new CourseOutline( page ); From 531986a28c651db6dc07b3b333887d720c8823e6 Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Thu, 28 Nov 2024 09:53:45 -0500 Subject: [PATCH 4/4] Add change logs --- changelog/deprecate-ptranslation-load-functions | 4 ++++ changelog/remove-loading-translations-code | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 changelog/deprecate-ptranslation-load-functions create mode 100644 changelog/remove-loading-translations-code diff --git a/changelog/deprecate-ptranslation-load-functions b/changelog/deprecate-ptranslation-load-functions new file mode 100644 index 0000000000..d737f3d66e --- /dev/null +++ b/changelog/deprecate-ptranslation-load-functions @@ -0,0 +1,4 @@ +Significance: patch +Type: deprecated + +Deprecate `load_localisation` and `load_plugin_textdomain` functions diff --git a/changelog/remove-loading-translations-code b/changelog/remove-loading-translations-code new file mode 100644 index 0000000000..3445d012e2 --- /dev/null +++ b/changelog/remove-loading-translations-code @@ -0,0 +1,4 @@ +Significance: patch +Type: removed + +Removed manual loading of translations