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/tests/phpunit/tests/l10n/loadScriptTextdomain.php

    r44310 r45685  
    1616
    1717        return $relative;
     18    }
     19
     20    public function plugins_url_custom_domain() {
     21        return 'https://plugins.example.com';
     22    }
     23
     24    public function content_url_custom_domain_with_no_path() {
     25        return 'https://content.example.com';
    1826    }
    1927
     
    3947        remove_filter( 'site_url', array( $this, 'site_url_subdirectory' ) );
    4048    }
     49
     50    /**
     51     * @ticket 46336
     52     */
     53    public function test_resolve_relative_path_custom_plugins_url() {
     54        $json_translations = file_get_contents( DIR_TESTDATA . '/languages/plugins/internationalized-plugin-en_US-2f86cb96a0233e7cb3b6f03ad573be0b.json' );
     55
     56        add_filter( 'plugins_url', array( $this, 'plugins_url_custom_domain' ) );
     57        wp_enqueue_script( 'plugin-example-1', 'https://plugins.example.com/my-plugin/js/script.js', array(), null );
     58        $this->assertEquals( $json_translations, load_script_textdomain( 'plugin-example-1', 'internationalized-plugin', DIR_TESTDATA . '/languages' ) );
     59        remove_filter( 'plugins_url', array( $this, 'plugins_url_custom_domain' ) );
     60    }
     61
     62    /**
     63     * @ticket 46387
     64     */
     65    public function test_resolve_relative_path_custom_content_url() {
     66        $json_translations = file_get_contents( DIR_TESTDATA . '/languages/plugins/internationalized-plugin-en_US-2f86cb96a0233e7cb3b6f03ad573be0b.json' );
     67
     68        add_filter( 'content_url', array( $this, 'content_url_custom_domain_with_no_path' ) );
     69        wp_enqueue_script( 'plugin-example-2', 'https://content.example.com/plugins/my-plugin/js/script.js', array(), null );
     70        $this->assertEquals( $json_translations, load_script_textdomain( 'plugin-example-2', 'internationalized-plugin', DIR_TESTDATA . '/languages' ) );
     71        remove_filter( 'content_url', array( $this, 'content_url_custom_domain_with_no_path' ) );
     72    }
    4173}
Note: See TracChangeset for help on using the changeset viewer.