Skip to content

Commit 7a74026

Browse files
I18N: Use correct default value for JavaScript translations path.
The `$path` parameter of some script translation functions had a default value of `null`, even though the parameter is documented as a string. This commit corrects the default value for `$path` in: * `WP_Dependency::set_translations()` * `WP_Scripts::set_translations()` * `wp_set_script_translations()` Additionally, this commit removes an `is_string()` check for `$path` in `load_script_textdomain()`. Now that the default value for `$path` in that function has also been corrected to an empty string instead of `null`, that check is no longer necessary, as it would ''hide'' an error which should be ''fixed'' (at the source of the problem) instead. Follow-up to [54349]. Props jrf, johnjamesjacoby. See #55967, #55656. git-svn-id: https://develop.svn.wordpress.org/trunk@54351 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 30c03e4 commit 7a74026

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

src/wp-includes/class-wp-dependency.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function add_data( $name, $data ) {
126126
* @param string $path Optional. The full file path to the directory containing translation files.
127127
* @return bool False if $domain is not a string, true otherwise.
128128
*/
129-
public function set_translations( $domain, $path = null ) {
129+
public function set_translations( $domain, $path = '' ) {
130130
if ( ! is_string( $domain ) ) {
131131
return false;
132132
}

src/wp-includes/class-wp-scripts.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ public function set_group( $handle, $recursion, $group = false ) {
573573
* @param string $path Optional. The full file path to the directory containing translation files.
574574
* @return bool True if the text domain was registered, false if not.
575575
*/
576-
public function set_translations( $handle, $domain = 'default', $path = null ) {
576+
public function set_translations( $handle, $domain = 'default', $path = '' ) {
577577
if ( ! isset( $this->registered[ $handle ] ) ) {
578578
return false;
579579
}
@@ -605,7 +605,11 @@ public function print_translations( $handle, $display = true ) {
605605
}
606606

607607
$domain = $this->registered[ $handle ]->textdomain;
608-
$path = $this->registered[ $handle ]->translations_path;
608+
$path = '';
609+
610+
if ( isset( $this->registered[ $handle ]->translations_path ) ) {
611+
$path = $this->registered[ $handle ]->translations_path;
612+
}
609613

610614
$json_translations = load_script_textdomain( $handle, $domain, $path );
611615

src/wp-includes/functions.wp-scripts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function wp_localize_script( $handle, $object_name, $l10n ) {
237237
* @param string $path Optional. The full file path to the directory containing translation files.
238238
* @return bool True if the text domain was successfully localized, false otherwise.
239239
*/
240-
function wp_set_script_translations( $handle, $domain = 'default', $path = null ) {
240+
function wp_set_script_translations( $handle, $domain = 'default', $path = '' ) {
241241
global $wp_scripts;
242242

243243
if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {

src/wp-includes/l10n.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,10 +1065,7 @@ function load_script_textdomain( $handle, $domain = 'default', $path = '' ) {
10651065
return false;
10661066
}
10671067

1068-
if ( is_string( $path ) ) {
1069-
$path = untrailingslashit( $path );
1070-
}
1071-
1068+
$path = untrailingslashit( $path );
10721069
$locale = determine_locale();
10731070

10741071
// If a path was given and the handle file exists simply return it.

0 commit comments

Comments
 (0)