[wp-trac] [WordPress Trac] #60888: Fatal error when passing non-strings to `WP_Translation_Controller::load_file()`

WordPress Trac noreply at wordpress.org
Tue Apr 2 22:18:08 UTC 2024


#60888: Fatal error when passing non-strings to
`WP_Translation_Controller::load_file()`
--------------------------+------------------------------------------
 Reporter:  swissspidy    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  assigned
 Priority:  normal        |  Milestone:  6.5.1
Component:  I18N          |    Version:
 Severity:  normal        |   Keywords:  needs-patch needs-unit-tests
  Focuses:                |
--------------------------+------------------------------------------
 Some plugins/themes such as Divi for example call
 `load_plugin_textdomain()` with a `$domain` value of `null` instead of a
 string, which is plain wrong and unsupported:
 `load_plugin_textdomain(NULL, false, 'includes/langua...')`.

 This leads to this fatal error:

 {{{
 PHP Fatal error:  Uncaught TypeError:
 WP_Translation_Controller::load_file(): Argument #2 ($textdomain) must be
 of type string, null given,
 }}}

 Props @verygoode for investigating and reporting
 [https://wordpress.slack.com/archives/C02RQBWTW/p1712093373518739 in this
 Slack thread].

 While a non-string text domain is really not supported and will lead to
 way more undefined behavior than just this error, there seem to be enough
 affected plugins (basically any Divi extension) that it's worth fixing
 this in core by adding some hardening (or well, softening).

 We could add some hardening to `load_textdomain()` and
 `load_plugin_textdomain()` et al to basically do `if ( ! is_string(
 $domain ) ) { $domain = 'default'; }`. That would be the most robust
 solution at the right level.

 Definitely needs some unit tests to verify this.

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


More information about the wp-trac mailing list