WordPress.org

Make WordPress Core

Changeset 18404


Ignore:
Timestamp:
07/06/11 23:33:05 (4 years ago)
Author:
nacin
Message:

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

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/update-core.php

    r18318 r18404  
    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', 
  • trunk/wp-includes/compat.php

    r18111 r18404  
    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.