[wp-trac] [WordPress Trac] #58873: Add function to pass variables to scripts

WordPress Trac noreply at wordpress.org
Thu Aug 14 09:06:03 UTC 2025


#58873: Add function to pass variables to scripts
-----------------------------+-------------------------
 Reporter:  apedog           |       Owner:  (none)
     Type:  feature request  |      Status:  closed
 Priority:  normal           |   Milestone:
Component:  Script Loader    |     Version:  5.7
 Severity:  normal           |  Resolution:  worksforme
 Keywords:                   |     Focuses:
-----------------------------+-------------------------
Changes (by jonsurrell):

 * status:  new => closed
 * resolution:   => worksforme
 * milestone:  Awaiting Review =>


Comment:

 > Since WordPress 5.7 using `wp_localize_scripts` to pass variables to
 registered scripts throws a `_doing_it_wrong` notice.

 I don't see a general `_doing_it_wrong` notice.
 [https://core.trac.wordpress.org/browser/tags/6.8.2/src/wp-includes/class-
 wp-scripts.php#L570 I do see a notice if the value is not an array.]

 I don't believe there's any general warning about using
 `wp_localize_script()`. If you provide a reproducible example of how the
 warning is generated, I'm happy to take a look.

 I agree with much of your feedback about how data is passed to scripts.
 However, with these with these systems established, in place, and
 generally working well, it's hard to advocate to add another different
 system without really compelling justification.

 One note, ''Script Modules'', use a different system that's simpler.
 [https://developer.wordpress.org/reference/hooks/script_module_data_module_id/
 You can read about it here.]

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


More information about the wp-trac mailing list