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

git-svn-id: https://develop.svn.wordpress.org/trunk@11875 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2009-08-25 07:48:59 +00:00
parent 61c97aba16
commit aca0f9160d
2 changed files with 889 additions and 3 deletions
+28 -3
View File
@@ -56,7 +56,7 @@ if (!function_exists('stripos')) {
}
}
if ( ! function_exists('hash_hmac') ):
if ( !function_exists('hash_hmac') ):
function hash_hmac($algo, $data, $key, $raw_output = false) {
$packs = array('md5' => 'H32', 'sha1' => 'H40');
@@ -77,7 +77,7 @@ function hash_hmac($algo, $data, $key, $raw_output = false) {
}
endif;
if ( ! function_exists('mb_substr') ):
if ( !function_exists('mb_substr') ):
function mb_substr( $str, $start, $length=null, $encoding=null ) {
return _mb_substr($str, $start, $length, $encoding);
}
@@ -115,4 +115,29 @@ if ( !function_exists( 'htmlspecialchars_decode' ) ) {
}
}
?>
// For PHP < 5.2.0
if ( !function_exists('json_encode') ) {
function json_encode( $string ) {
global $wp_json;
if ( !is_a($wp_json, 'Services_JSON') ) {
require_once( 'class-json.php' );
$wp_json = new Services_JSON();
}
return $wp_json->encode( $string );
}
}
if ( !function_exists('json_decode') ) {
function json_decode( $string ) {
global $wp_json;
if ( !is_a($wp_json, 'Services_JSON') ) {
require_once( 'class-json.php' );
$wp_json = new Services_JSON();
}
return $wp_json->decode( $string );
}
}