From 9393b9087272f20aee3ad9c541021ca2c8e44c94 Mon Sep 17 00:00:00 2001 From: Dion Hulse 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: https://develop.svn.wordpress.org/trunk@13863 602fd350-edb4-49c9-b593-d223f7449a82 --- 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 f1e118babb..8884379062 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+