[wp-trac] [WordPress Trac] #60862: wp_localize_script() on login_enqueue_scripts hook change in behavior

WordPress Trac noreply at wordpress.org
Fri Mar 29 18:09:27 UTC 2024


#60862: wp_localize_script() on login_enqueue_scripts hook change in behavior
------------------------------------+-----------------------------
 Reporter:  salcode                 |      Owner:  (none)
     Type:  defect (bug)            |     Status:  new
 Priority:  normal                  |  Milestone:  Awaiting Review
Component:  Login and Registration  |    Version:  trunk
 Severity:  normal                  |   Keywords:
  Focuses:                          |
------------------------------------+-----------------------------
 I'm seeing this change in behavior going from `6.4.3` to `6.5-RC4`.

 When I add the following code snippet to a file in `mu-plugins`.

 {{{
 <?php

 add_action(
   'login_enqueue_scripts',
   function() {
     wp_localize_script(
       'wp-util',
       'salcodeExample',
       [
         'answerToTheUltimateQuestionOfLifeTheUniverseAndEverything' => 42,
       ]
     );
   }
 );
 }}}

 and then I go to `/wp-login.php` and View Source.

 == 6.4.3 and below

 I see the line

 {{{
 var salcodeExample =
 {"answerToTheUltimateQuestionOfLifeTheUniverseAndEverything":"42"};
 }}}

 inside the `<script type="text/javascript" id="wp-util-js-extra">` block.

 This is the expected behavior.

 == 6.5-RC4

 The `<script type="text/javascript" id="wp-util-js-extra">` block is still
 included but the line we added via our code does NOT appear.

 == Notes:

 1. I've tested with both the `wp-util` and the `user-profile` hooks and
 get the same behavior.
 2. I'm only seeing this behavior when calling `wp_localize_script()` on
 the `login_enqueue_scripts` (specifically, I'm not seeing this behavior
 when using the `wp_enqueue_scripts` hook)
 3. This issue was originally identified in this GitHub issue
 https://github.com/salcode/wp-fast-login/issues/26

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


More information about the wp-trac mailing list