Make WordPress Core


Ignore:
Timestamp:
09/20/2019 08:07:28 PM (5 years ago)
Author:
desrosj
Message:

Code Modernization: Remove JSON extension workarounds for PHP < 5.6.

The PHP native JSON extension has been bundled and compiled with PHP by default since version 5.2.0. Because the minimum version of PHP required by WordPress is now 5.6.20 (see #46594 and [45058]), JSON extension related polyfills and backwards compatibility code can now be removed.

This change removes code that supported JSON related functionality on older versions of PHP. This includes (but is not limited to) checks that json_last_error() exists, checking and setting the JSON_UNESCAPED_SLASHES and JSON_PRETTY_PRINT constants if not previously defined, and deprecating the _wp_json_prepare_data() function (which was 100% workaround code).

Follow up of [46205].

See #47699.
Props jrf, Clorith, pento.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r46133 r46206  
    11171117        }
    11181118        $changeset_data = json_decode( $changeset_post->post_content, true );
    1119         if ( function_exists( 'json_last_error' ) && json_last_error() ) {
    1120             return new WP_Error( 'json_parse_error', '', json_last_error() );
     1119        $last_error     = json_last_error();
     1120        if ( $last_error ) {
     1121            return new WP_Error( 'json_parse_error', '', $last_error );
    11211122        }
    11221123        if ( ! is_array( $changeset_data ) ) {
     
    28442845
    28452846        // Gather the data for wp_insert_post()/wp_update_post().
    2846         $json_options = 0;
    2847         if ( defined( 'JSON_UNESCAPED_SLASHES' ) ) {
    2848             $json_options |= JSON_UNESCAPED_SLASHES; // Introduced in PHP 5.4. This is only to improve readability as slashes needn't be escaped in storage.
    2849         }
    2850         $json_options |= JSON_PRETTY_PRINT; // Also introduced in PHP 5.4, but WP defines constant for back compat. See WP Trac #30139.
    2851         $post_array    = array(
    2852             'post_content' => wp_json_encode( $data, $json_options ),
     2847        $post_array = array(
     2848            // JSON_UNESCAPED_SLASHES is only to improve readability as slashes needn't be escaped in storage.
     2849            'post_content' => wp_json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ),
    28532850        );
    28542851        if ( $args['title'] ) {
Note: See TracChangeset for help on using the changeset viewer.