1 | Index: wp-includes/class.wp-scripts.php |
---|
2 | =================================================================== |
---|
3 | --- wp-includes/class.wp-scripts.php (revision 19732) |
---|
4 | +++ wp-includes/class.wp-scripts.php (working copy) |
---|
5 | @@ -54,15 +54,34 @@ |
---|
6 | } |
---|
7 | |
---|
8 | function print_extra_script( $handle, $echo = true ) { |
---|
9 | - if ( !$output = $this->get_data( $handle, 'data' ) ) |
---|
10 | + $vars = $this->get_data($handle, 'data'); |
---|
11 | + if (empty($vars) || !is_array($vars)) { |
---|
12 | return; |
---|
13 | + } |
---|
14 | + |
---|
15 | + $output = ''; |
---|
16 | + foreach ($vars as $var=>$obj) { |
---|
17 | + if ( is_array($obj) && isset($obj['l10n_print_after']) ) { // back compat, preserve the code in 'l10n_print_after' if present |
---|
18 | + $after = $obj['l10n_print_after']; |
---|
19 | + unset($obj['l10n_print_after']); |
---|
20 | + } |
---|
21 | + |
---|
22 | + if (is_string($obj)) { |
---|
23 | + $obj = html_entity_decode( $obj, ENT_QUOTES, 'UTF-8'); |
---|
24 | + } |
---|
25 | + |
---|
26 | + $output .= "var $var = " . json_encode($obj) . ";\n"; |
---|
27 | + if (!empty($after)) { |
---|
28 | + $output .= "$after\n"; |
---|
29 | + } |
---|
30 | + } |
---|
31 | |
---|
32 | if ( !$echo ) |
---|
33 | return $output; |
---|
34 | |
---|
35 | echo "<script type='text/javascript'>\n"; // CDATA and type='text/javascript' is not needed for HTML 5 |
---|
36 | echo "/* <![CDATA[ */\n"; |
---|
37 | - echo "$output\n"; |
---|
38 | + echo $output; |
---|
39 | echo "/* ]]> */\n"; |
---|
40 | echo "</script>\n"; |
---|
41 | |
---|
42 | @@ -128,29 +147,18 @@ |
---|
43 | * Localizes only if the script has already been added |
---|
44 | */ |
---|
45 | function localize( $handle, $object_name, $l10n ) { |
---|
46 | - if ( is_array($l10n) && isset($l10n['l10n_print_after']) ) { // back compat, preserve the code in 'l10n_print_after' if present |
---|
47 | - $after = $l10n['l10n_print_after']; |
---|
48 | - unset($l10n['l10n_print_after']); |
---|
49 | + |
---|
50 | + $data = $this->get_data( $handle, 'data' ); |
---|
51 | + |
---|
52 | + if (empty($data) || !is_array($data)) { |
---|
53 | + $data = array(); |
---|
54 | } |
---|
55 | + |
---|
56 | + $data[$object_name] = $l10n; |
---|
57 | + |
---|
58 | + $return_val = $this->add_data( $handle, 'data', $data ); |
---|
59 | |
---|
60 | - foreach ( (array) $l10n as $key => $value ) { |
---|
61 | - if ( !is_scalar($value) ) |
---|
62 | - continue; |
---|
63 | - |
---|
64 | - $l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8'); |
---|
65 | - } |
---|
66 | - |
---|
67 | - $script = "var $object_name = " . json_encode($l10n) . ';'; |
---|
68 | - |
---|
69 | - if ( !empty($after) ) |
---|
70 | - $script .= "\n$after"; |
---|
71 | - |
---|
72 | - $data = $this->get_data( $handle, 'data' ); |
---|
73 | - |
---|
74 | - if ( !empty( $data ) ) |
---|
75 | - $script = "$data;\n$script"; |
---|
76 | - |
---|
77 | - return $this->add_data( $handle, 'data', $script ); |
---|
78 | + return $return_val; |
---|
79 | } |
---|
80 | |
---|
81 | function set_group( $handle, $recursion, $group = false ) { |
---|