From fced7be5798fc694796c1446c4316711184417b8 Mon Sep 17 00:00:00 2001
From: jrfnl <github_nospam@adviesenzo.nl>
Date: Mon, 28 Mar 2016 18:33:06 +0200
Subject: [PATCH] Fix _wp_json_prepare_data() was called too late.

---
 src/wp-includes/functions.php | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
index 0e720ee..6d8e3b6 100644
--- a/src/wp-includes/functions.php
+++ b/src/wp-includes/functions.php
@@ -2848,6 +2848,10 @@ function _scalar_wp_die_handler( $message = '' ) {
  * @return string|false The JSON encoded string, or false if it cannot be encoded.
  */
 function wp_json_encode( $data, $options = 0, $depth = 512 ) {
+
+	// Prepare the data for JSON serialization.
+	$data = _wp_json_prepare_data( $data );
+
 	/*
 	 * json_encode() has had extra params added over the years.
 	 * $options was added in 5.3, and $depth in 5.5.
@@ -2861,9 +2865,6 @@ function wp_json_encode( $data, $options = 0, $depth = 512 ) {
 		$args = array( $data );
 	}
 
-	// Prepare the data for JSON serialization.
-	$data = _wp_json_prepare_data( $data );
-
 	$json = @call_user_func_array( 'json_encode', $args );
 
 	// If json_encode() was successful, no need to do more sanity checking.
-- 
1.9.4.msysgit.2

