From 329bd9498952d8e023707d2953a2c4edf82a6790 Mon Sep 17 00:00:00 2001 From: thanghv Date: Mon, 3 Feb 2020 22:55:50 +0700 Subject: [PATCH] * Fixed: connection problems caused by issues with json_encode function --- class/class-mainwp-child.php | 30 +++++++++++++++--------------- class/class-mainwp-helper.php | 25 +++++++++++++++++++++++-- mainwp-child.php | 2 +- readme.txt | 5 ++++- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/class/class-mainwp-child.php b/class/class-mainwp-child.php index 894de7a..7e3ef47 100644 --- a/class/class-mainwp-child.php +++ b/class/class-mainwp-child.php @@ -115,7 +115,7 @@ if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyus } class MainWP_Child { - public static $version = '4.0.6.1'; + public static $version = '4.0.6.2'; private $update_version = '1.5'; private $callableFunctions = array( @@ -1539,7 +1539,7 @@ class MainWP_Child { MainWP_Helper::error( __( 'Required version has not been detected. Please, make sure that you are using the latest version of the MainWP Child plugin on your site.', 'mainwp-child' ) ); } - + if ( 1 === (int) get_option( 'mainwpKeywordLinks' ) ) { new MainWP_Keyword_Links(); if ( ! is_admin() ) { @@ -3038,7 +3038,7 @@ class MainWP_Child { $new_user['role'] = 'subscriber'; } } - + $new_user_id = wp_insert_user( $new_user ); if ( is_wp_error( $new_user_id ) ) { @@ -3586,9 +3586,9 @@ class MainWP_Child { MainWP_Helper::update_option( 'mainwp_child_clone_sites', '0' ); } } - - if ( isset( $_POST['siteId'] ) ) { - MainWP_Helper::update_option( 'mainwp_child_siteid', intval($_POST['siteId']) ); + + if ( isset( $_POST['siteId'] ) ) { + MainWP_Helper::update_option( 'mainwp_child_siteid', intval($_POST['siteId']) ); } if ( isset( $_POST['pluginDir'] ) ) { @@ -3629,7 +3629,7 @@ class MainWP_Child { MainWP_Child_Themes_Check::Instance()->cleanup_deactivation( false ); } } - + $information['version'] = self::$version; $information['wpversion'] = $wp_version; $information['siteurl'] = get_option( 'siteurl' ); @@ -3995,14 +3995,14 @@ class MainWP_Child { if ( ! is_array( $othersData ) ) { $othersData = array(); } - + if ( isset( $othersData['wpvulndbToken'] ) ) { - $wpvulndb_token = get_option( 'mainwp_child_wpvulndb_token', '' ); - if ( $wpvulndb_token != $othersData['wpvulndbToken'] ) { - MainWP_Helper::update_option( 'mainwp_child_wpvulndb_token', $othersData['wpvulndbToken'] ); + $wpvulndb_token = get_option( 'mainwp_child_wpvulndb_token', '' ); + if ( $wpvulndb_token != $othersData['wpvulndbToken'] ) { + MainWP_Helper::update_option( 'mainwp_child_wpvulndb_token', $othersData['wpvulndbToken'] ); } } - + try{ $information = apply_filters( 'mainwp-site-sync-others-data', $information, $othersData ); } catch(Exception $e) { @@ -5287,7 +5287,7 @@ class MainWP_Child { $maint_options = array(); } - + // $this->options = array( // 'revisions' => __( 'Delete all post revisions', 'mainwp-maintenance-extension' ), // 'autodraft' => __( 'Delete all auto draft posts', 'mainwp-maintenance-extension' ), @@ -5299,11 +5299,11 @@ class MainWP_Child { // 'categories' => __( 'Delete categories with 0 posts associated', 'mainwp-maintenance-extension' ), // 'optimize' => __( 'Optimize database tables', 'mainwp-maintenance-extension' ) // ); - + $performed_what = array(); if ( empty( $max_revisions ) ) { $sql_clean = "DELETE FROM $wpdb->posts WHERE post_type = 'revision'"; - $wpdb->query( $sql_clean ); + $wpdb->query( $sql_clean ); // to fix issue of meta_value short length $performed_what[] = 'revisions'; //'Posts revisions deleted'; } else { diff --git a/class/class-mainwp-helper.php b/class/class-mainwp-helper.php index 5c2d24d..35110e9 100644 --- a/class/class-mainwp-helper.php +++ b/class/class-mainwp-helper.php @@ -4,18 +4,39 @@ class MainWP_Helper { static function write( $val ) { if (isset( $_REQUEST['json_result'] ) && $_REQUEST['json_result'] == true) : - $output = json_encode( $val ); + $output = self::safe_json_encode( $val ); else: $output = serialize( $val ); endif; die( '' . base64_encode( $output ) . '' ); } + + public static function utf8ize($mixed) { + if (is_array($mixed)) { + foreach ($mixed as $key => $value) { + $mixed[$key] = self::utf8ize($value); + } + } elseif (is_string($mixed)) { + if ( function_exists( 'mb_convert_encoding' )) { + return mb_convert_encoding($mixed, "UTF-8", "UTF-8"); + } + } + return $mixed; + } + + public static function safe_json_encode($value, $options = 0, $depth = 512) { + $encoded = @json_encode($value, $options, $depth); + if ($encoded === false && $value && json_last_error() == JSON_ERROR_UTF8) { + $encoded = @json_encode(self::utf8ize($value), $options, $depth); + } + return $encoded; + } static function close_connection( $val = null ) { if (isset( $_REQUEST['json_result'] ) && $_REQUEST['json_result'] == true) : - $output = json_encode( $val ); + $output = self::safe_json_encode( $val ); else: $output = serialize( $val ); endif; diff --git a/mainwp-child.php b/mainwp-child.php index 19a8b5a..7054e75 100644 --- a/mainwp-child.php +++ b/mainwp-child.php @@ -6,7 +6,7 @@ Author: MainWP Author URI: https://mainwp.com Text Domain: mainwp-child - Version: 4.0.6.1 + Version: 4.0.6.2 */ include_once( ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'version.php' ); //Version information from wordpress diff --git a/readme.txt b/readme.txt index 686ed18..a57bf92 100644 --- a/readme.txt +++ b/readme.txt @@ -7,7 +7,7 @@ Plugin URI: https://mainwp.com Requires at least: 3.6 Tested up to: 5.3.2 Requires PHP: 5.6 -Stable tag: 4.0.6.1 +Stable tag: 4.0.6.2 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -71,6 +71,9 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m == Changelog == += 4.0.6.2 - 2-3-20 = +* Fixed: connection problems caused by issues with json_encode function + = 4.0.6.1 - 1-20-20 = * Updated: MainWP_Child_WPvivid_BackupRestore class