Title: problem wp_json_encode() with WP 3.8.3
Last modified: August 30, 2016

---

# problem wp_json_encode() with WP 3.8.3

 *  Resolved [pyramusnl](https://wordpress.org/support/users/pyramusnl/)
 * (@pyramusnl)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/problem-wp_json_encode-with-wp-383/)
 * hey there, the most recent update does not work with WP 3.8.3 anymore. the function
   wp_json_encode(), used in **alternative-experiment-controller.php** does not 
   exist.
 * i solved this by manually adding this function to my functions.php, but this 
   is perhaps not optimal.
 *     ```
       function wp_json_encode( $data, $options = 0, $depth = 512 ) {
           /*
            * json_encode() has had extra params added over the years.
            * $options was added in 5.3, and $depth in 5.5.
            * We need to make sure we call it with the correct arguments.
            */
           if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) {
               $args = array( $data, $options, $depth );
           } elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
               $args = array( $data, $options );
           } else {
               $args = array( $data );
           }
   
           $json = call_user_func_array( 'json_encode', $args );
   
           // If json_encode() was successful, no need to do more sanity checking.
           // ... unless we're in an old version of PHP, and json_encode() returned
           // a string containing 'null'. Then we need to do more sanity checking.
           if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) )  {
               return $json;
           }
   
           try {
               $args[0] = _wp_json_sanity_check( $data, $depth );
           } catch ( Exception $e ) {
               return false;
           }
           return call_user_func_array( 'json_encode', $args );
       }
       ```
   
 * [https://wordpress.org/plugins/nelio-ab-testing/](https://wordpress.org/plugins/nelio-ab-testing/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [David Aguilera](https://wordpress.org/support/users/davilera/)
 * (@davilera)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/problem-wp_json_encode-with-wp-383/#post-6880836)
 * Hi,
 * You’re right! I updated the plugin and I didn’t realize I used `wp_json_encode`
   instead of `json_encode`. The solution you applied is almost correct; notice 
   the `try-catch` block uses another function (`_wp_json_sanity_check`), which 
   is only available since WordPress 4.1.0 too.
 * As an alternative solution, I’d recommend you simply change our plugin so that
   it does no longer use `wp_json_encode`. Go to `includes/experiment-controllers/
   alternative-experiment-controller.php` line 1582:
 *     ```
       this.page.url = <?php echo wp_json_encode( $url ); ?>;
       ```
   
 * and change it to:
 *     ```
       this.page.url = <?php echo json_encode( $url ); ?>;
       ```
   
 * I’ll try to update a new version of the plugin with the fix shortly. In the meantime,
   you should be able to do it your self. If you need help, just let me know.
 * Thanks again for the heads up.
 * Have a wonderful week,
    David
 *  Thread Starter [pyramusnl](https://wordpress.org/support/users/pyramusnl/)
 * (@pyramusnl)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/problem-wp_json_encode-with-wp-383/#post-6880902)
 * Hey there, thanks for the suggestion. I would prefer to avoid change core plugin
   functionality as much as possible in favour of auto-updating. Looking forward
   to your forthcoming update. Keep rocking!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘problem wp_json_encode() with WP 3.8.3’ is closed to new replies.

 * ![](https://ps.w.org/nelio-ab-testing/assets/icon-256x256.png?rev=2514600)
 * [Nelio A/B Testing – AB Tests and Heatmaps for Better Conversion Optimization](https://wordpress.org/plugins/nelio-ab-testing/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/nelio-ab-testing/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/nelio-ab-testing/)
 * [Active Topics](https://wordpress.org/support/plugin/nelio-ab-testing/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/nelio-ab-testing/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/nelio-ab-testing/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [pyramusnl](https://wordpress.org/support/users/pyramusnl/)
 * Last activity: [10 years, 4 months ago](https://wordpress.org/support/topic/problem-wp_json_encode-with-wp-383/#post-6880902)
 * Status: resolved