Make WordPress Core

Ticket #48880: 48880.diff

File 48880.diff, 1.3 KB (added by naxvog, 5 years ago)

Changes to the WP_Scripts localize method and the block editor init script

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

    diff --git a/wp-includes/class.wp-scripts.php b/wp-includes/class.wp-scripts.php
    index 37ad372db9..9ed08fc945 100644
    a b class WP_Scripts extends WP_Dependencies { 
    486486                       $l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
    487487               }
    488488
    489                $script = "var $object_name = " . wp_json_encode( $l10n ) . ';';
     489               if ( is_scalar( $l10n ) ) {
     490                       $script = "var $object_name = " . wp_json_encode( $l10n ) . ';';
     491               } else {
     492                       $script = "var $object_name = JSON.parse('" . wp_json_encode( $l10n ) . '\');';
     493               }
    490494
    491495               if ( ! empty( $after ) ) {
    492496                       $script .= "\n$after;";
  • wp-admin/edit-form-blocks.php

    diff --git a/wp-admin/edit-form-blocks.php b/wp-admin/edit-form-blocks.php
    index 8f323501a0..b2ba07aef8 100644
    a b $script = sprintf( 
    394394       $init_script,
    395395       $post->post_type,
    396396       $post->ID,
    397        wp_json_encode( $editor_settings ),
     397       'JSON.parse(\'' . wp_json_encode( $editor_settings ) . '\');',
    398398       wp_json_encode( $initial_edits )
    399399);
    400400wp_add_inline_script( 'wp-edit-post', $script );