Skip to content

Commit bfe0eca

Browse files
committed
Handle possible undefined path index on src_url and fix type issues in _load_script_textdomain_from_src()
1 parent 2ce9b02 commit bfe0eca

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/wp-includes/l10n.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,7 @@ function load_script_module_textdomain( string $id, string $domain = 'default',
12061206
* @return string|false The JSON-encoded translated strings on success, false otherwise.
12071207
*/
12081208
function _load_script_textdomain_from_src( string $handle, string $src, string $domain, string $path, bool $is_module ) {
1209+
/** @var WP_Textdomain_Registry $wp_textdomain_registry */
12091210
global $wp_textdomain_registry;
12101211

12111212
$locale = determine_locale();
@@ -1214,7 +1215,9 @@ function _load_script_textdomain_from_src( string $handle, string $src, string $
12141215
$path = $wp_textdomain_registry->get( $domain, $locale );
12151216
}
12161217

1217-
$path = untrailingslashit( $path );
1218+
if ( $path ) {
1219+
$path = untrailingslashit( $path );
1220+
}
12181221

12191222
// If a path was given and the handle file exists simply return it.
12201223
$file_base = 'default' === $domain ? $locale : $domain . '-' . $locale;
@@ -1231,8 +1234,17 @@ function _load_script_textdomain_from_src( string $handle, string $src, string $
12311234
$relative = false;
12321235
$languages_path = WP_LANG_DIR;
12331236

1234-
$src_url = wp_parse_url( $src );
1237+
$src_url = wp_parse_url( $src );
1238+
if ( ! $src_url ) {
1239+
return false;
1240+
}
1241+
$src_url['path'] ??= '';
1242+
12351243
$content_url = wp_parse_url( content_url() );
1244+
if ( ! $content_url ) {
1245+
return false;
1246+
}
1247+
12361248
$plugins_url = wp_parse_url( plugins_url() );
12371249
$site_url = wp_parse_url( site_url() );
12381250
$theme_root = get_theme_root();
@@ -1304,7 +1316,7 @@ function _load_script_textdomain_from_src( string $handle, string $src, string $
13041316
$relative = apply_filters( 'load_script_textdomain_relative_path', $relative, $src, $is_module );
13051317

13061318
// If the source is not from WP.
1307-
if ( false === $relative ) {
1319+
if ( ! is_string( $relative ) ) {
13081320
return load_script_translations( false, $handle, $domain );
13091321
}
13101322

0 commit comments

Comments
 (0)