Changeset 46206
- Timestamp:
- 09/20/2019 08:07:28 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/noop.php
r42343 r46206 94 94 function wp_guess_url() {} 95 95 96 if ( ! function_exists( 'json_encode' ) ) :97 /**98 * @ignore99 */100 function json_encode() {}101 endif;102 103 96 function get_file( $path ) { 104 97 -
trunk/src/wp-includes/class-wp-customize-manager.php
r46133 r46206 1117 1117 } 1118 1118 $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 ); 1121 1122 } 1122 1123 if ( ! is_array( $changeset_data ) ) { … … 2844 2845 2845 2846 // 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 ), 2853 2850 ); 2854 2851 if ( $args['title'] ) { -
trunk/src/wp-includes/functions.php
r46176 r46206 3722 3722 * 3723 3723 * @since 4.1.0 3724 * @since 5.3.0 No longer handles support for PHP < 5.6. 3724 3725 * 3725 3726 * @param mixed $data Variable (usually an array or object) to encode as JSON. … … 3730 3731 */ 3731 3732 function wp_json_encode( $data, $options = 0, $depth = 512 ) { 3732 /* 3733 * json_encode() has had extra params added over the years. 3734 * $options was added in 5.3, and $depth in 5.5. 3735 * We need to make sure we call it with the correct arguments. 3736 */ 3737 if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) { 3738 $args = array( $data, $options, $depth ); 3739 } elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) ) { 3740 $args = array( $data, $options ); 3741 } else { 3742 $args = array( $data ); 3743 } 3744 3745 // Prepare the data for JSON serialization. 3746 $args[0] = _wp_json_prepare_data( $data ); 3747 3748 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- json_encode() errors are handled after this call 3749 $json = @call_user_func_array( 'json_encode', $args ); 3733 $json = json_encode( $data, $options, $depth ); 3750 3734 3751 3735 // If json_encode() was successful, no need to do more sanity checking. 3752 // ... unless we're in an old version of PHP, and json_encode() returned 3753 // a string containing 'null'. Then we need to do more sanity checking. 3754 if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) ) { 3736 if ( false !== $json ) { 3755 3737 return $json; 3756 3738 } 3757 3739 3758 3740 try { 3759 $ args[0]= _wp_json_sanity_check( $data, $depth );3741 $data = _wp_json_sanity_check( $data, $depth ); 3760 3742 } catch ( Exception $e ) { 3761 3743 return false; 3762 3744 } 3763 3745 3764 return call_user_func_array( 'json_encode', $args);3746 return json_encode( $data, $options, $depth ); 3765 3747 } 3766 3748 … … 3866 3848 * 3867 3849 * @ignore 3868 * @since 4.4.0 3869 * @access private 3850 * @since 4.4.0 3851 * @deprecated 5.3.0 This function is no longer needed as support for PHP 5.2-5.3 3852 * has been dropped. 3853 * @access private 3870 3854 * 3871 3855 * @param mixed $data Native representation. … … 3873 3857 */ 3874 3858 function _wp_json_prepare_data( $data ) { 3875 if ( ! defined( 'WP_JSON_SERIALIZE_COMPATIBLE' ) || WP_JSON_SERIALIZE_COMPATIBLE === false ) { 3876 return $data; 3877 } 3878 3879 switch ( gettype( $data ) ) { 3880 case 'boolean': 3881 case 'integer': 3882 case 'double': 3883 case 'string': 3884 case 'NULL': 3885 // These values can be passed through. 3886 return $data; 3887 3888 case 'array': 3889 // Arrays must be mapped in case they also return objects. 3890 return array_map( '_wp_json_prepare_data', $data ); 3891 3892 case 'object': 3893 // If this is an incomplete object (__PHP_Incomplete_Class), bail. 3894 if ( ! is_object( $data ) ) { 3895 return null; 3896 } 3897 3898 if ( $data instanceof JsonSerializable ) { 3899 $data = $data->jsonSerialize(); 3900 } else { 3901 $data = get_object_vars( $data ); 3902 } 3903 3904 // Now, pass the array (or whatever was returned from jsonSerialize through). 3905 return _wp_json_prepare_data( $data ); 3906 3907 default: 3908 return null; 3909 } 3859 _deprecated_function( __FUNCTION__, '5.3.0' ); 3860 return $data; 3910 3861 } 3911 3862 -
trunk/src/wp-includes/rest-api/class-wp-rest-request.php
r46105 r46206 640 640 /* 641 641 * Check for a parsing error. 642 *643 * Note that due to WP's JSON compatibility functions, json_last_error644 * might not be defined: https://core.trac.wordpress.org/ticket/27799645 642 */ 646 if ( null === $params && ( ! function_exists( 'json_last_error' ) || JSON_ERROR_NONE !== json_last_error()) ) {643 if ( null === $params && JSON_ERROR_NONE !== json_last_error() ) { 647 644 // Ensure subsequent calls receive error instance. 648 645 $this->parsed_json = false; 649 646 650 647 $error_data = array( 651 'status' => WP_Http::BAD_REQUEST, 648 'status' => WP_Http::BAD_REQUEST, 649 'json_error_code' => json_last_error(), 650 'json_error_message' => json_last_error_msg(), 652 651 ); 653 if ( function_exists( 'json_last_error' ) ) {654 $error_data['json_error_code'] = json_last_error();655 $error_data['json_error_message'] = json_last_error_msg();656 }657 652 658 653 return new WP_Error( 'rest_invalid_json', __( 'Invalid JSON body passed.' ), $error_data ); -
trunk/src/wp-includes/rest-api/class-wp-rest-server.php
r46191 r46206 1002 1002 */ 1003 1003 protected function get_json_last_error() { 1004 // See https://core.trac.wordpress.org/ticket/27799.1005 if ( ! function_exists( 'json_last_error' ) ) {1006 return false;1007 }1008 1009 1004 $last_error_code = json_last_error(); 1010 1005 1011 if ( ( defined( 'JSON_ERROR_NONE' ) && JSON_ERROR_NONE === $last_error_code )|| empty( $last_error_code ) ) {1006 if ( JSON_ERROR_NONE === $last_error_code || empty( $last_error_code ) ) { 1012 1007 return false; 1013 1008 } -
trunk/tests/phpunit/tests/customize/manager.php
r46127 r46206 1857 1857 $r = $manager->save_changeset_post( $args ); 1858 1858 $this->assertInstanceOf( 'WP_Error', $r ); 1859 if ( function_exists( 'json_last_error' ) ) { 1860 $this->assertEquals( 'json_parse_error', $r->get_error_code() ); 1861 } 1859 $this->assertEquals( 'json_parse_error', $r->get_error_code() ); 1862 1860 1863 1861 wp_update_post( -
trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php
r46190 r46206 489 489 $this->assertTrue( ! empty( $data ), $route['name'] . ' route should return data.' ); 490 490 491 if ( version_compare( PHP_VERSION, '5.4', '>=' ) ) { 492 $fixture = $this->normalize_fixture( $data, $route['name'] ); 493 $mocked_responses .= "\nmockedApiResponse." . $route['name'] . ' = ' 494 . json_encode( $fixture, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) 495 . ";\n"; 496 } 491 $fixture = $this->normalize_fixture( $data, $route['name'] ); 492 $mocked_responses .= "\nmockedApiResponse." . $route['name'] . ' = ' 493 . json_encode( $fixture, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) 494 . ";\n"; 497 495 } 498 496 499 497 // Only generate API client fixtures in single site and when required JSON_* constants are supported. 500 if ( ! is_multisite() && version_compare( PHP_VERSION, '5.4', '>=' )) {498 if ( ! is_multisite() ) { 501 499 // Save the route object for QUnit tests. 502 500 $file = dirname( DIR_TESTROOT ) . '/qunit/fixtures/wp-api-generated.js';
Note: See TracChangeset
for help on using the changeset viewer.