From 73a19c6116ad84a43cbdaa452642a41fa0a11299 Mon Sep 17 00:00:00 2001 From: herregroen Date: Thu, 15 Nov 2018 14:37:49 +0000 Subject: [PATCH] I18N: Fix warnings in JavaScript translations. Fixes an undefined index PHP warning in the load_script_textdomain function and a non-interrupting JS error when registering a domain which has no translations. Props omarreiss, ocean90, georgestephanis. Fixes #45256. Built from https://develop.svn.wordpress.org/branches/5.0@43898 git-svn-id: http://core.svn.wordpress.org/branches/5.0@43730 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class.wp-scripts.php | 3 ++- wp-includes/l10n.php | 20 ++++++++------------ wp-includes/version.php | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/wp-includes/class.wp-scripts.php b/wp-includes/class.wp-scripts.php index aa9d4261c9..0562d70bb9 100644 --- a/wp-includes/class.wp-scripts.php +++ b/wp-includes/class.wp-scripts.php @@ -528,7 +528,8 @@ class WP_Scripts extends WP_Dependencies { $json_translations = load_script_textdomain( $handle, $domain, $path ); if ( ! $json_translations ) { - return false; + // Register empty locale data object to ensure the domain still exists. + $json_translations = '{ "locale_data": { "messages": { "": {} } } }'; } $output = '(function( translations ){' . diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index feaf89d653..b46607ae61 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -923,18 +923,14 @@ function load_script_textdomain( $handle, $domain, $path = null ) { $relative = array_slice( $relative, 2 ); $relative = implode( '/', $relative ); - } else if ( - ! isset( $site_url['path'] ) && - ( ! isset( $src_url['host'] ) || $src_url['host'] !== $site_url['host'] ) - ) { - $relative = trim( $src_url['path'], '/' ); - } else if ( - ( strpos( $src_url['path'], $site_url['path'] ) === 0 ) && - ( ! isset( $src_url['host'] ) || $src_url['host'] !== $site_url['host'] ) - ) { - // Make the src relative to the WP root. - $relative = substr( $src, strlen( $site_url['path'] ) ); - $relative = trim( $relative, '/' ); + } elseif ( ! isset( $src_url['host'] ) || $src_url['host'] !== $site_url['host'] ) { + if ( ! isset( $site_url['path'] ) ) { + $relative = trim( $src_url['path'], '/' ); + } elseif ( ( strpos( $src_url['path'], $site_url['path'] ) === 0 ) ) { + // Make the src relative to the WP root. + $relative = substr( $src, strlen( $site_url['path'] ) ); + $relative = trim( $relative, '/' ); + } } // If the source is not from WP. diff --git a/wp-includes/version.php b/wp-includes/version.php index 19b93c5890..bfc267b8dc 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '5.0-beta4-43897'; +$wp_version = '5.0-beta4-43898'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.