Ticket #11520: print_scripts_l10n.diff
File print_scripts_l10n.diff, 1.7 KB (added by , 15 years ago) |
---|
-
wp-includes/class.wp-scripts.php
48 48 } 49 49 50 50 function print_scripts_l10n( $handle, $echo = true ) { 51 if ( empty($this->registered[$handle]->extra['l10n']) || empty($this->registered[$handle]->extra['l10n'][0]) || !is_array($this->registered[$handle]->extra['l10n'][1]))51 if ( empty($this->registered[$handle]->extra['l10n']) || empty($this->registered[$handle]->extra['l10n'][0]) ) 52 52 return false; 53 53 54 54 $object_name = $this->registered[$handle]->extra['l10n'][0]; 55 $data = $this->registered[$handle]->extra['l10n'][1]; 55 56 56 $data = "var $object_name = {\n"; 57 $eol = ''; 58 foreach ( $this->registered[$handle]->extra['l10n'][1] as $var => $val ) { 59 if ( 'l10n_print_after' == $var ) { 60 $after = $val; 61 continue; 62 } 63 $data .= "$eol\t$var: \"" . esc_js( $val ) . '"'; 64 $eol = ",\n"; 65 } 66 $data .= "\n};\n"; 67 $data .= isset($after) ? "$after\n" : ''; 68 69 if ( $echo ) { 70 echo "<script type='text/javascript'>\n"; 71 echo "/* <![CDATA[ */\n"; 72 echo $data; 73 echo "/* ]]> */\n"; 74 echo "</script>\n"; 75 return true; 57 if ( is_array($data) && isset($data['l10n_print_after']) ) { 58 $after = $data['l10n_print_after']; 59 unset($data['l10n_print_after']); 76 60 } else { 77 return $data;61 $after = ''; 78 62 } 63 64 $output = "var $object_name = " . json_encode($data) . "; $after\n"; 65 66 if ( !$echo ) 67 return $output; 68 69 echo "<script type='text/javascript'>\n"; 70 echo "/* <![CDATA[ */\n"; 71 echo $output; 72 echo "/* ]]> */\n"; 73 echo "</script>\n"; 74 return true; 79 75 } 80 76 81 77 function do_item( $handle, $group = false ) {