diff --git a/src/wp-includes/l10n.php b/src/wp-includes/l10n.php index e4acf40b38..bee3581618 100644 --- a/src/wp-includes/l10n.php +++ b/src/wp-includes/l10n.php @@ -1151,6 +1151,7 @@ function load_script_textdomain( $handle, $domain = 'default', $path = '' ) { $content_url = wp_parse_url( content_url() ); $plugins_url = wp_parse_url( plugins_url() ); $site_url = wp_parse_url( site_url() ); + $theme_root = get_theme_root(); // If the host is the same or it's a relative URL. if ( @@ -1167,12 +1168,13 @@ function load_script_textdomain( $handle, $domain = 'default', $path = '' ) { $relative = explode( '/', $relative ); /* - * Ensure correct languages path when using a custom `WP_PLUGIN_DIR` / `WP_PLUGIN_URL` configuration. + * Ensure correct languages path when using a custom `WP_PLUGIN_DIR` / `WP_PLUGIN_URL` configuration, + * a custom theme root, and/or using Multisite with subdirectories. * See https://core.trac.wordpress.org/ticket/60891 and https://core.trac.wordpress.org/ticket/62016. */ - $plugins_dir = array_slice( explode( '/', $plugins_url['path'] ), 2 ); - $plugins_dir = trim( $plugins_dir[0], '/' ); - $dirname = $plugins_dir === $relative[0] ? 'plugins' : 'themes'; + + $theme_dir = array_slice( explode( '/', $theme_root ), -1 ); + $dirname = $theme_dir[0] === $relative[0] ? 'themes' : 'plugins'; $languages_path = WP_LANG_DIR . '/' . $dirname; diff --git a/tests/phpunit/tests/l10n/loadScriptTextdomain.php b/tests/phpunit/tests/l10n/loadScriptTextdomain.php index 1f5fde9eec..bc028fbfa5 100644 --- a/tests/phpunit/tests/l10n/loadScriptTextdomain.php +++ b/tests/phpunit/tests/l10n/loadScriptTextdomain.php @@ -28,7 +28,7 @@ class Tests_L10n_LoadScriptTextdomain extends WP_UnitTestCase { $this->assertSame( $expected, load_script_textdomain( $handle, $textdomain, DIR_TESTDATA . '/languages' ) ); } - public function data_resolve_relative_path() { + public static function data_resolve_relative_path() { return array( // @ticket 45528 array( @@ -43,7 +43,7 @@ class Tests_L10n_LoadScriptTextdomain extends WP_UnitTestCase { 'test-example-cdn', 'https://my-cdn.com/wordpress/wp-includes/js/script.js', 'default', - array( 'load_script_textdomain_relative_path', array( $this, 'relative_path_from_cdn' ), 2 ), + array( 'load_script_textdomain_relative_path', array( __CLASS__, 'relative_path_from_cdn' ), 2 ), ), // Test for WordPress installs in a subdirectory. array( @@ -146,7 +146,7 @@ class Tests_L10n_LoadScriptTextdomain extends WP_UnitTestCase { ); } - public function relative_path_from_cdn( $relative, $src ) { + public static function relative_path_from_cdn( $relative, $src ) { if ( 0 === strpos( $src, 'https://my-cdn.com/wordpress/' ) ) { return substr( $src, strlen( 'https://my-cdn.com/wordpress/' ) ); }