I18N: Fix JavaScript translations for subdirectory installations.
Fixes the `load_script_textdomain` function not resolving the md5 hash based on the relative path for WordPress installations in a subdirectory. Also adds a filter to allow sites using CDNs or other alternative asset locations to filter the relative path resolution. Props akirk, fierevere, swissspidy, mypacecreator, babaevan, tmatsuur, ocean90. Fixes #45528. Built from https://develop.svn.wordpress.org/branches/5.0@44209 git-svn-id: http://core.svn.wordpress.org/branches/5.0@44039 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d1a1778fa1
commit
fd7d1f576c
|
@ -888,6 +888,10 @@ function load_child_theme_textdomain( $domain, $path = false ) {
|
||||||
function load_script_textdomain( $handle, $domain, $path = null ) {
|
function load_script_textdomain( $handle, $domain, $path = null ) {
|
||||||
global $wp_scripts;
|
global $wp_scripts;
|
||||||
|
|
||||||
|
if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$path = untrailingslashit( $path );
|
$path = untrailingslashit( $path );
|
||||||
$locale = determine_locale();
|
$locale = determine_locale();
|
||||||
|
|
||||||
|
@ -900,8 +904,12 @@ function load_script_textdomain( $handle, $domain, $path = null ) {
|
||||||
|
|
||||||
$obj = $wp_scripts->registered[ $handle ];
|
$obj = $wp_scripts->registered[ $handle ];
|
||||||
|
|
||||||
|
$src = $obj->src;
|
||||||
|
if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && 0 === strpos( $src, $wp_scripts->content_url ) ) ) {
|
||||||
|
$src = $wp_scripts->base_url . $src;
|
||||||
|
}
|
||||||
/** This filter is documented in wp-includes/class.wp-scripts.php */
|
/** This filter is documented in wp-includes/class.wp-scripts.php */
|
||||||
$src = esc_url( apply_filters( 'script_loader_src', $obj->src, $handle ) );
|
$src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
|
||||||
|
|
||||||
$relative = false;
|
$relative = false;
|
||||||
$languages_path = WP_LANG_DIR;
|
$languages_path = WP_LANG_DIR;
|
||||||
|
@ -913,26 +921,36 @@ function load_script_textdomain( $handle, $domain, $path = null ) {
|
||||||
// If the host is the same or it's a relative URL.
|
// If the host is the same or it's a relative URL.
|
||||||
if (
|
if (
|
||||||
strpos( $src_url['path'], $content_url['path'] ) === 0 &&
|
strpos( $src_url['path'], $content_url['path'] ) === 0 &&
|
||||||
( ! isset( $src_url['host'] ) || $src_url['host'] !== $content_url['host'] )
|
( ! isset( $src_url['host'] ) || $src_url['host'] === $content_url['host'] )
|
||||||
) {
|
) {
|
||||||
// Make the src relative the specific plugin or theme.
|
// Make the src relative the specific plugin or theme.
|
||||||
$relative = trim( substr( $src, strlen( $content_url['path'] ) ), '/' );
|
$relative = trim( substr( $src_url['path'], strlen( $content_url['path'] ) ), '/' );
|
||||||
$relative = explode( '/', $relative );
|
$relative = explode( '/', $relative );
|
||||||
|
|
||||||
$languages_path = WP_LANG_DIR . '/' . $relative[0];
|
$languages_path = WP_LANG_DIR . '/' . $relative[0];
|
||||||
|
|
||||||
$relative = array_slice( $relative, 2 );
|
$relative = array_slice( $relative, 2 );
|
||||||
$relative = implode( '/', $relative );
|
$relative = implode( '/', $relative );
|
||||||
} elseif ( ! isset( $src_url['host'] ) || $src_url['host'] !== $site_url['host'] ) {
|
} elseif ( ! isset( $src_url['host'] ) || $src_url['host'] === $site_url['host'] ) {
|
||||||
if ( ! isset( $site_url['path'] ) ) {
|
if ( ! isset( $site_url['path'] ) ) {
|
||||||
$relative = trim( $src_url['path'], '/' );
|
$relative = trim( $src_url['path'], '/' );
|
||||||
} elseif ( ( strpos( $src_url['path'], $site_url['path'] ) === 0 ) ) {
|
} elseif ( ( strpos( $src_url['path'], trailingslashit( $site_url['path'] ) ) === 0 ) ) {
|
||||||
// Make the src relative to the WP root.
|
// Make the src relative to the WP root.
|
||||||
$relative = substr( $src, strlen( $site_url['path'] ) );
|
$relative = substr( $src_url['path'], strlen( $site_url['path'] ) );
|
||||||
$relative = trim( $relative, '/' );
|
$relative = trim( $relative, '/' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters the relative path of scripts used for finding translation files.
|
||||||
|
*
|
||||||
|
* @since 5.0.2
|
||||||
|
*
|
||||||
|
* @param string $relative The relative path of the script. False if it could not be determined.
|
||||||
|
* @param string $src The full source url of the script.
|
||||||
|
*/
|
||||||
|
$relative = apply_filters( 'load_script_textdomain_relative_path', $relative, $src );
|
||||||
|
|
||||||
// If the source is not from WP.
|
// If the source is not from WP.
|
||||||
if ( false === $relative ) {
|
if ( false === $relative ) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.0.2-alpha-44208';
|
$wp_version = '5.0.2-alpha-44209';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue