Make WordPress Core


Ignore:
Timestamp:
07/27/2019 12:43:56 PM (5 years ago)
Author:
ocean90
Message:

I18N: Add support for custom WP_PLUGIN_URL in load_script_textdomain().

Plugins may not be on the same host/path as the rest of the content. To support loading translations for this setup check if the script source matches plugins_url().
Also fixes an undefined index notice when a custom content URL has no path.

Props odminstudios, ocean90.
Fixes #46336, #46387.

File:
1 edited

Legend:

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

    r45590 r45685  
    949949    $src_url     = wp_parse_url( $src );
    950950    $content_url = wp_parse_url( content_url() );
     951    $plugins_url = wp_parse_url( plugins_url() );
    951952    $site_url    = wp_parse_url( site_url() );
    952953
    953954    // If the host is the same or it's a relative URL.
    954955    if (
    955         strpos( $src_url['path'], $content_url['path'] ) === 0 &&
     956        ( ! isset( $content_url['path'] ) || strpos( $src_url['path'], $content_url['path'] ) === 0 ) &&
    956957        ( ! isset( $src_url['host'] ) || $src_url['host'] === $content_url['host'] )
    957958    ) {
    958959        // Make the src relative the specific plugin or theme.
    959         $relative = trim( substr( $src_url['path'], strlen( $content_url['path'] ) ), '/' );
     960        if ( isset( $content_url['path'] ) ) {
     961            $relative = substr( $src_url['path'], strlen( $content_url['path'] ) );
     962        } else {
     963            $relative = $src_url['path'];
     964        }
     965        $relative = trim( $relative, '/' );
    960966        $relative = explode( '/', $relative );
    961967
    962968        $languages_path = WP_LANG_DIR . '/' . $relative[0];
    963969
    964         $relative = array_slice( $relative, 2 );
     970        $relative = array_slice( $relative, 2 ); // Remove plugins/<plugin name> or themes/<theme name>.
     971        $relative = implode( '/', $relative );
     972    } elseif (
     973        ( ! isset( $plugins_url['path'] ) || strpos( $src_url['path'], $plugins_url['path'] ) === 0 ) &&
     974        ( ! isset( $src_url['host'] ) || $src_url['host'] === $plugins_url['host'] )
     975    ) {
     976        // Make the src relative the specific plugin.
     977        if ( isset( $plugins_url['path'] ) ) {
     978            $relative = substr( $src_url['path'], strlen( $plugins_url['path'] ) );
     979        } else {
     980            $relative = $src_url['path'];
     981        }
     982        $relative = trim( $relative, '/' );
     983        $relative = explode( '/', $relative );
     984
     985        $languages_path = WP_LANG_DIR . '/plugins';
     986
     987        $relative = array_slice( $relative, 1 ); // Remove <plugin name>.
    965988        $relative = implode( '/', $relative );
    966989    } elseif ( ! isset( $src_url['host'] ) || $src_url['host'] === $site_url['host'] ) {
Note: See TracChangeset for help on using the changeset viewer.