From 8059b362e83b980be06a32098a0f7168fc939de9 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Sat, 27 Jul 2019 12:44:56 +0000 Subject: [PATCH] I18N: Add support for custom `WP_PLUGIN_URL` in `load_script_textdomain()`. Plugins may not be on the same host/path as the rest of the content. To support loading translations for this setup check if the script source matches `plugins_url()`. Also fixes an undefined index notice when a custom content URL has no path. Props odminstudios, ocean90. Fixes #46336, #46387. Built from https://develop.svn.wordpress.org/trunk@45685 git-svn-id: http://core.svn.wordpress.org/trunk@45496 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/l10n.php | 29 ++++++++++++++++++++++++++--- wp-includes/version.php | 2 +- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 4bcdc4fc4e..bd0110d780 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -948,20 +948,43 @@ function load_script_textdomain( $handle, $domain = 'default', $path = null ) { $src_url = wp_parse_url( $src ); $content_url = wp_parse_url( content_url() ); + $plugins_url = wp_parse_url( plugins_url() ); $site_url = wp_parse_url( site_url() ); // If the host is the same or it's a relative URL. if ( - strpos( $src_url['path'], $content_url['path'] ) === 0 && + ( ! isset( $content_url['path'] ) || strpos( $src_url['path'], $content_url['path'] ) === 0 ) && ( ! isset( $src_url['host'] ) || $src_url['host'] === $content_url['host'] ) ) { // Make the src relative the specific plugin or theme. - $relative = trim( substr( $src_url['path'], strlen( $content_url['path'] ) ), '/' ); + if ( isset( $content_url['path'] ) ) { + $relative = substr( $src_url['path'], strlen( $content_url['path'] ) ); + } else { + $relative = $src_url['path']; + } + $relative = trim( $relative, '/' ); $relative = explode( '/', $relative ); $languages_path = WP_LANG_DIR . '/' . $relative[0]; - $relative = array_slice( $relative, 2 ); + $relative = array_slice( $relative, 2 ); // Remove plugins/ or themes/. + $relative = implode( '/', $relative ); + } elseif ( + ( ! isset( $plugins_url['path'] ) || strpos( $src_url['path'], $plugins_url['path'] ) === 0 ) && + ( ! isset( $src_url['host'] ) || $src_url['host'] === $plugins_url['host'] ) + ) { + // Make the src relative the specific plugin. + if ( isset( $plugins_url['path'] ) ) { + $relative = substr( $src_url['path'], strlen( $plugins_url['path'] ) ); + } else { + $relative = $src_url['path']; + } + $relative = trim( $relative, '/' ); + $relative = explode( '/', $relative ); + + $languages_path = WP_LANG_DIR . '/plugins'; + + $relative = array_slice( $relative, 1 ); // Remove . $relative = implode( '/', $relative ); } elseif ( ! isset( $src_url['host'] ) || $src_url['host'] === $site_url['host'] ) { if ( ! isset( $site_url['path'] ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index c6952c572c..b7dd8923d8 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-alpha-45684'; +$wp_version = '5.3-alpha-45685'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.