Make WordPress Core


Ignore:
Timestamp:
09/28/2022 10:17:38 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

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

    r54254 r54351  
    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;
     
    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 );
Note: See TracChangeset for help on using the changeset viewer.