Make WordPress Core


Ignore:
Timestamp:
11/26/2024 10:14:07 AM (21 months ago)
Author:
swissspidy
Message:

I18N: Load translations just-in-time for custom themes and plugins.

In #34114, just-in-time (JIT) translation loading was implemented for projects hosted on WordPress.org. This is now expanded to all other plugins/themes.

Projects with a custom Text Domain and Domain Path header no longer need to call load_plugin_textdomain() or load_theme_textdomain().

This reduces the risk of calling them too late, after some translation calls already happened, and generally makes it easier to properly internationalize a plugin or theme.

This moves the get_plugin_data() from wp-admin/includes/plugin.php to wp-includes/functions.php so it's available during the plugin loading process.

Props swissspidy.
Fixes #62244.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-settings.php

    r59132 r59461  
    535535         */
    536536        do_action( 'plugin_loaded', $plugin );
    537 }
    538 unset( $plugin, $_wp_plugin_file );
     537
     538        $plugin_data = get_plugin_data( $plugin, false, false );
     539
     540        $textdomain = $plugin_data['TextDomain'];
     541        if ( $textdomain ) {
     542                if ( $plugin_data['DomainPath'] ) {
     543                        $GLOBALS['wp_textdomain_registry']->set_custom_path( $textdomain, dirname( $plugin ) . $plugin_data['DomainPath'] );
     544                } else {
     545                        $GLOBALS['wp_textdomain_registry']->set_custom_path( $textdomain, dirname( $plugin ) );
     546                }
     547        }
     548}
     549unset( $plugin, $_wp_plugin_file, $plugin_data, $textdomain );
    539550
    540551// Load pluggable functions.
     
    672683                include $theme . '/functions.php';
    673684        }
     685
     686        $theme = wp_get_theme( basename( $theme ) );
     687        $theme->load_textdomain();
    674688}
    675689unset( $theme );
Note: See TracChangeset for help on using the changeset viewer.