WordPress.org

Make WordPress Core

Changeset 11875


Ignore:
Timestamp:
08/25/2009 07:48:59 AM (12 years ago)
Author:
azaozz
Message:

Add JSON compat for PHP < 5.2, props Viper007Bond, see #10337

Location:
trunk/wp-includes
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/compat.php

    r10707 r11875  
    5757}
    5858
    59 if ( ! function_exists('hash_hmac') ):
     59if ( !function_exists('hash_hmac') ):
    6060function hash_hmac($algo, $data, $key, $raw_output = false) {
    6161    $packs = array('md5' => 'H32', 'sha1' => 'H40');
     
    7878endif;
    7979
    80 if ( ! function_exists('mb_substr') ):
     80if ( !function_exists('mb_substr') ):
    8181    function mb_substr( $str, $start, $length=null, $encoding=null ) {
    8282        return _mb_substr($str, $start, $length, $encoding);
     
    116116}
    117117
    118 ?>
     118// For PHP < 5.2.0
     119if ( !function_exists('json_encode') ) {
     120    function json_encode( $string ) {
     121        global $wp_json;
     122
     123        if ( !is_a($wp_json, 'Services_JSON') ) {
     124            require_once( 'class-json.php' );
     125            $wp_json = new Services_JSON();
     126        }
     127
     128        return $wp_json->encode( $string );
     129    }
     130}
     131
     132if ( !function_exists('json_decode') ) {
     133    function json_decode( $string ) {
     134        global $wp_json;
     135
     136        if ( !is_a($wp_json, 'Services_JSON') ) {
     137            require_once( 'class-json.php' );
     138            $wp_json = new Services_JSON();
     139        }
     140
     141        return $wp_json->decode( $string );
     142    }
     143}
Note: See TracChangeset for help on using the changeset viewer.