Skip to content

Commit

Permalink
fix: Moved loading of textdomain to init callback (#204)
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Klein <[email protected]>
  • Loading branch information
schakko committed Nov 26, 2024
1 parent 4cf8b50 commit 6749e22
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
3 changes: 3 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@

add_action('plugins_loaded', 'next_ad_int_angular_ajax_params_to_post');

// #204: register `init` hook to make loading the textdomain possible
add_action('init', array($adiPlugin, '_init'));

// register any hooks after the plug-in has been activated e.g. to display notices for a migration of options
add_action('admin_init', array($adiPlugin, 'postActivation'));

Expand Down
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ It is __not__ possible to activate *NADI* for a site inside a network.
For detailed information you can visit the official [GitHub repository of Next Active Directory Integration](https://github.com/NeosIT/active-directory-integration2)

= UNRELEASED =
* FIXED: Check for false value if hostname or port contains invalid value and ldap_connect fails.
* FIXED: Moved loading of textdomain to init callback (#204)
* FIXED: Check for false value if hostname or port contains invalid value and ldap_connect fails (#203)

= 3.1.7 =
* CHANGED: WordPress 6.7 compatibility has been checked
Expand Down
15 changes: 11 additions & 4 deletions src/plug-in/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ function initialize()
return;
}

// load internationalization (i18n)
load_plugin_textdomain('next-active-directory-integration', false,
plugin_basename(NEXT_ACTIVE_DIRECTORY_INTEGRATION_PLUGIN_PATH) . '/languages');

// ADI-354 (dme)
$configurationService = $this->dc()->getMultisiteConfigurationService();

Expand All @@ -130,6 +126,17 @@ function initialize()
$this->initialized = true;
}

/**
* Hook into WordPress' `load` action to load correct textdomain
* @issue #204
* @return void
*/
public function _init() {
// load internationalization (i18n)
load_plugin_textdomain('next-active-directory-integration', false,
plugin_basename(NEXT_ACTIVE_DIRECTORY_INTEGRATION_PLUGIN_PATH) . '/languages');
}

/**
* Is called after all plug-ins have been loaded (hook 'plugins_loaded') to gain access to WordPress functions.
* This method mostly delegates to the register* methods in this class. Only required hooks are registered to
Expand Down
6 changes: 2 additions & 4 deletions test/Nadi/InitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function tearDown(): void

/**
* @test
* @issue #204
*/
public function initialize_loadsLanguageFile()
{
Expand All @@ -36,9 +37,6 @@ public function initialize_loadsLanguageFile()
$fakeService = $this->createInitializeEnvironment($dc);
$pluginFolderName = basename(NEXT_ACTIVE_DIRECTORY_INTEGRATION_PLUGIN_PATH);

$fakeService->expects($this->exactly(2))
->method('getOptionValue');

\WP_Mock::userFunction('plugin_basename', array(
'args' => array(NEXT_ACTIVE_DIRECTORY_INTEGRATION_PLUGIN_PATH),
'times' => 1,
Expand All @@ -53,7 +51,7 @@ public function initialize_loadsLanguageFile()
),
'times' => 1));

$sut->initialize();
$sut->_init();
}

private function createActivationEnvironment($dc)
Expand Down

0 comments on commit 6749e22

Please sign in to comment.