From 03375fa84447d8fd2383af084f6ba1811cb4c562 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 29 Sep 2011 06:43:46 +0000 Subject: [PATCH] Recursively convert html entities in script localization strings, see #11520 git-svn-id: https://develop.svn.wordpress.org/trunk@18813 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/class.wp-scripts.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/wp-includes/class.wp-scripts.php b/wp-includes/class.wp-scripts.php index bec49c4532..70e1fca82d 100644 --- a/wp-includes/class.wp-scripts.php +++ b/wp-includes/class.wp-scripts.php @@ -62,15 +62,18 @@ class WP_Scripts extends WP_Dependencies { $after = $data['l10n_print_after']; unset($data['l10n_print_after']); } - $output = "var $name = " . json_encode($data) . "; $after\n"; + + $data = $this->decode_html_entities($data); + $output = "var $name = " . json_encode( $data ) . "; $after\n"; } else { $data = $this->get_data( $handle, 'data' ); if ( empty( $data ) ) return false; - foreach ( (array) $data as $name => $data ) { - $output = "var $name = " . json_encode($data) . ";\n"; + foreach ( (array) $data as $name => $value ) { + $value = $this->decode_html_entities($value); + $output = "var $name = " . json_encode( $value ) . ";\n"; } } @@ -216,6 +219,16 @@ class WP_Scripts extends WP_Dependencies { return false; } + function decode_html_entities($data) { + foreach ( (array) $data as $key => $value ) { + if ( is_array($value) ) + $data[$key] = $this->decode_html_entities($value); + elseif ( is_string($value) ) + $data[$key] = html_entity_decode($value, ENT_QUOTES, 'UTF-8'); + } + return $data; + } + function reset() { $this->do_concat = false; $this->print_code = '';