PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / trunk
MainWP Dashboard: Self-hosted WordPress Management for Agencies vtrunk
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
← All changes | class/class-mainwp-post-handler.php +337 -66 5.3trunk View file →
@@ -6,8 +6,16 @@
6 6 */
7 7
8 8 namespace MainWP\Dashboard;
9 9
10 +use MainWP\Dashboard\Module\Log\Log_DB_Helper;
11 +use MainWP\Dashboard\Module\Log\Log_Changes_Logs_Helper;
12 +
13 +// Exit if accessed directly.
14 +if ( ! defined( 'ABSPATH' ) ) {
15 + exit;
16 +}
17 +
10 18 // phpcs:disable Generic.Metrics.CyclomaticComplexity -- complexity.
11 19
12 20 /**
13 21 * Class MainWP_Post_Handler
@@ -71,8 +79,10 @@
71 79 $this->add_action( 'mainwp_leftmenu_filter_group', array( &$this, 'mainwp_leftmenu_filter_group' ) );
72 80 $this->add_action( 'mainwp_widgets_order', array( &$this, 'ajax_widgets_order' ) );
73 81 $this->add_action( 'mainwp_save_settings', array( &$this, 'ajax_mainwp_save_settings' ) );
74 82 $this->add_action( 'mainwp_guided_tours_option_update', array( &$this, 'ajax_guided_tours_option_update' ) );
83 + $this->add_action( 'mainwp_help_modal_content_update', array( &$this, 'ajax_mainwp_help_modal_content_update' ) );
84 + $this->add_action( 'mainwp_widgets_connections_status_details_display_rows', array( MainWP_Connection_Status::instance(), 'ajax_display_rows' ) );
75 85
76 86 // Page: Recent Posts.
77 87 if ( \mainwp_current_user_can( 'dashboard', 'manage_posts' ) ) {
78 88 $this->add_action( 'mainwp_post_unpublish', array( &$this, 'mainwp_post_unpublish' ) );
@@ -128,8 +138,9 @@
128 138 $this->add_action( 'mainwp_clients_delete_client', array( &$this, 'mainwp_clients_delete_client' ) );
129 139
130 140 $this->add_action( 'mainwp_clients_save_field', array( &$this, 'mainwp_clients_save_field' ) );
131 141 $this->add_action( 'mainwp_clients_delete_general_field', array( &$this, 'mainwp_clients_delete_general_field' ) );
142 + $this->add_action( 'mainwp_clients_bulk_delete_fields', array( &$this, 'mainwp_clients_bulk_delete_fields' ) );
132 143 $this->add_action( 'mainwp_clients_delete_field', array( &$this, 'mainwp_clients_delete_field' ) );
133 144 $this->add_action( 'mainwp_clients_notes_save', array( &$this, 'mainwp_clients_notes_save' ) );
134 145 $this->add_action( 'mainwp_clients_suspend_client', array( &$this, 'mainwp_clients_suspend_client' ) );
135 146 $this->add_action( 'mainwp_refresh_icon', array( &$this, 'ajax_refresh_icon' ) );
@@ -134,15 +145,16 @@
134 145 $this->add_action( 'mainwp_clients_suspend_client', array( &$this, 'mainwp_clients_suspend_client' ) );
135 146 $this->add_action( 'mainwp_refresh_icon', array( &$this, 'ajax_refresh_icon' ) );
136 147 $this->add_action( 'mainwp_upload_custom_icon', array( &$this, 'ajax_upload_custom_icon' ) );
137 148 $this->add_action( 'mainwp_select_custom_theme', array( &$this, 'ajax_select_custom_theme' ) );
138 - $this->add_action( 'mainwp_site_actions_dismiss', array( &$this, 'ajax_site_actions_dismiss' ) );
139 - $this->add_action( 'mainwp_delete_non_mainwp_actions', array( &$this, 'ajax_delete_non_mainwp_actions' ) );
140 149 $this->add_action( 'mainwp_import_demo_data', array( &$this, 'ajax_import_demo_data' ) );
141 150 $this->add_action( 'mainwp_delete_demo_data', array( &$this, 'ajax_delete_demo_data' ) );
142 151 $this->add_action( 'mainwp_prepare_renew_connections', array( MainWP_Connect_Helper::instance(), 'ajax_prepare_renew_connections' ) );
143 152 $this->add_action( 'mainwp_renew_connections', array( MainWP_Connect_Helper::instance(), 'ajax_renew_connections' ) );
144 153
154 + $this->add_action( 'mainwp_clients_check_client', array( &$this, 'mainwp_clients_check_client' ) );
155 + $this->add_action( 'mainwp_clients_import_client', array( &$this, 'mainwp_clients_import_client' ) );
156 +
145 157 // Page: managesites.
146 158 $this->add_action( 'mainwp_save_temp_import_website', array( &$this, 'ajax_save_temp_import_website' ) );
147 159 $this->add_action( 'mainwp_delete_temp_import_website', array( &$this, 'ajax_delete_temp_import_website' ) );
148 160 $this->add_action( 'mainwp_import_website_add_client', array( &$this, 'ajax_import_website_add_client' ) );
@@ -150,8 +162,11 @@
150 162
151 163 // Page:: mainwp-setup.
152 164 $this->add_action( 'mainwp_clients_add_multi_client', array( &$this, 'ajax_clients_add_multi_client' ) );
153 165 $this->add_action( 'mainwp_increase_connection_security', array( &$this, 'ajax_increase_connection_security' ) );
166 + $this->add_action( 'mainwp_qsw_ui_mode_detected', array( &$this, 'ajax_ui_mode_detected' ) );
167 +
168 + $this->add_action( 'mainwp_changes_logs_get_item_changes', array( &$this, 'ajax_get_item_changes_logs' ) );
154 169 }
155 170
156 171 /**
157 172 * Method add_post_action()
@@ -197,8 +212,9 @@
197 212 $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
198 213 $search = isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '';
199 214 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
200 215 MainWP_User::render_table( false, $role, $groups, $sites, $search, $clients );
216 + session_write_close();
201 217 die();
202 218 }
203 219
204 220 /**
@@ -523,12 +539,30 @@
523 539 $this->secure_request( 'mainwp_notice_status_update' );
524 540
525 541 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
526 542 $no_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : false;
543 +
544 + if ( ! empty( $_POST['short_term'] ) ) {
545 + if ( empty( $no_id ) ) {
546 + die( 'invalid' );
547 + }
548 +
549 + $keys = explode( ';', $no_id );
550 + foreach ( $keys as $key ) {
551 + MainWP_Utility::dismiss_short_term_notice( $key );
552 + }
553 + die( 'dismissed' );
554 + }
555 +
527 556 if ( 'mail_failed' === $no_id ) {
528 557 MainWP_Utility::update_option( 'mainwp_notice_wp_mail_failed', 'hide' );
529 558 die( 'ok' );
530 559 }
560 +
561 + if ( 'phpver_8_0' === $no_id ) {
562 + MainWP_Utility::update_user_option( 'lasttime_hidden_phpver_8_0', time() );
563 + }
564 +
531 565 $time_set = isset( $_POST['time_set'] ) && 1 === intval( $_POST['time_set'] ) ? true : false;
532 566 $this->hide_dashboard_notice_status( $no_id, $time_set );
533 567 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
534 568 die( 1 );
@@ -635,11 +669,12 @@
635 669 $this->secure_request( 'mainwp_widgets_order' );
636 670 $user = wp_get_current_user();
637 671 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
638 672 if ( $user && ! empty( $_POST['page'] ) ) {
639 - $page = isset( $_POST['page'] ) ? sanitize_text_field( wp_unslash( $_POST['page'] ) ) : '';
640 - $order = isset( $_POST['order'] ) ? sanitize_text_field( wp_unslash( $_POST['order'] ) ) : '';
641 - $wgids = isset( $_POST['wgids'] ) ? sanitize_text_field( wp_unslash( $_POST['wgids'] ) ) : '';
673 + $page = isset( $_POST['page'] ) ? sanitize_text_field( wp_unslash( $_POST['page'] ) ) : '';
674 + $order = isset( $_POST['order'] ) ? sanitize_text_field( wp_unslash( $_POST['order'] ) ) : '';
675 + $wgids = isset( $_POST['wgids'] ) ? sanitize_text_field( wp_unslash( $_POST['wgids'] ) ) : '';
676 + $page_widget = isset( $_POST['page_widget'] ) ? sanitize_text_field( wp_unslash( $_POST['page_widget'] ) ) : '';
642 677
643 678 $wgs_orders = array();
644 679
645 680 if ( ! empty( $wgids ) ) {
@@ -647,9 +682,9 @@
647 682 $order = json_decode( $order, true );
648 683 if ( is_array( $wgids ) && is_array( $order ) ) {
649 684 foreach ( $wgids as $idx => $wgid ) {
650 685 if ( isset( $order[ $idx ] ) ) {
651 - $pre = 'widget-';
686 + $pre = 'widget-'; // #compatible-widgetid.
652 687 if ( 0 === strpos( $wgid, $pre ) ) {
653 688 $wgid = substr( $wgid, strlen( $pre ) );
654 689 }
655 690 $wgs_orders[ $wgid ] = $order[ $idx ];
@@ -671,8 +706,9 @@
671 706 update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $sorted_array ), true );
672 707 } else {
673 708 update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $wgs_orders ), true );
674 709 }
710 + MainWP_Cache_Warm_Helper::invalidate_manage_pages( array( $page_widget ) );
675 711 die( 'ok' );
676 712 }
677 713 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
678 714 die( -1 );
@@ -714,8 +750,23 @@
714 750 die( 'ok ' . intval( $enable ) );
715 751 }
716 752
717 753 /**
754 + * Method mainwp_help_modal_content_update()
755 + *
756 + * Update saved MainWP Settings.
757 + *
758 + * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
759 + */
760 + public function ajax_mainwp_help_modal_content_update() {
761 + $this->secure_request( 'mainwp_help_modal_content_update' );
762 + MainWP_Utility::update_option( 'mainwp_enable_guided_tours', ( int)$_POST['enable_tour'] ); //phpcs:ignore -- NOSONAR verify.
763 + MainWP_Utility::update_option( 'mainwp_enable_guided_video', (int)$_POST['enable_video'] ); //phpcs:ignore -- NOSONAR verify.
764 + MainWP_Utility::update_option( 'mainwp_enable_guided_chatbase', (int)$_POST['enable_chatbase'] ); //phpcs:ignore -- NOSONAR verify.
765 + die( 'ok' );
766 + }
767 +
768 + /**
718 769 * Method mainwp_leftmenu_filter_group()
719 770 *
720 771 * MainWP left menu filter by group.
721 772 *
@@ -973,8 +1024,9 @@
973 1024 if ( $client_id ) {
974 1025 MainWP_DB_Client::instance()->delete_client( $client_id );
975 1026 $ret['success'] = 'SUCCESS';
976 1027 $ret['result'] = esc_html__( 'Client removed successfully.', 'mainwp' );
1028 + MainWP_Client::invalidate_warm_cache();
977 1029 } else {
978 1030 $ret['result'] = esc_html__( 'Client ID empty.', 'mainwp' );
979 1031 }
980 1032
@@ -988,8 +1040,9 @@
988 1040 * Save client custom fields.
989 1041 */
990 1042 public function mainwp_clients_save_field() {
991 1043 $this->check_security( 'mainwp_clients_save_field' );
1044 + MainWP_Client::invalidate_warm_cache();
992 1045 MainWP_Client::save_client_field();
993 1046 die();
994 1047 }
995 1048
@@ -1007,8 +1060,9 @@
1007 1060 $client_id = 0; // 0 general fields.
1008 1061 if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
1009 1062 $ret['success'] = true;
1010 1063 }
1064 + MainWP_Client::invalidate_warm_cache();
1011 1065 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1012 1066 echo wp_json_encode( $ret );
1013 1067 exit;
1014 1068 }
@@ -1013,8 +1067,45 @@
1013 1067 exit;
1014 1068 }
1015 1069
1016 1070 /**
1071 + * Method mainwp_clients_bulk_delete_fields()
1072 + *
1073 + * Bulk delete client general fields.
1074 + */
1075 + public function mainwp_clients_bulk_delete_fields() {
1076 + $this->check_security( 'mainwp_clients_bulk_delete_fields' );
1077 + $ret = array( 'success' => false );
1078 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1079 + $field_ids = isset( $_POST['field_ids'] ) && is_array( $_POST['field_ids'] ) ? array_map( 'intval', $_POST['field_ids'] ) : array();
1080 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1081 +
1082 + if ( empty( $field_ids ) ) {
1083 + $ret['data'] = array( 'message' => __( 'No fields selected.', 'mainwp' ) );
1084 + echo wp_json_encode( $ret );
1085 + exit;
1086 + }
1087 +
1088 + $client_id = 0; // 0 general fields.
1089 + $deleted_count = 0;
1090 + foreach ( $field_ids as $field_id ) {
1091 + if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
1092 + ++$deleted_count;
1093 + }
1094 + }
1095 +
1096 + if ( $deleted_count > 0 ) {
1097 + $ret['success'] = true;
1098 + MainWP_Client::invalidate_warm_cache();
1099 + } else {
1100 + $ret['data'] = array( 'message' => __( 'Failed to delete fields.', 'mainwp' ) );
1101 + }
1102 +
1103 + echo wp_json_encode( $ret );
1104 + exit;
1105 + }
1106 +
1107 + /**
1017 1108 * Method mainwp_clients_delete_field()
1018 1109 *
1019 1110 * Delete client custom fields.
1020 1111 */
@@ -1101,8 +1192,114 @@
1101 1192 wp_die( 'success' );
1102 1193 }
1103 1194
1104 1195 /**
1196 + * Method mainwp_clients_check_client()
1197 + *
1198 + * The client check has been created in the system yet.
1199 + *
1200 + * @uses \MainWP_DB_Client::instance()->get_wp_client_by()
1201 + */
1202 + public function mainwp_clients_check_client() {
1203 + $this->secure_request( 'mainwp_clients_check_client' );
1204 + // phpcs:disable WordPress.Security.NonceVerification
1205 + $client_email = isset( $_POST['email'] ) ? sanitize_text_field( wp_unslash( $_POST['email'] ) ) : '';
1206 + // phpcs:enable WordPress.Security.NonceVerification
1207 + $client_existed = MainWP_DB_Client::instance()->get_wp_client_by( 'client_email', $client_email, ARRAY_A );
1208 + if ( is_array( $client_existed ) && isset( $client_existed['client_id'] ) ) {
1209 + return wp_send_json_error( array( 'error' => esc_html__( 'Client email exists. Please try again.', 'mainwp' ) ) );
1210 + }
1211 + return wp_send_json_success( array( 'result' => esc_html__( 'Client email not exists.', 'mainwp' ) ) );
1212 + }
1213 +
1214 + /**
1215 + * Method mainwp_clients_import_client()
1216 + *
1217 + * Import new client
1218 + *
1219 + * @uses \MainWP_DB::instance()->get_websites_by_url()
1220 + * @uses \MainWP_Client_Handler::get_default_client_fields()
1221 + * @uses \MainWP_DB_Client::instance()->update_client()
1222 + * @uses \MainWP_DB_Client::instance()->update_selected_sites_for_client()
1223 + */
1224 + public function mainwp_clients_import_client() { // phpcs:ignore -- NOSONAR
1225 + $this->secure_request( 'mainwp_clients_import_client' );
1226 + // phpcs:disable
1227 + // Set value from POST data.
1228 + $default_values = array(
1229 + 'client.name' => ! empty( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '',
1230 + 'client.email' => ! empty( $_POST['email'] ) ? sanitize_text_field( wp_unslash( $_POST['email'] ) ) : '',
1231 + 'client.contact.address.1' => ! empty( $_POST['address_1'] ) ? sanitize_text_field( wp_unslash( $_POST['address_1'] ) ) : '',
1232 + 'client.contact.address.2' => ! empty( $_POST['address_2'] ) ? sanitize_text_field( wp_unslash( $_POST['address_2'] ) ) : '',
1233 + 'client.city' => ! empty( $_POST['city'] ) ? sanitize_text_field( wp_unslash( $_POST['city'] ) ) : '',
1234 + 'client.state' => ! empty( $_POST['state'] ) ? sanitize_text_field( wp_unslash( $_POST['state'] ) ) : '',
1235 + 'client.zip' => ! empty( $_POST['zip'] ) ? sanitize_text_field( wp_unslash( $_POST['zip'] ) ) : '',
1236 + 'client.country' => ! empty( $_POST['country'] ) ? sanitize_text_field( wp_unslash( $_POST['country'] ) ) : '',
1237 + 'client.suspended' => ! empty( $_POST['suspended'] ) ? sanitize_text_field( wp_unslash( $_POST['suspended'] ) ) : 0,
1238 + );
1239 + // Get Site id.
1240 + $selected_sites = array();
1241 + if ( ! empty( $_POST['urls'] ) ) {
1242 + $urls = array_map( 'sanitize_text_field', wp_unslash( $_POST['urls'] ) );
1243 + $selected_sites = array_filter(
1244 + array_map(
1245 + function ( $v_url ) {
1246 + $url = esc_url( $v_url );
1247 + $website = MainWP_DB::instance()->get_websites_by_url( $url );
1248 + return ! empty( $website ) ? current( $website )->id : null;
1249 + },
1250 + $urls
1251 + )
1252 + );
1253 + }
1254 + // phpcs:enable
1255 + $client_to_add = array();
1256 + $default_client_fields = MainWP_Client_Handler::get_default_client_fields(); // Get client field database.
1257 + foreach ( $default_values as $key_client => $val_client ) {
1258 + if ( isset( $default_client_fields[ $key_client ] ) && ! empty( $default_client_fields[ $key_client ]['db_field'] ) && ! empty( $val_client ) ) {
1259 + $client_to_add[ $default_client_fields[ $key_client ]['db_field'] ] = $val_client; // Assign data to customers according to DB Field.
1260 + }
1261 + }
1262 +
1263 + if ( ! empty( $client_to_add ) ) {
1264 + // Set default values.
1265 + $client_to_add['created'] = time();
1266 + $client_to_add['primary_contact_id'] = 0;
1267 + // Inset client.
1268 + $inserted = MainWP_DB_Client::instance()->update_client( $client_to_add, true );
1269 +
1270 + if ( ! empty( $inserted ) && is_object( $inserted ) ) {
1271 + if ( ! empty( $selected_sites ) ) {
1272 + MainWP_DB_Client::instance()->update_selected_sites_for_client( $inserted->client_id, $selected_sites ); // Set client to selected sites.
1273 + }
1274 + // Set default color and icon .
1275 + $update = array(
1276 + 'client_id' => $inserted->client_id,
1277 + 'selected_icon_info' => 'selected:wordpress;color:#34424d',
1278 + );
1279 + MainWP_DB_Client::instance()->update_client( $update ); // Update Client.
1280 +
1281 + return wp_send_json_success(
1282 + array(
1283 + 'message' => esc_html__( 'successful client.', 'mainwp' ),
1284 + 'client' => $inserted,
1285 + )
1286 + );
1287 + }
1288 + return wp_send_json_error(
1289 + array(
1290 + 'message' => esc_html__( 'unsuccessful client.', 'mainwp' ),
1291 + )
1292 + );
1293 + }
1294 + return wp_send_json_error(
1295 + array(
1296 + 'message' => esc_html__( 'Error, please try again later.', 'mainwp' ),
1297 + )
1298 + );
1299 + }
1300 +
1301 + /**
1105 1302 * Method mainwp_syncerrors_dismiss()
1106 1303 *
1107 1304 * Dismiss Sync errors for,
1108 1305 * Widget: RightNow.
@@ -1347,9 +1544,9 @@
1347 1544
1348 1545 /**
1349 1546 * Method ajax_upload_custom_icon()
1350 1547 */
1351 - public function ajax_upload_custom_icon() {
1548 + public function ajax_upload_custom_icon() { //phpcs:ignore -- NOSONAR -complex.
1352 1549 $this->secure_request( 'mainwp_upload_custom_icon' );
1353 1550 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1354 1551 $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1355 1552 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
@@ -1355,9 +1552,9 @@
1355 1552 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1356 1553 $delete = isset( $_POST['delete'] ) ? intval( $_POST['delete'] ) : 0;
1357 1554
1358 1555 if ( empty( $slug ) || ( 'plugin' !== $type && 'theme' !== $type ) ) {
1359 - wp_die( 'invalid data!' );
1556 + wp_die( 'Invalid data! Type or empty slug' );
1360 1557 }
1361 1558
1362 1559 $sub_folder = '';
1363 1560
@@ -1385,13 +1582,55 @@
1385 1582 if ( 'NOTCHANGE' !== $uploaded_icon ) {
1386 1583 MainWP_System_Utility::update_cached_icons( $uploaded_icon, $slug, $type, true );
1387 1584 wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1388 1585 } else {
1389 - wp_die( wp_json_encode( array( 'result' => 'failed' ) ) );
1586 + $result = array(
1587 + 'result' => 'failed',
1588 + );
1589 + $error = static::get_upload_icon_error( $output );
1590 + if ( ! empty( $error ) ) {
1591 + $result['error'] = esc_html( $error );
1592 + }
1593 + wp_die( wp_json_encode( $result ) );
1390 1594 }
1391 1595 }
1392 1596
1393 1597 /**
1598 + * Method get_upload_icon_error().
1599 + *
1600 + * @param mixed $results Upload results.
1601 + *
1602 + * @return string
1603 + */
1604 + public static function get_upload_icon_error( $results ) {
1605 + $error = '';
1606 + if ( is_array( $results ) && ! empty( $results['error'] ) && is_array( $results['error'] ) ) {
1607 + $error_code = $results['error'][0];
1608 + switch ( $error_code ) {
1609 + case 3:
1610 + $error = __( 'File size is too big. Please try a smaller file.', 'mainwp' );
1611 + break;
1612 + case 4:
1613 + $error = __( 'File type is not allowed. Please use a different file type.', 'mainwp' );
1614 + break;
1615 + case 5:
1616 + $error = __( 'File extension is not allowed. Please use a different file type.', 'mainwp' );
1617 + break;
1618 + case 6:
1619 + $error = __( 'Cannot copy file. Please try again.', 'mainwp' );
1620 + break;
1621 + case 9:
1622 + $error = __( 'Failed to crop file. Please try again.', 'mainwp' );
1623 + break;
1624 + default:
1625 + $error = __( 'Undefined error. Please try again.', 'mainwp' );
1626 + break;
1627 + }
1628 + }
1629 + return $error;
1630 + }
1631 +
1632 + /**
1394 1633 * Method ajax_select_custom_theme()
1395 1634 */
1396 1635 public function ajax_select_custom_theme() {
1397 1636 $this->secure_request( 'mainwp_select_custom_theme' );
@@ -1410,66 +1649,9 @@
1410 1649 update_user_option( $user->ID, 'mainwp_selected_theme', $theme );
1411 1650 wp_die( 'success' );
1412 1651 }
1413 1652
1414 -
1415 1653 /**
1416 - * Method ajax_site_actions_dismiss()
1417 - */
1418 - public function ajax_site_actions_dismiss() {
1419 - $this->secure_request( 'mainwp_site_actions_dismiss' );
1420 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1421 - $action_id = isset( $_POST['action_id'] ) ? intval( $_POST['action_id'] ) : 0;
1422 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1423 -
1424 - if ( empty( $action_id ) ) {
1425 - wp_die( 'failed' );
1426 - }
1427 - $update = array(
1428 - 'dismiss' => 1,
1429 - );
1430 - MainWP_DB_Site_Actions::instance()->update_action_by_id( $action_id, $update );
1431 - wp_die( 'success' );
1432 - }
1433 -
1434 - /**
1435 - * Method ajax_site_actions_dismiss()
1436 - */
1437 - public function ajax_delete_non_mainwp_actions() {
1438 - $this->secure_request( 'mainwp_delete_non_mainwp_actions' );
1439 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1440 - $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
1441 - if ( empty( $siteid ) ) {
1442 - wp_die( wp_json_encode( array( 'error' => 'Empty site ID' ) ) );
1443 - }
1444 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1445 - $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1446 - $success = false;
1447 - $error = '';
1448 - try {
1449 - $response = MainWP_Connect::fetch_url_authed( $website, 'delete_actions', array( 'del' => 'act' ) );
1450 - if ( is_array( $response ) ) {
1451 - if ( isset( $response['success'] ) ) {
1452 - $success = true;
1453 - } elseif ( isset( $response['error'] ) ) {
1454 - $error = $response['error'];
1455 - }
1456 - }
1457 - } catch ( \Exception $e ) {
1458 - // ok!
1459 - }
1460 - if ( $success ) {
1461 - MainWP_DB_Site_Actions::instance()->delete_action_by( 'wpid', $siteid );
1462 - wp_die( wp_json_encode( array( 'success' => 'ok' ) ) );
1463 - }
1464 -
1465 - if ( empty( $error ) ) {
1466 - $error = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1467 - }
1468 - wp_die( wp_json_encode( array( 'error' => $error ) ) );
1469 - }
1470 -
1471 - /**
1472 1654 * Method ajax_import_demo_data().
1473 1655 */
1474 1656 public function ajax_import_demo_data() {
1475 1657 $this->secure_request( 'mainwp_import_demo_data' );
@@ -1766,8 +1948,97 @@
1766 1948 delete_option( 'mainwp_not_start_encrypt_keys' );
1767 1949 wp_die( wp_json_encode( array( 'success' => 1 ) ) );
1768 1950 }
1769 1951
1952 + /**
1953 + * Method ajax_ui_mode_detected
1954 + */
1955 + public function ajax_ui_mode_detected() {
1956 + $this->check_security( 'mainwp_qsw_ui_mode_detected' );
1957 +
1958 + $detected_ui = isset( $_POST['ui_mode'] ) ? sanitize_text_field( wp_unslash( $_POST['ui_mode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1959 +
1960 + $current_user_theme = get_user_option( 'mainwp_selected_theme' );
1961 + if ( empty( $current_user_theme ) ) {
1962 + if ( 'dark' === $detected_ui ) {
1963 + MainWP_Utility::update_user_option( 'mainwp_selected_theme', 'default-dark' );
1964 + } else {
1965 + MainWP_Utility::update_user_option( 'mainwp_selected_theme', 'default' );
1966 + }
1967 + }
1968 +
1969 + wp_die( wp_json_encode( array( 'success' => 1 ) ) );
1970 + }
1971 +
1972 +
1973 +
1974 + /**
1975 + * Handle ajax get changes logs for plugins/themes.
1976 + */
1977 + public function ajax_get_item_changes_logs() { //phpcs:ignore -- NOSONAR -complex.
1978 + $this->check_security( 'mainwp_changes_logs_get_item_changes' );
1979 +
1980 + $siteId = isset( $_POST['siteId'] ) ? intval( $_POST['siteId'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1981 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1982 + $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1983 + $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( urldecode( $_POST['name'] ) ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1984 +
1985 + if ( 'plugin' === $type && ! empty( $slug ) ) {
1986 + if ( false !== strpos( $slug, '/' ) ) {
1987 + $parts = explode( '/', $slug );
1988 + $slug = $parts[0];
1989 + } else {
1990 + $slug = basename( $slug, '.php' );
1991 + }
1992 + } elseif ( 'theme' === $type && ! empty( $slug ) ) {
1993 + $slug = strtolower( $slug );
1994 + }
1995 +
1996 + // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1997 + $target_dt = ! empty( $_POST['target_date'] ) ? sanitize_text_field( wp_unslash( $_POST['target_date'] ) ) : '';
1998 +
1999 + if ( ! in_array( $type, array( 'plugin', 'theme' ) ) || ( empty( $target_dt ) && ( empty( $siteId ) || ( empty( $slug ) && empty( $name ) ) ) ) ) {
2000 + wp_send_json( array( 'error' => esc_html__( 'Invalid request data. Please try again.', 'mainwp' ) ) );
2001 + }
2002 +
2003 + // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2004 + $from_date = isset( $_POST['from_date'] ) ? sanitize_text_field( wp_unslash( $_POST['from_date'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2005 +
2006 + $results = Log_Changes_Logs_Helper::instance()->get_history_changes(
2007 + array(
2008 + 'wpid' => $siteId,
2009 + 'from_date' => $from_date,
2010 + 'days_number' => 10,
2011 + 'slug' => $slug,
2012 + 'type' => $type,
2013 + 'name' => $name,
2014 + 'target_date' => $target_dt,
2015 + )
2016 + );
2017 +
2018 + if ( ! is_array( $results ) ) {
2019 + $results = array();
2020 + }
2021 +
2022 + wp_send_json( $results );
2023 + }
2024 +
2025 + /**
2026 + * Handle self_connect action.
2027 + */
2028 + public function ajax_self_connect() {
2029 +
2030 + $mainwp_run = isset( $_POST['mainwp_run'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_run'] ) ) : ''; // phpcs:ignore -- NOSONAR -ok.
2031 +
2032 + if ( 'self_connect' !== $mainwp_run ) {
2033 + status_header( 400 );
2034 + exit;
2035 + }
2036 +
2037 + MainWP_System_Utility::instance()->handle_self_connect();
2038 +
2039 + exit;
2040 + }
1770 2041
1771 2042
1772 2043 /**
1773 2044 * Method mainwp_get_sanitized_post()