WordPress.org

Make WordPress Core

Changeset 44209


Ignore:
Timestamp:
12/15/2018 12:54:54 PM (9 months ago)
Author:
herregroen
Message:

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.

Location:
branches/5.0
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/l10n.php

    r43959 r44209  
    889889    global $wp_scripts;
    890890
     891    if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
     892        return false;
     893    }
     894
    891895    $path   = untrailingslashit( $path );
    892896    $locale = determine_locale();
     
    901905    $obj = $wp_scripts->registered[ $handle ];
    902906
     907    $src = $obj->src;
     908    if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && 0 === strpos( $src, $wp_scripts->content_url ) ) ) {
     909        $src = $wp_scripts->base_url . $src;
     910    }
    903911    /** This filter is documented in wp-includes/class.wp-scripts.php */
    904     $src = esc_url( apply_filters( 'script_loader_src', $obj->src, $handle ) );
     912    $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
    905913
    906914    $relative       = false;
     
    914922    if (
    915923        strpos( $src_url['path'], $content_url['path'] ) === 0 &&
    916         ( ! isset( $src_url['host'] ) || $src_url['host'] !== $content_url['host'] )
     924        ( ! isset( $src_url['host'] ) || $src_url['host'] === $content_url['host'] )
    917925    ) {
    918926        // Make the src relative the specific plugin or theme.
    919         $relative = trim( substr( $src, strlen( $content_url['path'] ) ), '/' );
     927        $relative = trim( substr( $src_url['path'], strlen( $content_url['path'] ) ), '/' );
    920928        $relative = explode( '/', $relative );
    921929
     
    924932        $relative = array_slice( $relative, 2 );
    925933        $relative = implode( '/', $relative );
    926     } elseif ( ! isset( $src_url['host'] ) || $src_url['host'] !== $site_url['host'] ) {
     934    } elseif ( ! isset( $src_url['host'] ) || $src_url['host'] === $site_url['host'] ) {
    927935        if ( ! isset( $site_url['path'] ) ) {
    928936            $relative = trim( $src_url['path'], '/' );
    929         } elseif ( ( strpos( $src_url['path'], $site_url['path'] ) === 0 ) ) {
     937        } elseif ( ( strpos( $src_url['path'], trailingslashit( $site_url['path'] ) ) === 0 ) ) {
    930938            // Make the src relative to the WP root.
    931             $relative = substr( $src, strlen( $site_url['path'] ) );
     939            $relative = substr( $src_url['path'], strlen( $site_url['path'] ) );
    932940            $relative = trim( $relative, '/' );
    933941        }
    934942    }
     943
     944    /**
     945     * Filters the relative path of scripts used for finding translation files.
     946     *
     947     * @since 5.0.2
     948     *
     949     * @param string $relative The relative path of the script. False if it could not be determined.
     950     * @param string $src      The full source url of the script.
     951     */
     952    $relative = apply_filters( 'load_script_textdomain_relative_path', $relative, $src );
    935953
    936954    // If the source is not from WP.
Note: See TracChangeset for help on using the changeset viewer.