Make WordPress Core

Ticket #25280: 25280.4.patch

File 25280.4.patch, 829 bytes (added by Fab1en, 10 years ago)

Allow wp_localize_script to use scalar variable

  • wp-includes/class.wp-scripts.php

    diff --git a/wp-includes/class.wp-scripts.php b/wp-includes/class.wp-scripts.php
    index 1ceb51d..2076be8 100644
    a b class WP_Scripts extends WP_Dependencies { 
    160160                        unset($l10n['l10n_print_after']);
    161161                }
    162162
    163                 foreach ( (array) $l10n as $key => $value ) {
    164                         if ( !is_scalar($value) )
    165                                 continue;
     163                if( is_array($l10n) ) {
     164                        foreach ( $l10n as $key => $value ) {
     165                                if ( !is_string($value) )
     166                                        continue;
    166167
    167                         $l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8');
     168                                $l10n[$key] = html_entity_decode( $value, ENT_QUOTES, 'UTF-8');
     169                        }
     170                } else if( is_string($l10n) ) {
     171                        $l10n = html_entity_decode( $l10n, ENT_QUOTES, 'UTF-8');
    168172                }
    169173
    170174                $script = "var $object_name = " . json_encode($l10n) . ';';