Make WordPress Core

Changeset 18405


Ignore:
Timestamp:
07/06/2011 11:44:23 PM (13 years ago)
Author:
nacin
Message:

Restore compat for json_decode and json_encode. fixes #18015 for 3.2.

Location:
branches/3.2
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.2

    • Property svn:mergeinfo changed
      /trunk (added)merged: 18404
  • branches/3.2/wp-admin/includes/update-core.php

    r18318 r18405  
    245245// 3.2
    246246'wp-includes/default-embeds.php',
    247 'wp-includes/class-json.php',
    248247'wp-includes/js/tinymce/plugins/wordpress/img/more.gif',
    249248'wp-includes/js/tinymce/plugins/wordpress/img/toolbars.gif',
  • branches/3.2/wp-includes/compat.php

    r18111 r18405  
    6161    return $hmac;
    6262}
     63
     64if ( !function_exists('json_encode') ) {
     65    function json_encode( $string ) {
     66        global $wp_json;
     67
     68        if ( !is_a($wp_json, 'Services_JSON') ) {
     69            require_once( ABSPATH . WPINC . '/class-json.php' );
     70            $wp_json = new Services_JSON();
     71        }
     72
     73        return $wp_json->encodeUnsafe( $string );
     74    }
     75}
     76
     77if ( !function_exists('json_decode') ) {
     78    function json_decode( $string, $assoc_array = false ) {
     79        global $wp_json;
     80
     81        if ( !is_a($wp_json, 'Services_JSON') ) {
     82            require_once( ABSPATH . WPINC . '/class-json.php' );
     83            $wp_json = new Services_JSON();
     84        }
     85
     86        $res = $wp_json->decode( $string );
     87        if ( $assoc_array )
     88            $res = _json_decode_object_helper( $res );
     89        return $res;
     90    }
     91    function _json_decode_object_helper($data) {
     92        if ( is_object($data) )
     93            $data = get_object_vars($data);
     94        return is_array($data) ? array_map(__FUNCTION__, $data) : $data;
     95    }
     96}
Note: See TracChangeset for help on using the changeset viewer.