From 4d0c30d8834eaaf34ae6cbe5c7c4aa2d277fd186 Mon Sep 17 00:00:00 2001 From: thanghv Date: Mon, 11 Nov 2019 23:17:10 +0700 Subject: [PATCH] * Fixed: WordPress 5.3 compatibility problems * Fixed: an issue with managing BackWPup backups * Updated: multiple error messages * Removed: unused code --- class/class-mainwp-child-back-wp-up.php | 48 +++++++++++++++++++++---- class/class-mainwp-child.php | 40 ++++++++++++--------- class/class-mainwp-helper.php | 6 ++-- class/class-mainwp-keyword-links.php | 2 +- mainwp-child.php | 2 +- readme.txt | 10 ++++-- 6 files changed, 77 insertions(+), 31 deletions(-) diff --git a/class/class-mainwp-child-back-wp-up.php b/class/class-mainwp-child-back-wp-up.php index b751c61..326d1a6 100644 --- a/class/class-mainwp-child-back-wp-up.php +++ b/class/class-mainwp-child-back-wp-up.php @@ -72,7 +72,13 @@ class MainWP_Child_Back_WP_Up { if ( is_plugin_active( 'backwpup-pro/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php' ) ) { $file_path1 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php'; - $file_path2 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/inc/pro/class-pro.php'; + $file_path2 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/inc/Pro/class-pro.php'; + + // to fix + if ( ! file_exists( $file_path2 ) ) { + $file_path2 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/inc/pro/class-pro.php'; + } + MainWP_Helper::check_files_exists(array( $file_path1, $file_path2 )); require_once( $file_path1 ); require_once( $file_path2 ); @@ -90,7 +96,8 @@ class MainWP_Child_Back_WP_Up { MainWP_Helper::check_methods('get_instance'); BackWPup::get_instance(); - add_action( 'wp_ajax_mainwp_backwpup_download_backup', array( $this, 'download_backup' ) ); + //add_action( 'wp_ajax_mainwp_backwpup_download_backup', array( $this, 'download_backup' ) ); + add_action( 'admin_init', array( $this, 'init_download_backup' ) ); add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); } } catch ( Exception $e) { @@ -748,6 +755,17 @@ class MainWP_Child_Back_WP_Up { '&', admin_url( 'admin-ajax.php' ) . '?action=mainwp_backwpup_download_backup&type=', ), $temp_array['downloadurl'] . '&_wpnonce=' . $this->create_nonce_without_session( 'mainwp_download_backup' ) ); + + $temp_array['downloadurl_id'] = '/wp-admin/admin.php?page=backwpupbackups'; + if ( preg_match( '/.*&jobid=([^&]+)&.*/is', $temp_array['downloadurl'], $matches )) { + if ( !empty( $matches[1] ) && is_numeric( $matches[1] ) ) { + $temp_array['downloadurl_id'] .= '&download_click_id=' . $matches[1]; + } + error_log('did match' . print_r($matches, true)); + } else { + error_log('not match'); + } + $temp_array['website_id'] = $website_id; if ( ! isset( $without_dupes[ $temp_array['file'] ] ) ) { @@ -765,7 +783,23 @@ class MainWP_Child_Back_WP_Up { return array( 'success' => 1, 'response' => $array ); } - public function download_backup() { + public function init_download_backup() { + if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'backwpupbackups' || !isset( $_GET['download_click_id'] ) || empty( $_GET['download_click_id'] )) { + return; + } + ?> + + verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_backup' ) ) { die( '-3' ); } - + $dest = strtoupper( str_replace( 'download', '', $_GET['type'] ) ); if ( ! empty( $dest ) && strstr( $_GET['type'], 'download' ) ) { $dest_class = BackWPup::get_destination( $dest ); if ( is_null( $dest_class ) ) { die( '-4' ); - } + } $dest_class->file_download( (int) $_GET['jobid'], $_GET['file'] ); } else { die( '-5' ); - } + } die(); - } + } protected function create_nonce_without_session( $action = - 1 ) { $user = wp_get_current_user(); diff --git a/class/class-mainwp-child.php b/class/class-mainwp-child.php index 2a0ec1f..58890c2 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.3'; + public static $version = '4.0.4'; private $update_version = '1.5'; private $callableFunctions = array( @@ -1442,11 +1442,11 @@ class MainWP_Child { $auth = $this->auth( isset( $_POST['mainwpsignature'] ) ? $_POST['mainwpsignature'] : '', isset( $_POST['function'] ) ? $_POST['function'] : '', isset( $_POST['nonce'] ) ? $_POST['nonce'] : '', isset( $_POST['nossl'] ) ? $_POST['nossl'] : 0 ); if ( ! $auth && isset( $_POST['mainwpsignature'] ) ) { - MainWP_Helper::error( __( 'Authentication failed! Please deactivate and re-activate the MainWP Child plugin on this site.', 'mainwp-child' ) ); + MainWP_Helper::error( __( 'Authentication failed! Please deactivate & re-activate the MainWP Child plugin on this site and try again.', 'mainwp-child' ) ); } if ( ! $auth && isset( $_POST['function'] ) && isset( $this->callableFunctions[ $_POST['function'] ] ) && ! isset( $this->callableFunctionsNoAuth[ $_POST['function'] ] ) ) { - MainWP_Helper::error( __( 'Authentication failed! Please deactivate and re-activate the MainWP Child plugin on this site.', 'mainwp-child' ) ); + MainWP_Helper::error( __( 'Authentication failed! Please deactivate & re-activate the MainWP Child plugin on this site and try again.', 'mainwp-child' ) ); } $auth_user = false; @@ -1470,11 +1470,11 @@ class MainWP_Child { } if ( ! $user ) { - MainWP_Helper::error( __( 'That administrator username was not found on this child site. Please verify that it is an existing administrator.', 'mainwp-child' ) ); + MainWP_Helper::error( __( 'Unexising administrator username. Please verify that it is an existing administrator.', 'mainwp-child' ) ); } if ( 10 != $user->wp_user_level && ( ! isset( $user->user_level ) || 10 != $user->user_level ) && ! $user->has_cap( 'level_10' ) ) { - MainWP_Helper::error( __( 'That user is not an administrator. Please use an administrator user to establish the connection.', 'mainwp-child' ) ); + MainWP_Helper::error( __( 'Invalid user. Please verify that the user has administrator privileges.', 'mainwp-child' ) ); } $this->login( $auth_user ); @@ -2404,7 +2404,7 @@ class MainWP_Child { // set disconnect status to yes here, it will empty after reconnected MainWP_Child_Branding::Instance()->save_branding_options('branding_disconnected', 'yes'); MainWP_Helper::update_option( 'mainwp_child_branding_disconnected', 'yes', 'yes' ); // to compatible with old client reports - MainWP_Helper::error( __( 'Public key already set. Please reset the MainWP Child plugin on the child site and try again.', 'mainwp-child' ) ); + MainWP_Helper::error( __( 'Public key already set. Please deactivate & reactivate the MainWP Child plugin and try again.', 'mainwp-child' ) ); } @@ -3032,7 +3032,13 @@ class MainWP_Child { //Read form data $new_user = maybe_unserialize( base64_decode( $_POST['new_user'] ) ); $send_password = $_POST['send_password']; - + // check role existed + if (isset( $new_user['role'] )) { + if ( !get_role( $new_user['role'] ) ) { + $new_user['role'] = 'subscriber'; + } + } + $new_user_id = wp_insert_user( $new_user ); if ( is_wp_error( $new_user_id ) ) { @@ -4926,17 +4932,17 @@ class MainWP_Child { function search_users() { - $search_user_role = array(); - $check_users_role = false; + $search_user_role = array(); + $check_users_role = false; - if (isset($_POST['role']) && !empty($_POST['role'])) { - $check_users_role = true; - $all_users_role = $this->get_all_users(true); - foreach($all_users_role as $user) { - $search_user_role[] = $user['id']; - } - unset($all_users_role); - } + if (isset($_POST['role']) && !empty($_POST['role'])) { + $check_users_role = true; + $all_users_role = $this->get_all_users(true); + foreach($all_users_role as $user) { + $search_user_role[] = $user['id']; + } + unset($all_users_role); + } $columns = explode( ',', $_POST['search_columns'] ); $allusers = array(); diff --git a/class/class-mainwp-helper.php b/class/class-mainwp-helper.php index 371425f..90b535b 100644 --- a/class/class-mainwp-helper.php +++ b/class/class-mainwp-helper.php @@ -887,9 +887,9 @@ class MainWP_Helper { if ( empty( $wp_filesystem ) ) { ob_start(); - if ( file_exists( ABSPATH . '/wp-admin/includes/deprecated.php' ) ) { - include_once( ABSPATH . '/wp-admin/includes/deprecated.php' ); - } +// if ( file_exists( ABSPATH . '/wp-admin/includes/deprecated.php' ) ) { +// include_once( ABSPATH . '/wp-admin/includes/deprecated.php' ); +// } if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) { include_once( ABSPATH . '/wp-admin/includes/screen.php' ); } diff --git a/class/class-mainwp-keyword-links.php b/class/class-mainwp-keyword-links.php index c2c9130..3eae47e 100644 --- a/class/class-mainwp-keyword-links.php +++ b/class/class-mainwp-keyword-links.php @@ -38,7 +38,7 @@ class MainWP_Keyword_Links { public function keywordLinksJS() { - if ( ! is_admin() && get_option( 'mainwp_kwl_enable_statistic' ) ) { + if ( ! is_admin() && get_option( 'mainwp_kwl_enable_statistic' ) && !empty($this->keyword_links) ) { wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'keywordLinks', plugins_url( '/js/keywordlinks.js', dirname( __FILE__ ) ) ); add_action( 'wp_head', array( $this, 'head_loading' ), 1 ); diff --git a/mainwp-child.php b/mainwp-child.php index d377d7b..f9eba5a 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.3 + Version: 4.0.4 */ include_once( ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'version.php' ); //Version information from wordpress diff --git a/readme.txt b/readme.txt index 3026c1a..4fd8403 100644 --- a/readme.txt +++ b/readme.txt @@ -5,9 +5,9 @@ Author: mainwp Author URI: https://mainwp.com Plugin URI: https://mainwp.com Requires at least: 3.6 -Tested up to: 5.2.3 +Tested up to: 5.3 Requires PHP: 5.6 -Stable tag: 4.0.3 +Stable tag: 4.0.4 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -71,6 +71,12 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m == Changelog == += 4.0.4 - 11-11-19 = +* Fixed: WordPress 5.3 compatibility problems +* Fixed: an issue with managing BackWPup backups +* Updated: multiple error messages +* Removed: unused code + = 4.0.3 - 10-1-19 = * Added: 'mainwp_child_branding_init_options' filter for disabling custom branding * Updated: support for the WPVulnDB API v3