[wp-trac] [WordPress Trac] #56393: Invalid default value for WP_Scripts->set_translations $path argument

WordPress Trac noreply at wordpress.org
Tue Aug 16 19:00:58 UTC 2022


#56393: Invalid default value for WP_Scripts->set_translations $path argument
---------------------------+-----------------------------
 Reporter:  iviweb         |      Owner:  iviweb
     Type:  defect (bug)   |     Status:  assigned
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Script Loader  |    Version:  trunk
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 Currently WP_Scripts->set_translations have arguments with bellow
 signature:


 {{{
  * @param string $handle Name of the script to register a translation
 domain to.
  * @param string $domain Optional. Text domain. Default 'default'.
  * @param string $path   Optional. The full file path to the directory
 containing translation files.
 }}}

 But for $path argument default value is set as NULL.

 WP_Scripts extends from WP_Dependencies, which have items _WP_Dependency,
 in this class we also have set_translations method with arguments:


 {{{
 * @param string $domain The translation textdomain.
 * @param string $path   Optional. The full file path to the directory
 containing translation files.

 }}}

 And there also $path  default value is NULL.


 These methods are calling load_script_textdomain function, which also have
 the same issue. Declared signature:

 {{{
  * @param string $handle Name of the script to register a translation
 domain to.
  * @param string $domain Optional. Text domain. Default 'default'.
  * @param string $path   Optional. The full file path to the directory
 containing translation files.
 }}}

 and default for $path is NULL.

 All these signature/default differences cause issue:

 {{{
 PHP Deprecated:  rtrim(): Passing null to parameter #1 ($string) of type
 string is deprecated in C:\xampp\htdocs\tps\wp-includes\formatting.php on
 line 2772
 }}}

 because finally these methods are using

 {{{#!php
 <?php
 $path   = untrailingslashit( $path );
 }}}

 which is called rtrim() with passed $path, and we are getting warning
 about invalid input type.

 So, we need for all these methods to set $path argument default value as
 empty string, instead of NULL

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56393>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list