Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/wp-includes/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,26 @@ function ms_allowed_http_request_hosts( $is_external, $host ) {
* When a specific component has been requested: null if the component
* doesn't exist in the given URL; a string or - in the case of
* PHP_URL_PORT - integer when it does. See parse_url()'s return values.
*
* @phpstan-param int<-1, 7> $component
* @phpstan-return (
* $component is -1
* ? false|array{
* scheme?: string,
* host?: string,
* port?: int<0, 65535>,
* user?: string,
* pass?: string,
* path?: string,
* query?: string,
* fragment?: string,
* }
* : (
* $component is 2
* ? int<0, 65535>|null
* : string|null
* )
Comment thread
westonruter marked this conversation as resolved.
* )
*/
function wp_parse_url( $url, $component = -1 ) {
$to_unset = array();
Expand Down Expand Up @@ -763,6 +783,36 @@ function wp_parse_url( $url, $component = -1 ) {
* When a specific component has been requested: null if the component
* doesn't exist in the given URL; a string or - in the case of
* PHP_URL_PORT - integer when it does. See parse_url()'s return values.
*
* @phpstan-param false|array{
* scheme?: string,
* host?: string,
* port?: int<0, 65535>,
* user?: string,
* pass?: string,
* path?: string,
* query?: string,
* fragment?: string,
* } $url_parts
* @phpstan-param int<-1, 7> $component
* @phpstan-return (
* $component is -1
* ? false|array{
* scheme?: string,
* host?: string,
* port?: int<0, 65535>,
* user?: string,
* pass?: string,
* path?: string,
* query?: string,
* fragment?: string,
* }
* : (
* $component is 2
* ? int<0, 65535>|null
* : string|null
Comment thread
westonruter marked this conversation as resolved.
* )
* )
*/
function _get_component_from_parsed_url_array( $url_parts, $component = -1 ) {
if ( -1 === $component ) {
Expand All @@ -789,6 +839,9 @@ function _get_component_from_parsed_url_array( $url_parts, $component = -1 ) {
*
* @param int $constant PHP_URL_* constant.
* @return string|false The named key or false.
*
* @phpstan-param int<-1, 7> $constant
* @phpstan-return 'scheme'|'host'|'port'|'user'|'pass'|'path'|'query'|'fragment'|false
*/
function _wp_translate_php_url_constant_to_key( $constant ) {
$translation = array(
Expand Down
18 changes: 15 additions & 3 deletions src/wp-includes/l10n.php
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,7 @@ function load_script_module_textdomain( string $id, string $domain = 'default',
* @return string|false The JSON-encoded translated strings on success, false otherwise.
*/
function _load_script_textdomain_from_src( string $handle, string $src, string $domain, string $path, bool $is_module ) {
/** @var WP_Textdomain_Registry $wp_textdomain_registry */
global $wp_textdomain_registry;

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

$path = untrailingslashit( $path );
if ( $path ) {
Copy link
Copy Markdown
Member Author

@westonruter westonruter Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditional added because the $path can still be false here since $wp_textdomain_registry->get() returns string|false.

$path = untrailingslashit( $path );
}

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

$src_url = wp_parse_url( $src );
$src_url = wp_parse_url( $src );
if ( ! $src_url ) {
return load_script_translations( false, $handle, $domain );
}
$src_url['path'] ??= '';
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the crux for fixing the undefined index error.


$content_url = wp_parse_url( content_url() );
if ( ! $content_url ) {
return load_script_translations( false, $handle, $domain );
}

$plugins_url = wp_parse_url( plugins_url() );
$site_url = wp_parse_url( site_url() );
$theme_root = get_theme_root();
Expand Down Expand Up @@ -1304,7 +1316,7 @@ function _load_script_textdomain_from_src( string $handle, string $src, string $
$relative = apply_filters( 'load_script_textdomain_relative_path', $relative, $src, $is_module );

// If the source is not from WP.
if ( false === $relative ) {
if ( ! is_string( $relative ) ) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since apply_filters() can return anything, safer to check for a string specifically than for equality with false.

return load_script_translations( false, $handle, $domain );
}

Expand Down
Loading