I18N: Set textdomain registry information before loading plugins/theme.

This way, warnings for early translation calls can be emitted that aren't attached to any hook.

Follow-up to [59461].

Props swissspidy.
Fixes #62244.See #44937.

git-svn-id: https://develop.svn.wordpress.org/trunk@59670 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler 2025-01-21 11:42:19 +00:00
parent 7be10747ea
commit 4b89ebe5be

View File

@ -525,6 +525,17 @@ require_once ABSPATH . 'wp-admin/includes/plugin.php';
foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
wp_register_plugin_realpath( $plugin );
$plugin_data = get_plugin_data( $plugin, false, false );
$textdomain = $plugin_data['TextDomain'];
if ( $textdomain ) {
if ( $plugin_data['DomainPath'] ) {
$GLOBALS['wp_textdomain_registry']->set_custom_path( $textdomain, dirname( $plugin ) . $plugin_data['DomainPath'] );
} else {
$GLOBALS['wp_textdomain_registry']->set_custom_path( $textdomain, dirname( $plugin ) );
}
}
$_wp_plugin_file = $plugin;
include_once $plugin;
$plugin = $_wp_plugin_file; // Avoid stomping of the $plugin variable in a plugin.
@ -537,17 +548,6 @@ foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
* @param string $plugin Full path to the plugin's main file.
*/
do_action( 'plugin_loaded', $plugin );
$plugin_data = get_plugin_data( $plugin, false, false );
$textdomain = $plugin_data['TextDomain'];
if ( $textdomain ) {
if ( $plugin_data['DomainPath'] ) {
$GLOBALS['wp_textdomain_registry']->set_custom_path( $textdomain, dirname( $plugin ) . $plugin_data['DomainPath'] );
} else {
$GLOBALS['wp_textdomain_registry']->set_custom_path( $textdomain, dirname( $plugin ) );
}
}
}
unset( $plugin, $_wp_plugin_file, $plugin_data, $textdomain );
@ -684,11 +684,11 @@ $GLOBALS['wp_locale_switcher']->init();
foreach ( wp_get_active_and_valid_themes() as $theme ) {
$wp_theme = wp_get_theme( basename( $theme ) );
$wp_theme->load_textdomain();
if ( file_exists( $theme . '/functions.php' ) ) {
include $theme . '/functions.php';
}
$wp_theme->load_textdomain();
}
unset( $theme, $wp_theme );