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. Built from https://develop.svn.wordpress.org/trunk@46206 git-svn-id: http://core.svn.wordpress.org/trunk@46018 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -1116,8 +1116,9 @@ final class WP_Customize_Manager {
|
||||
return new WP_Error( 'wrong_post_type' );
|
||||
}
|
||||
$changeset_data = json_decode( $changeset_post->post_content, true );
|
||||
if ( function_exists( 'json_last_error' ) && json_last_error() ) {
|
||||
return new WP_Error( 'json_parse_error', '', json_last_error() );
|
||||
$last_error = json_last_error();
|
||||
if ( $last_error ) {
|
||||
return new WP_Error( 'json_parse_error', '', $last_error );
|
||||
}
|
||||
if ( ! is_array( $changeset_data ) ) {
|
||||
return new WP_Error( 'expected_array' );
|
||||
@@ -2843,13 +2844,9 @@ final class WP_Customize_Manager {
|
||||
}
|
||||
|
||||
// Gather the data for wp_insert_post()/wp_update_post().
|
||||
$json_options = 0;
|
||||
if ( defined( 'JSON_UNESCAPED_SLASHES' ) ) {
|
||||
$json_options |= JSON_UNESCAPED_SLASHES; // Introduced in PHP 5.4. This is only to improve readability as slashes needn't be escaped in storage.
|
||||
}
|
||||
$json_options |= JSON_PRETTY_PRINT; // Also introduced in PHP 5.4, but WP defines constant for back compat. See WP Trac #30139.
|
||||
$post_array = array(
|
||||
'post_content' => wp_json_encode( $data, $json_options ),
|
||||
$post_array = array(
|
||||
// JSON_UNESCAPED_SLASHES is only to improve readability as slashes needn't be escaped in storage.
|
||||
'post_content' => wp_json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ),
|
||||
);
|
||||
if ( $args['title'] ) {
|
||||
$post_array['post_title'] = $args['title'];
|
||||
|
||||
Reference in New Issue
Block a user