Make WordPress Core

Changeset 59126


Ignore:
Timestamp:
09/30/2024 02:57:32 PM (6 weeks ago)
Author:
swissspidy
Message:

I18N: Fix script languages path for themes.

Remove hardcoded path added in [57922] which ignored the fact that themes can also use script translations.
They should not be affected even if plugins are installed outside the typical wp-content/plugins location.

Props itapress, swissspidy.
Fixes #62016.

Location:
trunk
Files:
2 edited

Legend:

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

    r59029 r59126  
    12081208        $relative = explode( '/', $relative );
    12091209
    1210         $languages_path = WP_LANG_DIR . '/plugins';
     1210        /*
     1211         * Ensure correct languages path when using a custom `WP_PLUGIN_DIR` / `WP_PLUGIN_URL` configuration.
     1212         * See https://core.trac.wordpress.org/ticket/60891 and https://core.trac.wordpress.org/ticket/62016.
     1213         */
     1214        $plugins_dir = array_slice( explode( '/', $plugins_url['path'] ), 2 );
     1215        $plugins_dir = trim( $plugins_dir[0], '/' );
     1216        $dirname     = $plugins_dir === $relative[0] ? 'plugins' : 'themes';
     1217
     1218        $languages_path = WP_LANG_DIR . '/' . $dirname;
    12111219
    12121220        $relative = array_slice( $relative, 2 ); // Remove plugins/<plugin name> or themes/<theme name>.
  • trunk/tests/phpunit/tests/l10n/loadScriptTextdomain.php

    r57922 r59126  
    1515     * @ticket 49145
    1616     * @ticket 60891
     17     * @ticket 62016
    1718     *
    1819     * @dataProvider data_resolve_relative_path
     
    136137                ),
    137138            ),
     139            // @ticket 62016
     140            array(
     141                '/languages/themes/internationalized-theme-en_US-2f86cb96a0233e7cb3b6f03ad573be0b.json',
     142                'theme-with-script-translations',
     143                '/wp-content/themes/my-theme/js/script.js',
     144                'internationalized-theme',
     145            ),
    138146        );
    139147    }
Note: See TracChangeset for help on using the changeset viewer.