Changeset 45685
- Timestamp:
- 07/27/2019 12:43:56 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/l10n.php
r45590 r45685 949 949 $src_url = wp_parse_url( $src ); 950 950 $content_url = wp_parse_url( content_url() ); 951 $plugins_url = wp_parse_url( plugins_url() ); 951 952 $site_url = wp_parse_url( site_url() ); 952 953 953 954 // If the host is the same or it's a relative URL. 954 955 if ( 955 strpos( $src_url['path'], $content_url['path'] ) === 0&&956 ( ! isset( $content_url['path'] ) || strpos( $src_url['path'], $content_url['path'] ) === 0 ) && 956 957 ( ! isset( $src_url['host'] ) || $src_url['host'] === $content_url['host'] ) 957 958 ) { 958 959 // 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, '/' ); 960 966 $relative = explode( '/', $relative ); 961 967 962 968 $languages_path = WP_LANG_DIR . '/' . $relative[0]; 963 969 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>. 965 988 $relative = implode( '/', $relative ); 966 989 } elseif ( ! isset( $src_url['host'] ) || $src_url['host'] === $site_url['host'] ) { -
trunk/tests/phpunit/tests/l10n/loadScriptTextdomain.php
r44310 r45685 16 16 17 17 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'; 18 26 } 19 27 … … 39 47 remove_filter( 'site_url', array( $this, 'site_url_subdirectory' ) ); 40 48 } 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 } 41 73 }
Note: See TracChangeset
for help on using the changeset viewer.