I18N: Allow to short-circuit load_textdomain().

Introduces a new `pre_load_textdomain` filter, which is useful for plugins to develop and test alternative loading/caching strategies for translations. This brings consistency with the existing `pre_load_script_translations` filter for JavaScript translations.

Props ocean90, swissspidy.
Fixes #58035.

git-svn-id: https://develop.svn.wordpress.org/trunk@55928 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler
2023-06-16 12:56:03 +00:00
parent a1673dccae
commit 6048eb34be
2 changed files with 38 additions and 0 deletions
@@ -300,4 +300,20 @@ class Tests_L10n_LoadTextdomain extends WP_UnitTestCase {
$this->assertSame( get_user_locale(), $this->locale );
}
/**
* @ticket 58035
*
* @covers ::load_theme_textdomain
*/
public function test_pre_load_textdomain_filter() {
$override_load_textdomain_callback = new MockAction();
add_filter( 'override_load_textdomain', array( $override_load_textdomain_callback, 'action' ) );
add_filter( 'pre_load_textdomain', '__return_true' );
load_plugin_textdomain( 'wp-tests-domain' );
remove_filter( 'pre_load_textdomain', '__return_true' );
$this->assertSame( 0, $override_load_textdomain_callback->get_call_count(), 'Expected override_load_textdomain not to be called.' );
}
}