Skip to content

Commit

Permalink
No need to manually load translations anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
donnapep committed Nov 28, 2024
1 parent a8f600c commit 48b78d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 73 deletions.
20 changes: 11 additions & 9 deletions includes/class-sensei.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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/' );
}
Expand All @@ -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() ) {
Expand Down
64 changes: 0 additions & 64 deletions tests/unit-tests/test-class-sensei.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 48b78d3

Please sign in to comment.