[wp-trac] [WordPress Trac] #62424: Warning in wp_salt() since 6.7

WordPress Trac noreply at wordpress.org
Tue Nov 19 18:33:11 UTC 2024


#62424: Warning in wp_salt() since 6.7
-------------------------------------------------+-------------------------
 Reporter:  juliobox                             |       Owner:  desrosj
     Type:  defect (bug)                         |      Status:  assigned
 Priority:  normal                               |   Milestone:  6.7.1
Component:  Options, Meta APIs                   |     Version:  6.7
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-screenshots has-       |     Focuses:
  testing-info reporter-feedback                 |
-------------------------------------------------+-------------------------
Changes (by desrosj):

 * keywords:  has-patch has-screenshots has-testing-info => has-patch has-
     screenshots has-testing-info reporter-feedback


Comment:

 This seems to be caused by the fact that `get_user_locale()` is called
 within the `gettext` filter. Removing that function silences the warnings.

 In my testing, it also does not matter where the constants are defined
 (`wp-config.php`, MU plugin, etc.). It is only important that they are
 defined and salts stored in the options table are not being used.

 The problem is that there is one string translated within `wp_salts()`,
 but it's only translated the first time the function runs when
 `$duplicate_keys` is `null`.  So the order goes something like this:
 - `wp_salts()` called first time.
 - the `static $duplicated_keys` is `null`, so that conditional statement
 is `true`.
 - The first thing that block of code does is sets `$duplicated_keys` to an
 array containing the default `put your unique phrase here` value.
 - Then that phrase is passed through `__()` in case the config file is
 localized.
 - The provided example `gettext` filter is run, and `get_user_locale()`
 eventually calls `wp_salt()` again while determining who the current user
 is.
 - When the `null === $duplicate_keys` condition is encountered, it's no
 longer `true` because it's `static` and now set to the default.
 - The function continues, and the condition throws the warnings because
 the constant is in fact set, it's just not populated into
 `$duplicate_keys` as expected.
 - Eventually, the initial call to the function completes and the `static`
 variable is fully populated with all of the defined constants. All
 subsequent `wp_salt()` calls work as expected without throwing warnings.

 I'm now of the opinion that an `isset()` check is not the correct change
 to make here as this new code added in [58837] is clearly surfacing an
 edge case that was not previously exposed.

 One way to fix this issue is to establish the current user ''before''
 `wp_salt()` is called. There may be better hooks to use, but this worked
 in my testing:

 {{{
 add_filter( 'setup_theme', function() {
         wp_get_current_user();
 });
 }}}

 I'm not familiar enough with how `gettext` is used in the wild for
 filtering translations. Could you share more context around your use case
 @juliobox?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62424#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list