From e1f2eadb901ee654e8a27899cc07ddf3850b92a4 Mon Sep 17 00:00:00 2001 From: Thang Hoang Van Date: Wed, 22 Mar 2023 23:23:07 +0700 Subject: [PATCH 1/3] Fixed: issue of timeout to get Install Extensions for some dashboard. Fixed: fixed missing some of general client fields. Fixed: issue of update website options Fixed: issue of loading user language setting. Fixed: warning on widget client --- class/class-mainwp-api-manager-key.php | 6 ++- ...class-mainwp-api-manager-plugin-update.php | 2 +- class/class-mainwp-db-client.php | 42 ++++++++++++++++--- class/class-mainwp-db.php | 2 + class/class-mainwp-system-utility.php | 12 +++--- class/class-mainwp-system-view.php | 2 +- class/class-mainwp-system.php | 4 +- class/class-mainwp-ui.php | 23 ++++++---- pages/page-mainwp-updates-handler.php | 10 ++++- widgets/widget-mainwp-clients.php | 16 ++++--- 10 files changed, 87 insertions(+), 32 deletions(-) diff --git a/class/class-mainwp-api-manager-key.php b/class/class-mainwp-api-manager-key.php index 5ff3db344..fa0d37d12 100644 --- a/class/class-mainwp-api-manager-key.php +++ b/class/class-mainwp-api-manager-key.php @@ -264,18 +264,20 @@ public function get_purchased_software( $args ) { MainWP_Api_Manager::instance()->get_upgrade_url() . '?mainwp-api=am-software-api', array( 'body' => $args, - 'timeout' => 50, + 'timeout' => 200, 'sslverify' => self::$apisslverify, ) ); + MainWP_Logger::instance()->debug( 'Get purchased softwares: ' . MainWP_Utility::value_to_string( $request ) ); + if ( is_wp_error( $request ) || 200 != wp_remote_retrieve_response_code( $request ) ) { // Request failed. return false; } $response = wp_remote_retrieve_body( $request ); - + return $response; } diff --git a/class/class-mainwp-api-manager-plugin-update.php b/class/class-mainwp-api-manager-plugin-update.php index 21180223a..5f32d332f 100644 --- a/class/class-mainwp-api-manager-plugin-update.php +++ b/class/class-mainwp-api-manager-plugin-update.php @@ -171,7 +171,7 @@ public function plugin_information( $args, $bulk_check = false ) { $target_url = $this->create_upgrade_api_url( $args, $bulk_check ); $default = array( - 'timeout' => 50, + 'timeout' => 150, 'sslverify' => 1, ); diff --git a/class/class-mainwp-db-client.php b/class/class-mainwp-db-client.php index bf9b9c2d7..a28faf820 100644 --- a/class/class-mainwp-db-client.php +++ b/class/class-mainwp-db-client.php @@ -1112,25 +1112,57 @@ public function get_client_fields( $general = true, $client_id = 0, $field_name_ return false; } + $gene_results = array(); + + if ( $general ) { + // to fix: missing general fields for client without client fields values. + $gene_sql = 'SELECT f.* FROM ' . $this->table_name( 'wp_clients_fields' ) . ' f WHERE f.client_id = 0 ORDER BY f.field_name '; + $gene_results = $this->wpdb->get_results( $gene_sql ); + } + if ( $client_id ) { // get fields values of client. - $sql = 'SELECT f.*,v.value_client_id, v.field_value as field_value FROM ' . $this->table_name( 'wp_clients_fields' ) . ' f LEFT JOIN ' . + $sql = 'SELECT f.*, v.field_value as field_value FROM ' . $this->table_name( 'wp_clients_fields' ) . ' f LEFT JOIN ' . $this->table_name( 'wp_clients_field_values' ) . ' v ON f.field_id = v.field_id WHERE ' . $where . ' ORDER BY f.field_name '; } else { $sql = 'SELECT f.* FROM ' . $this->table_name( 'wp_clients_fields' ) . ' f WHERE ' . $where . ' ORDER BY f.field_name '; // value_client_id to compatible result. } + $results = $this->wpdb->get_results( $sql ); + + $fields_list = array(); if ( $field_name_index ) { - $results = $this->wpdb->get_results( $sql ); - $fields_list = array(); if ( $results ) { foreach ( $results as $item ) { $fields_list[ $item->field_name ] = $item; } } - return $fields_list; + if ( $gene_results ) { + foreach ( $gene_results as $gene_item ) { + if ( ! isset( $fields_list[ $gene_item->field_name ] ) ) { + $gene_item->field_value = ''; + $fields_list[ $gene_item->field_name ] = $gene_item; + } + } + } } else { - return $this->wpdb->get_results( $sql ); + $check_list = array(); + if ( $results ) { + foreach ( $results as $item ) { + $check_list[ $item->field_name ] = true; + $fields_list[] = $item; + } + } + if ( $gene_results ) { + foreach ( $gene_results as $gene_item ) { + if ( ! isset( $check_list[ $gene_item->field_name ] ) ) { + $check_list[ $gene_item->field_name ] = true; + $gene_item->field_value = ''; + $fields_list[] = $gene_item; + } + } + } } + return $fields_list; } /** diff --git a/class/class-mainwp-db.php b/class/class-mainwp-db.php index 8338aa998..6fc522eb9 100644 --- a/class/class-mainwp-db.php +++ b/class/class-mainwp-db.php @@ -274,6 +274,8 @@ public function get_website_options_array( &$website, $options ) { } else { $get_options[] = $option; } + } else { + $get_options[] = $option; } } diff --git a/class/class-mainwp-system-utility.php b/class/class-mainwp-system-utility.php index fdabc7c65..ca0884426 100644 --- a/class/class-mainwp-system-utility.php +++ b/class/class-mainwp-system-utility.php @@ -692,18 +692,18 @@ public static function get_child_response( $data ) { } if ( isset( $resp['notices'] ) ) { - $notices = array(); if ( is_string( $resp['notices'] ) ) { - $notices = MainWP_Utility::esc_content( $resp['notices'] ); + $resp['notices'] = MainWP_Utility::esc_content( $resp['notices'] ); } elseif ( is_array( $resp['notices'] ) ) { + $notices = array(); foreach ( $resp['notices'] as $noti ) { - if ( is_string( $noti ) ) { + if ( ! empty( $noti ) && is_string( $noti ) ) { $notices[] = MainWP_Utility::esc_content( $noti ); } } - } - if ( ! empty( $notices ) ) { - $resp['notices'] = $notices; + if ( ! empty( $notices ) ) { + $resp['notices'] = implode( ' || ', $notices ); + } } } } diff --git a/class/class-mainwp-system-view.php b/class/class-mainwp-system-view.php index 8985843bf..3613b081e 100644 --- a/class/class-mainwp-system-view.php +++ b/class/class-mainwp-system-view.php @@ -898,7 +898,7 @@ public static function get_plugins_install_check() { 'name' => 'Jetpack Protect', ), array( - 'page' => 'Extensions-Mainwp-Jetpack-Scan-Extension', + 'page' => 'Extensions-Mainwp-Jetpack-Scan-Extension', 'slug' => 'jetpack/jetpack.php', 'name' => 'Jetpack', ), diff --git a/class/class-mainwp-system.php b/class/class-mainwp-system.php index ce09589f8..cfbe9a2f3 100644 --- a/class/class-mainwp-system.php +++ b/class/class-mainwp-system.php @@ -126,7 +126,7 @@ public function __construct( $mainwp_plugin_file ) { if ( is_admin() ) { include_once ABSPATH . 'wp-admin' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'plugin.php'; - $pluginData = get_plugin_data( $mainwp_plugin_file ); + $pluginData = get_plugin_data( $mainwp_plugin_file, true, false ); // to fix issue of user language setting. $this->current_version = $pluginData['Version']; $currentVersion = get_option( 'mainwp_plugin_version' ); @@ -165,7 +165,7 @@ public function __construct( $mainwp_plugin_file ) { $systemHandler = MainWP_System_Handler::instance(); - add_action( 'init', array( &$this, 'localization' ) ); + add_action( 'plugins_loaded', array( &$this, 'localization' ) ); add_filter( 'site_transient_update_plugins', array( $systemHandler, 'check_update_custom' ) ); add_filter( 'pre_set_site_transient_update_plugins', array( $systemHandler, 'pre_check_update_custom' ) ); add_filter( 'plugins_api', array( $systemHandler, 'plugins_api_info' ), 10, 3 ); diff --git a/class/class-mainwp-ui.php b/class/class-mainwp-ui.php index 5b6907c14..92bbdb13d 100644 --- a/class/class-mainwp-ui.php +++ b/class/class-mainwp-ui.php @@ -1137,16 +1137,25 @@ public static function render_header_actions() { $sidebar_pages = apply_filters( 'mainwp_sidbar_pages', $sidebar_pages ); // deprecated filter. $sidebar_pages = apply_filters( 'mainwp_sidebar_pages', $sidebar_pages ); ob_start(); - if ( isset( $_GET['dashboard'] ) ) : + if ( isset( $_GET['dashboard'] ) || isset( $_GET['id'] ) || isset( $_GET['updateid'] ) || isset( $_GET['emailsettingsid'] ) || isset( $_GET['scanid'] ) ) : + if ( isset( $_GET['dashboard'] ) ) { $id = intval( $_GET['dashboard'] ); + } else if ( isset( $_GET['id'] ) ) { + $id = intval( $_GET['id'] ); + } else if ( isset( $_GET['updateid'] ) ) { + $id = intval( $_GET['updateid'] ); + } else if ( isset( $_GET['emailsettingsid'] ) ) { + $id = intval( $_GET['emailsettingsid'] ); + } else if ( isset( $_GET['scanid'] ) ) { + $id = intval( $_GET['scanid'] ); + } + + $website = MainWP_DB::instance()->get_website_by_id( $id ); - if ( '' != $website->sync_errors ) : - ?> + if ( '' != $website->sync_errors ) : ?> - + diff --git a/pages/page-mainwp-updates-handler.php b/pages/page-mainwp-updates-handler.php index ac4dacb32..a726583ed 100644 --- a/pages/page-mainwp-updates-handler.php +++ b/pages/page-mainwp-updates-handler.php @@ -658,6 +658,7 @@ public static function upgrade_plugin_theme_translation( $id, $type, $list ) { } $result = self::update_plugin_theme_translation( $website, $type, $list ); if ( is_array( $result ) ) { + $undefined = true; if ( isset( $result['upgrades'] ) ) { $tmp = array(); if ( isset( $result['upgrades'] ) ) { @@ -669,8 +670,13 @@ public static function upgrade_plugin_theme_translation( $id, $type, $list ) { } elseif ( isset( $result['error'] ) ) { throw new MainWP_Exception( 'WPERROR', esc_html( $result['error'] ) ); } elseif ( isset( $result['notices'] ) ) { - throw new MainWP_Exception( $result['notices'], '', 'MAINWP_NOTICE' ); - } else { + $noti = $result['notices']; + if ( ! empty( $noti ) && is_string( $noti ) ) { + throw new MainWP_Exception( $noti, '', 'MAINWP_NOTICE' ); + } + } + + if ( $undefined ) { throw new MainWP_Exception( 'ERROR', esc_html__( 'Invalid response retured from the child site. Please try again.', 'mainwp' ) ); } } diff --git a/widgets/widget-mainwp-clients.php b/widgets/widget-mainwp-clients.php index eace1bcc7..8e887bf24 100644 --- a/widgets/widget-mainwp-clients.php +++ b/widgets/widget-mainwp-clients.php @@ -99,19 +99,23 @@ private static function render_clients( $clients ) { get_wp_client_contact_by( 'contact_id', $client['primary_contact_id'] ); - ?> + if ( $contact ) { + ?> contact_name ); ?> contact_role ) && '' != $contact->contact_role ) ? ' - ' . esc_html( $contact->contact_role ) : ''; ?>
- contact_email ) && '' != $contact->contact_email ) : ?> + contact_email ) && '' != $contact->contact_email ) : ?> contact_email ); ?>
- contact_phone ) && '' != $contact->contact_phone ) : ?> + contact_phone ) && '' != $contact->contact_phone ) : ?> contact_phone ); ?> - From 6f86f9c1b3e896191b140e7c7cd091c14f23df0f Mon Sep 17 00:00:00 2001 From: codefactor-io Date: Wed, 22 Mar 2023 16:26:03 +0000 Subject: [PATCH 2/3] [CodeFactor] Apply fixes to commit e1f2ead [ci skip] [skip ci] --- class/class-mainwp-api-manager-key.php | 2 +- class/class-mainwp-db-client.php | 6 +++--- class/class-mainwp-system-view.php | 2 +- class/class-mainwp-ui.php | 16 ++++++++-------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/class/class-mainwp-api-manager-key.php b/class/class-mainwp-api-manager-key.php index fa0d37d12..8ae4e8ff3 100644 --- a/class/class-mainwp-api-manager-key.php +++ b/class/class-mainwp-api-manager-key.php @@ -277,7 +277,7 @@ public function get_purchased_software( $args ) { } $response = wp_remote_retrieve_body( $request ); - + return $response; } diff --git a/class/class-mainwp-db-client.php b/class/class-mainwp-db-client.php index a28faf820..a42f46b12 100644 --- a/class/class-mainwp-db-client.php +++ b/class/class-mainwp-db-client.php @@ -1139,7 +1139,7 @@ public function get_client_fields( $general = true, $client_id = 0, $field_name_ if ( $gene_results ) { foreach ( $gene_results as $gene_item ) { if ( ! isset( $fields_list[ $gene_item->field_name ] ) ) { - $gene_item->field_value = ''; + $gene_item->field_value = ''; $fields_list[ $gene_item->field_name ] = $gene_item; } } @@ -1156,8 +1156,8 @@ public function get_client_fields( $general = true, $client_id = 0, $field_name_ foreach ( $gene_results as $gene_item ) { if ( ! isset( $check_list[ $gene_item->field_name ] ) ) { $check_list[ $gene_item->field_name ] = true; - $gene_item->field_value = ''; - $fields_list[] = $gene_item; + $gene_item->field_value = ''; + $fields_list[] = $gene_item; } } } diff --git a/class/class-mainwp-system-view.php b/class/class-mainwp-system-view.php index 3613b081e..8985843bf 100644 --- a/class/class-mainwp-system-view.php +++ b/class/class-mainwp-system-view.php @@ -898,7 +898,7 @@ public static function get_plugins_install_check() { 'name' => 'Jetpack Protect', ), array( - 'page' => 'Extensions-Mainwp-Jetpack-Scan-Extension', + 'page' => 'Extensions-Mainwp-Jetpack-Scan-Extension', 'slug' => 'jetpack/jetpack.php', 'name' => 'Jetpack', ), diff --git a/class/class-mainwp-ui.php b/class/class-mainwp-ui.php index 92bbdb13d..a96fcad54 100644 --- a/class/class-mainwp-ui.php +++ b/class/class-mainwp-ui.php @@ -1139,21 +1139,21 @@ public static function render_header_actions() { ob_start(); if ( isset( $_GET['dashboard'] ) || isset( $_GET['id'] ) || isset( $_GET['updateid'] ) || isset( $_GET['emailsettingsid'] ) || isset( $_GET['scanid'] ) ) : if ( isset( $_GET['dashboard'] ) ) { - $id = intval( $_GET['dashboard'] ); - } else if ( isset( $_GET['id'] ) ) { + $id = intval( $_GET['dashboard'] ); + } elseif ( isset( $_GET['id'] ) ) { $id = intval( $_GET['id'] ); - } else if ( isset( $_GET['updateid'] ) ) { + } elseif ( isset( $_GET['updateid'] ) ) { $id = intval( $_GET['updateid'] ); - } else if ( isset( $_GET['emailsettingsid'] ) ) { + } elseif ( isset( $_GET['emailsettingsid'] ) ) { $id = intval( $_GET['emailsettingsid'] ); - } else if ( isset( $_GET['scanid'] ) ) { + } elseif ( isset( $_GET['scanid'] ) ) { $id = intval( $_GET['scanid'] ); } - - + $website = MainWP_DB::instance()->get_website_by_id( $id ); - if ( '' != $website->sync_errors ) : ?> + if ( '' != $website->sync_errors ) : + ?>