diff --git a/src/wp-includes/http.php b/src/wp-includes/http.php index 643efc0a16930..8280f424934dd 100644 --- a/src/wp-includes/http.php +++ b/src/wp-includes/http.php @@ -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 + * ) + * ) */ function wp_parse_url( $url, $component = -1 ) { $to_unset = array(); @@ -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 + * ) + * ) */ function _get_component_from_parsed_url_array( $url_parts, $component = -1 ) { if ( -1 === $component ) { @@ -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( diff --git a/src/wp-includes/l10n.php b/src/wp-includes/l10n.php index ee2dfc5dd308b..2f27c2180037a 100644 --- a/src/wp-includes/l10n.php +++ b/src/wp-includes/l10n.php @@ -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(); @@ -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 ) { + $path = untrailingslashit( $path ); + } // If a path was given and the handle file exists simply return it. $file_base = 'default' === $domain ? $locale : $domain . '-' . $locale; @@ -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'] ??= ''; + $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(); @@ -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 ) ) { return load_script_translations( false, $handle, $domain ); }