WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#23590 closed enhancement (wontfix)

Rename wp_localize_script

Reported by: bftrick Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:
PR Number:

Description

Hello,

It's never made any sense to me to call a function that makes data from a php file accessible to a js file localize script. The name localize script makes me think of passing language specific data to a script. That is a valid and useful use of that method but it is only one use. It is similar to calling a spoon a cereal delivery system.

If we can give it a better name then other developers will be better able to find it an use it instead of coming up with their own methods (like embedding JS in a php file; eek!).

If you do a Google search for "pass php variable to js in wordpress" you get a lot of: "I didn't know how to do this until someone told me about this function". Here's some of the confusion:

For backwards compatibility would could make the wp_localize_script function an alias of the new method.

Change History (3)

#1 @SergeyBiryukov
7 years ago

  • Severity changed from trivial to normal

Related: #11520, #21547

[18464] introduced wp_add_script_data(), which was later reverted in [18490] and [18491].

[19217] introduced wp_add_script_before(), which was later reverted in [19573].

Relevant IRC discussion: https://irclogs.wordpress.org/chanlog.php?channel=wordpress-dev&day=2011-12-08&sort=asc#m342977

#2 @bftrick
7 years ago

  • Resolution set to fixed
  • Status changed from new to closed

@SergeyBiryukov Thanks for the related tickets! :)

It's good to know this has been talked by other people. We can close the ticket since there already has been a mountain of discussion about this.

#3 @SergeyBiryukov
7 years ago

  • Milestone Awaiting Review deleted
  • Resolution changed from fixed to wontfix
Note: See TracTickets for help on using tickets.