[wp-trac] [WordPress Trac] #54776: passing empty object to wp_localize_script will convert it to empty array instead of empty object
WordPress Trac
noreply at wordpress.org
Mon Jan 10 10:38:57 UTC 2022
#54776: passing empty object to wp_localize_script will convert it to empty array
instead of empty object
--------------------------+-----------------------------
Reporter: erikdemarco | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
This will correctly converted to js object:
wp_localize_script( $handle, $object_name, array(
"foo" => "Foo value",
"bar" => "Bar value"
) );
But passing empty array will be converted to js empty array:
wp_localize_script( $handle, $object_name, array() );
We want to pass empty array because we want to prepare the global js
variable to be used later. But because of the inconsistency it can cause
problem if we want to loop it. since we use different method to loop
object and array in javascript.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54776>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list