Make WordPress Core

Changeset 44310


Ignore:
Timestamp:
12/18/2018 11:09:51 PM (6 years ago)
Author:
desrosj
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, herregroen.

Merges [44209] to trunk.

Fixes #45528.

Location:
trunk
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/l10n.php

    r44278 r44310  
    913913    global $wp_scripts;
    914914
     915    if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
     916        return false;
     917    }
     918
    915919    $path   = untrailingslashit( $path );
    916920    $locale = determine_locale();
     
    925929    $obj = $wp_scripts->registered[ $handle ];
    926930
     931    $src = $obj->src;
     932    if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && 0 === strpos( $src, $wp_scripts->content_url ) ) ) {
     933        $src = $wp_scripts->base_url . $src;
     934    }
    927935    /** This filter is documented in wp-includes/class.wp-scripts.php */
    928     $src = esc_url( apply_filters( 'script_loader_src', $obj->src, $handle ) );
     936    $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
    929937
    930938    $relative       = false;
     
    938946    if (
    939947        strpos( $src_url['path'], $content_url['path'] ) === 0 &&
    940         ( ! isset( $src_url['host'] ) || $src_url['host'] !== $content_url['host'] )
     948        ( ! isset( $src_url['host'] ) || $src_url['host'] === $content_url['host'] )
    941949    ) {
    942950        // Make the src relative the specific plugin or theme.
    943         $relative = trim( substr( $src, strlen( $content_url['path'] ) ), '/' );
     951        $relative = trim( substr( $src_url['path'], strlen( $content_url['path'] ) ), '/' );
    944952        $relative = explode( '/', $relative );
    945953
     
    948956        $relative = array_slice( $relative, 2 );
    949957        $relative = implode( '/', $relative );
    950     } elseif ( ! isset( $src_url['host'] ) || $src_url['host'] !== $site_url['host'] ) {
     958    } elseif ( ! isset( $src_url['host'] ) || $src_url['host'] === $site_url['host'] ) {
    951959        if ( ! isset( $site_url['path'] ) ) {
    952960            $relative = trim( $src_url['path'], '/' );
    953         } elseif ( ( strpos( $src_url['path'], $site_url['path'] ) === 0 ) ) {
     961        } elseif ( ( strpos( $src_url['path'], trailingslashit( $site_url['path'] ) ) === 0 ) ) {
    954962            // Make the src relative to the WP root.
    955             $relative = substr( $src, strlen( $site_url['path'] ) );
     963            $relative = substr( $src_url['path'], strlen( $site_url['path'] ) );
    956964            $relative = trim( $relative, '/' );
    957965        }
    958966    }
     967
     968    /**
     969     * Filters the relative path of scripts used for finding translation files.
     970     *
     971     * @since 5.0.2
     972     *
     973     * @param string $relative The relative path of the script. False if it could not be determined.
     974     * @param string $src      The full source url of the script.
     975     */
     976    $relative = apply_filters( 'load_script_textdomain_relative_path', $relative, $src );
    959977
    960978    // If the source is not from WP.
Note: See TracChangeset for help on using the changeset viewer.