From ceb1acf3f7b86f26c44e21bdfd4bc3668a8444d6 Mon Sep 17 00:00:00 2001 From: dd32 Date: Sun, 28 Mar 2010 04:42:44 +0000 Subject: [PATCH] Implement the 2nd parameter of json_decode() for back-compat purposes. Returns an associative array instead of an object. For the recursive object handling, Props carbolineum. Fixes #11963 git-svn-id: http://svn.automattic.com/wordpress/trunk@13863 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/compat.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wp-includes/compat.php b/wp-includes/compat.php index f1e118bab..888437906 100644 --- a/wp-includes/compat.php +++ b/wp-includes/compat.php @@ -148,9 +148,14 @@ if ( !function_exists('json_decode') ) { $res = $wp_json->decode( $string ); if ( $assoc_array ) - $res = get_object_vars( $res ); + $res = _json_decode_object_helper( $res ); return $res; } + function _json_decode_object_helper($data) { + if ( is_object($data) ) + $data = get_object_vars($data); + return is_array($data) ? array_map(__FUNCTION__, $data) : $data; + } } // pathinfo that fills 'filename' without extension like in PHP 5.2+