PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.1.8
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.1.8
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
mainwp / class / class-mainwp-post-handler.php

class-mainwp-post-handler.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 6.1.8, at class/class-mainwp-post-handler.php

2,123 lines 88.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Post Handler.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
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
18 // phpcs:disable Generic.Metrics.CyclomaticComplexity -- complexity.
19
20 /**
21 * Class MainWP_Post_Handler
22 *
23 * @package MainWP\Dashboard
24 *
25 * @uses \MainWP\Dashboard\MainWP_Post_Base_Handler
26 */
27 class MainWP_Post_Handler extends MainWP_Post_Base_Handler { // phpcs:ignore -- NOSONAR - Complex.
28
29 /**
30 * Private static variable to hold the single instance of the class.
31 *
32 * @static
33 *
34 * @var mixed Default null
35 */
36 private static $instance = null;
37
38 /**
39 * Method instance()
40 *
41 * Create a public static instance.
42 *
43 * @static
44 * @return MainWP_Post_Handler
45 */
46 public static function instance() {
47 if ( null === static::$instance ) {
48 static::$instance = new self();
49 }
50 return static::$instance;
51 }
52
53 /**
54 * Initiate all actions.
55 *
56 * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_class_name()
57 */
58 public function init() {
59 // Page: ManageSites.
60 $this->add_action( 'mainwp_notes_save', array( &$this, 'mainwp_notes_save' ) );
61
62 // Page: BulkAddUser.
63 $this->add_action( 'mainwp_bulkadduser', array( &$this, 'mainwp_bulkadduser' ) );
64 $this->add_action( 'mainwp_importuser', array( &$this, 'mainwp_importuser' ) );
65
66 // Widget: RightNow.
67 $this->add_action( 'mainwp_syncerrors_dismiss', array( &$this, 'mainwp_syncerrors_dismiss' ) );
68
69 if ( \mainwp_current_user_can( 'dashboard', 'manage_security_issues' ) ) {
70 // Page: SecurityIssues.
71 $this->add_action( 'mainwp_security_issues_request', array( &$this, 'mainwp_security_issues_request' ) );
72 $this->add_action( 'mainwp_security_issues_fix', array( &$this, 'mainwp_security_issues_fix' ) );
73 $this->add_action( 'mainwp_security_issues_unfix', array( &$this, 'mainwp_security_issues_unfix' ) );
74 }
75
76 $this->add_action( 'mainwp_notice_status_update', array( &$this, 'mainwp_notice_status_update' ) );
77 $this->add_action( 'mainwp_dismiss_activate_notice', array( &$this, 'dismiss_activate_notice' ) );
78 $this->add_action( 'mainwp_status_saving', array( &$this, 'mainwp_status_saving' ) );
79 $this->add_action( 'mainwp_leftmenu_filter_group', array( &$this, 'mainwp_leftmenu_filter_group' ) );
80 $this->add_action( 'mainwp_widgets_order', array( &$this, 'ajax_widgets_order' ) );
81 $this->add_action( 'mainwp_save_settings', array( &$this, 'ajax_mainwp_save_settings' ) );
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' ) );
85
86 // Page: Recent Posts.
87 if ( \mainwp_current_user_can( 'dashboard', 'manage_posts' ) ) {
88 $this->add_action( 'mainwp_post_unpublish', array( &$this, 'mainwp_post_unpublish' ) );
89 $this->add_action( 'mainwp_post_publish', array( &$this, 'mainwp_post_publish' ) );
90 $this->add_action( 'mainwp_post_trash', array( &$this, 'mainwp_post_trash' ) );
91 $this->add_action( 'mainwp_post_delete', array( &$this, 'mainwp_post_delete' ) );
92 $this->add_action( 'mainwp_post_restore', array( &$this, 'mainwp_post_restore' ) );
93 $this->add_action( 'mainwp_post_approve', array( &$this, 'mainwp_post_approve' ) );
94 }
95 $this->add_action( 'mainwp_post_addmeta', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_add_meta' ) );
96 // Page: Pages.
97 if ( \mainwp_current_user_can( 'dashboard', 'manage_pages' ) ) {
98 $this->add_action( 'mainwp_page_unpublish', array( &$this, 'mainwp_page_unpublish' ) );
99 $this->add_action( 'mainwp_page_publish', array( &$this, 'mainwp_page_publish' ) );
100 $this->add_action( 'mainwp_page_trash', array( &$this, 'mainwp_page_trash' ) );
101 $this->add_action( 'mainwp_page_delete', array( &$this, 'mainwp_page_delete' ) );
102 $this->add_action( 'mainwp_page_restore', array( &$this, 'mainwp_page_restore' ) );
103 }
104 // Page: Users.
105 $this->add_action( 'mainwp_user_delete', array( &$this, 'mainwp_user_delete' ) );
106 $this->add_action( 'mainwp_user_edit', array( &$this, 'mainwp_user_edit' ) );
107 $this->add_action( 'mainwp_user_update_password', array( &$this, 'mainwp_user_update_password' ) );
108 $this->add_action( 'mainwp_user_update_user', array( &$this, 'mainwp_user_update_user' ) );
109
110 // Page: Posts.
111 $this->add_action( 'mainwp_posts_search', array( &$this, 'mainwp_posts_search' ) );
112 $this->add_action( 'mainwp_get_categories', array( &$this, 'mainwp_get_categories' ) );
113 $this->add_action( 'mainwp_post_get_edit', array( &$this, 'mainwp_post_get_edit' ) );
114 $this->add_action( 'mainwp_post_postingbulk', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_posting_posts' ) );
115 $this->add_action( 'mainwp_get_sites_of_groups', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_get_sites_of_groups' ) );
116
117 // Page: Pages.
118 $this->add_action( 'mainwp_pages_search', array( &$this, 'mainwp_pages_search' ) );
119 // Page: User.
120 $this->add_action( 'mainwp_users_search', array( &$this, 'mainwp_users_search' ) );
121
122 $this->add_action( 'mainwp_events_notice_hide', array( &$this, 'mainwp_events_notice_hide' ) );
123 $this->add_action( 'mainwp_showhide_sections', array( &$this, 'mainwp_showhide_sections' ) );
124 $this->add_action( 'mainwp_saving_status', array( &$this, 'mainwp_saving_status' ) );
125 $this->add_action( 'mainwp_autoupdate_and_trust_child', array( &$this, 'mainwp_autoupdate_and_trust_child' ) );
126 $this->add_action( 'mainwp_installation_warning_hide', array( &$this, 'mainwp_installation_warning_hide' ) );
127 $this->add_action( 'mainwp_force_destroy_sessions', array( &$this, 'mainwp_force_destroy_sessions' ) );
128 $this->add_action( 'mainwp_recheck_http', array( &$this, 'ajax_recheck_http' ) );
129 $this->add_action( 'mainwp_ignore_http_response', array( &$this, 'mainwp_ignore_http_response' ) );
130 $this->add_action( 'mainwp_disconnect_site', array( &$this, 'ajax_disconnect_site' ) );
131 $this->add_action( 'mainwp_manage_sites_display_rows', array( &$this, 'ajax_sites_display_rows' ) );
132 $this->add_action( 'mainwp_monitoring_sites_display_rows', array( &$this, 'ajax_monitoring_display_rows' ) );
133
134 $this->add_action_nonce( 'mainwp-common-nonce' );
135
136 // Page: Clients.
137 $this->add_action( 'mainwp_clients_add_client', array( &$this, 'mainwp_clients_add_client' ) );
138 $this->add_action( 'mainwp_clients_delete_client', array( &$this, 'mainwp_clients_delete_client' ) );
139
140 $this->add_action( 'mainwp_clients_save_field', array( &$this, 'mainwp_clients_save_field' ) );
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' ) );
143 $this->add_action( 'mainwp_clients_delete_field', array( &$this, 'mainwp_clients_delete_field' ) );
144 $this->add_action( 'mainwp_clients_notes_save', array( &$this, 'mainwp_clients_notes_save' ) );
145 $this->add_action( 'mainwp_clients_suspend_client', array( &$this, 'mainwp_clients_suspend_client' ) );
146 $this->add_action( 'mainwp_refresh_icon', array( &$this, 'ajax_refresh_icon' ) );
147 $this->add_action( 'mainwp_upload_custom_icon', array( &$this, 'ajax_upload_custom_icon' ) );
148 $this->add_action( 'mainwp_select_custom_theme', array( &$this, 'ajax_select_custom_theme' ) );
149 $this->add_action( 'mainwp_import_demo_data', array( &$this, 'ajax_import_demo_data' ) );
150 $this->add_action( 'mainwp_delete_demo_data', array( &$this, 'ajax_delete_demo_data' ) );
151 $this->add_action( 'mainwp_prepare_renew_connections', array( MainWP_Connect_Helper::instance(), 'ajax_prepare_renew_connections' ) );
152 $this->add_action( 'mainwp_renew_connections', array( MainWP_Connect_Helper::instance(), 'ajax_renew_connections' ) );
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
157 // Page: managesites.
158 $this->add_action( 'mainwp_save_temp_import_website', array( &$this, 'ajax_save_temp_import_website' ) );
159 $this->add_action( 'mainwp_delete_temp_import_website', array( &$this, 'ajax_delete_temp_import_website' ) );
160 $this->add_action( 'mainwp_import_website_add_client', array( &$this, 'ajax_import_website_add_client' ) );
161 $this->add_action( 'mainwp_import_website_add_client_no_site', array( &$this, 'ajax_import_website_add_client_no_site' ) );
162
163 // Page:: mainwp-setup.
164 $this->add_action( 'mainwp_clients_add_multi_client', array( &$this, 'ajax_clients_add_multi_client' ) );
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' ) );
169 }
170
171 /**
172 * Method add_post_action()
173 *
174 * Add ajax action.
175 *
176 * @param string $action Action to perform.
177 * @param string $callback Callback to perform.
178 */
179 public function add_post_action( $action, $callback ) {
180 $this->add_action( $action, $callback );
181 }
182
183 /**
184 * Method mainwp_installation_warning_hide()
185 *
186 * Hide the installation warning.
187 */
188 public function mainwp_installation_warning_hide() {
189 $this->secure_request( 'mainwp_installation_warning_hide' );
190
191 update_option( 'mainwp_installation_warning_hide_the_notice', 'yes' );
192 die( 'ok' );
193 }
194
195 /**
196 * Method mainwp_users_search()
197 *
198 * Search Post handler,
199 * Page: User.
200 *
201 * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
202 * @uses \MainWP\Dashboard\MainWP_User::render_table()
203 */
204 public function mainwp_users_search() {
205 $this->secure_request( 'mainwp_users_search' );
206 MainWP_Cache::init_session();
207
208 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
209 $role = isset( $_POST['urole'] ) ? sanitize_text_field( wp_unslash( $_POST['urole'] ) ) : '';
210 $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
211 $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
212 $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
213 $search = isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '';
214 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
215 MainWP_User::render_table( false, $role, $groups, $sites, $search, $clients );
216 session_write_close();
217 die();
218 }
219
220 /**
221 * Method mainwp_posts_search()
222 *
223 * Search Post handler,
224 * Page: Posts.
225 *
226 * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
227 * @uses \MainWP\Dashboard\MainWP_Post::render_table()
228 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
229 */
230 public function mainwp_posts_search() { // phpcs:ignore -- NOSONAR - complex.
231 $this->secure_request( 'mainwp_posts_search' );
232 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
233 $post_type = ( isset( $_POST['post_type'] ) && 0 < strlen( sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) ) ? sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) : 'post' );
234 if ( isset( $_POST['maximum'] ) ) {
235 MainWP_Utility::update_option( 'mainwp_maximumPosts', isset( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 );
236 }
237 $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
238 $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( trim( wp_unslash( $_POST['dtsstart'] ) ) ) : '';
239 $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( trim( wp_unslash( $_POST['dtsstop'] ) ) ) : '';
240 $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
241 $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
242 $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
243 $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
244 $postId = isset( $_POST['postId'] ) ? sanitize_text_field( wp_unslash( $_POST['postId'] ) ) : '';
245 $userId = isset( $_POST['userId'] ) ? sanitize_text_field( wp_unslash( $_POST['userId'] ) ) : '';
246 $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
247 $table_content_only = isset( $_POST['table_content'] ) && wp_unslash( $_POST['table_content'] ) ? true : false;
248 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
249
250 MainWP_Cache::init_session();
251 if ( $table_content_only ) {
252 MainWP_Post::render_table_body( $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId, $post_type, $search_on, true, $clients );
253 } else {
254 $params = array(
255 'groups' => $groups,
256 'sites' => $sites,
257 'postId' => $postId,
258 'userId' => $userId,
259 'post_type' => $post_type,
260 'search_on' => $search_on,
261 'clients' => $clients,
262 );
263 MainWP_Post::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $params );
264 }
265 die();
266 }
267 /**
268 * Method mainwp_pages_search()
269 *
270 * Search Post handler,
271 * Page: Pages.
272 *
273 * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
274 * @uses \MainWP\Dashboard\MainWP_Page::render_table()
275 *
276 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
277 */
278 public function mainwp_pages_search() {
279 $this->secure_request( 'mainwp_pages_search' );
280 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
281 if ( isset( $_POST['maximum'] ) ) {
282 MainWP_Utility::update_option( 'mainwp_maximumPages', intval( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 );
283 }
284 $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
285 $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) : '';
286 $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) : '';
287 $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
288 $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
289 $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
290 $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
291 $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
292 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
293 MainWP_Cache::init_session();
294
295 $params = array(
296 'groups' => $groups,
297 'sites' => $sites,
298 'search_on' => $search_on,
299 'clients' => $clients,
300 );
301
302 MainWP_Page::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $params );
303 die();
304 }
305
306 /**
307 * Method mainwp_get_categories()
308 *
309 * Get post/page categories.
310 *
311 * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_categories()
312 */
313 public function mainwp_get_categories() {
314 $this->secure_request( 'mainwp_get_categories' );
315 MainWP_Post_Page_Handler::ajax_handle_get_categories();
316 die();
317 }
318
319 /**
320 * Method mainwp_post_get_edit()
321 *
322 * Get post to edit.
323 *
324 * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_post()
325 */
326 public function mainwp_post_get_edit() {
327 $this->secure_request( 'mainwp_post_get_edit' );
328 MainWP_Post_Page_Handler::get_post();
329 die();
330 }
331
332 /**
333 * Method mainwp_user_delete()
334 *
335 * Delete User from Child Site,
336 * Page: Users.
337 *
338 * @uses \MainWP\Dashboard\MainWP_User::delete()
339 */
340 public function mainwp_user_delete() {
341 $this->secure_request( 'mainwp_user_delete' );
342 MainWP_User::delete();
343 }
344
345 /**
346 * Method mainwp_user_edit()
347 *
348 * Edit User from Child Site,
349 * Page: Users.
350 *
351 * @uses \MainWP\Dashboard\MainWP_User::edit()
352 */
353 public function mainwp_user_edit() {
354 $this->secure_request( 'mainwp_user_edit' );
355 MainWP_User::edit();
356 }
357
358 /**
359 * Method mainwp_user_update_password(
360 *
361 * Update User password from Child Site,
362 * Page: Users.
363 *
364 * @uses \MainWP\Dashboard\MainWP_User::update_password()
365 */
366 public function mainwp_user_update_password() {
367 $this->secure_request( 'mainwp_user_update_password' );
368 MainWP_User::update_password();
369 }
370
371 /**
372 * Method mainwp_user_update_user()
373 *
374 * Update User from Child Site,
375 * Page: Users.
376 *
377 * @uses \MainWP\Dashboard\MainWP_User::update_user()
378 */
379 public function mainwp_user_update_user() {
380 $this->secure_request( 'mainwp_user_update_user' );
381 MainWP_User::update_user();
382 }
383
384 /**
385 * Method mainwp_post_unpublish()
386 *
387 * Unpublish post from Child Site,
388 * Page: Recent Posts.
389 *
390 * @uses \MainWP\Dashboard\MainWP_Recent_Posts::unpublish()
391 */
392 public function mainwp_post_unpublish() {
393 $this->secure_request( 'mainwp_post_unpublish' );
394 MainWP_Recent_Posts::unpublish();
395 }
396
397 /**
398 * Method mainwp_post_publish()
399 *
400 * Publish post on Child Site,
401 * Page: Recent Posts.
402 *
403 * @uses \MainWP\Dashboard\MainWP_Recent_Posts::publish()
404 */
405 public function mainwp_post_publish() {
406 $this->secure_request( 'mainwp_post_publish' );
407 MainWP_Recent_Posts::publish();
408 }
409
410 /**
411 * Method mainwp_post_approve()
412 *
413 * Approve post on Child Site,
414 * Page: Recent Posts.
415 *
416 * @uses \MainWP\Dashboard\MainWP_Recent_Posts::approve()
417 */
418 public function mainwp_post_approve() {
419 $this->secure_request( 'mainwp_post_approve' );
420 MainWP_Recent_Posts::approve();
421 }
422
423 /**
424 * Method mainwp_post_trash()
425 *
426 * Trash post on Child Site,
427 * Page: Recent Posts.
428 *
429 * @uses \MainWP\Dashboard\MainWP_Recent_Posts::trash()
430 */
431 public function mainwp_post_trash() {
432 $this->secure_request( 'mainwp_post_trash' );
433
434 MainWP_Recent_Posts::trash();
435 }
436
437 /**
438 * Method mainwp_post_delete()
439 *
440 * Delete post on Child Site,
441 * Page: Recent Posts.
442 *
443 * @uses \MainWP\Dashboard\MainWP_Recent_Posts::delete()
444 */
445 public function mainwp_post_delete() {
446 $this->secure_request( 'mainwp_post_delete' );
447
448 MainWP_Recent_Posts::delete();
449 }
450
451 /**
452 * Method mainwp_post_restore()
453 *
454 * Restore post,
455 * Page: Recent Posts.
456 *
457 * @uses \MainWP\Dashboard\MainWP_Recent_Posts::restore()
458 */
459 public function mainwp_post_restore() {
460 $this->secure_request( 'mainwp_post_restore' );
461
462 MainWP_Recent_Posts::restore();
463 }
464
465 /**
466 * Method mainwp_page_unpublish()
467 *
468 * Unpublish page,
469 * Page: Recent Pages.
470 *
471 * @uses \MainWP\Dashboard\MainWP_Page::unpublish()
472 */
473 public function mainwp_page_unpublish() {
474 $this->secure_request( 'mainwp_page_unpublish' );
475 MainWP_Page::unpublish();
476 }
477
478 /**
479 * Method mainwp_page_publish()
480 *
481 * Publish page,
482 * Page: Recent Pages.
483 *
484 * @uses \MainWP\Dashboard\MainWP_Page::publish()
485 */
486 public function mainwp_page_publish() {
487 $this->secure_request( 'mainwp_page_publish' );
488 MainWP_Page::publish();
489 }
490
491 /**
492 * Method mainwp_page_trash()
493 *
494 * Trash page,
495 * Page: Recent Pages.
496 *
497 * @uses \MainWP\Dashboard\MainWP_Page::trash()
498 */
499 public function mainwp_page_trash() {
500 $this->secure_request( 'mainwp_page_trash' );
501 MainWP_Page::trash();
502 }
503
504 /**
505 * Method mainwp_page_delete()
506 *
507 * Delete page,
508 * Page: Recent Pages.
509 *
510 * @uses \MainWP\Dashboard\MainWP_Page::delete()
511 */
512 public function mainwp_page_delete() {
513 $this->secure_request( 'mainwp_page_delete' );
514 MainWP_Page::delete();
515 }
516
517 /**
518 * Method mainwp_page_restor()
519 *
520 * Restore page,
521 * Page: Recent Pages.
522 *
523 * @uses \MainWP\Dashboard\MainWP_Page::restore()
524 */
525 public function mainwp_page_restore() {
526 $this->secure_request( 'mainwp_page_restore' );
527 MainWP_Page::restore();
528 }
529
530 /**
531 * Method mainwp_notice_status_update()
532 *
533 * Hide after installation notices,
534 * (PHP version, Trust MainWP Child, Multisite Warning and OpenSSL warning).
535 *
536 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
537 */
538 public function mainwp_notice_status_update() {
539 $this->secure_request( 'mainwp_notice_status_update' );
540
541 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
542 $no_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : false;
543 if ( 'mail_failed' === $no_id ) {
544 MainWP_Utility::update_option( 'mainwp_notice_wp_mail_failed', 'hide' );
545 die( 'ok' );
546 }
547
548 if ( 'phpver_8_0' === $no_id ) {
549 MainWP_Utility::update_user_option( 'lasttime_hidden_phpver_8_0', time() );
550 }
551
552 $time_set = isset( $_POST['time_set'] ) && 1 === intval( $_POST['time_set'] ) ? true : false;
553 $this->hide_dashboard_notice_status( $no_id, $time_set );
554 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
555 die( 1 );
556 }
557
558 /**
559 * Method hide dashboard notice status.
560 *
561 * @param mixed $no_id notice id.
562 * @param mixed $time_set time.
563 * @param bool $hide_noti hide notice.
564 * @return void
565 */
566 public function hide_dashboard_notice_status( $no_id, $time_set = false, $hide_noti = true ) { //phpcs:ignore -- NOSONAR - complexity.
567 /**
568 * Current user global.
569 *
570 * @global string
571 */
572 global $current_user;
573 $user_id = $current_user->ID;
574 if ( $user_id ) {
575 $status = get_user_option( 'mainwp_notice_saved_status' );
576 if ( ! is_array( $status ) ) {
577 $status = array();
578 }
579 if ( ! empty( $no_id ) ) {
580 if ( 'mainwp_secure_priv_key_notice' === $no_id ) {
581 MainWP_Utility::update_option( 'mainwp_not_start_encrypt_keys', 1 ); // to show the button.
582 }
583 if ( $hide_noti ) {
584 if ( $time_set ) {
585 $status[ $no_id ] = time();
586 } else {
587 $status[ $no_id ] = 1;
588 }
589 } elseif ( ! empty( $status[ $no_id ] ) ) {
590 unset( $status[ $no_id ] );
591 }
592 update_user_option( $user_id, 'mainwp_notice_saved_status', $status );
593 }
594 }
595 }
596
597 /**
598 * Method mainwp_status_saving()
599 *
600 * Save last_sync_sites time().
601 */
602 public function mainwp_status_saving() { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR - complexity.
603 $this->secure_request( 'mainwp_status_saving' );
604 $values = get_option( 'mainwp_status_saved_values' );
605
606 if ( ! is_array( $values ) ) {
607 $values = array();
608 }
609
610 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
611 if ( ! isset( $_POST['status'] ) ) {
612 die( -1 );
613 }
614
615 if ( 'last_sync_sites' === $_POST['status'] ) {
616 if ( isset( $_POST['isGlobalSync'] ) && ! empty( $_POST['isGlobalSync'] ) ) {
617 update_option( 'mainwp_last_synced_all_sites', time() );
618
619 /**
620 * Action: mainwp_synced_all_sites
621 *
622 * Fires upon successfull synchronization process.
623 *
624 * @since 3.5.1
625 */
626 do_action( 'mainwp_synced_all_sites' );
627 }
628 die( 'ok' );
629 }
630
631 $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
632 $value = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
633 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
634
635 if ( ! empty( $status ) ) {
636 if ( empty( $value ) ) {
637 if ( isset( $values[ $status ] ) ) {
638 unset( $values[ $status ] );
639 }
640 } else {
641 $values[ $status ] = $value;
642 }
643 update_option( 'mainwp_status_saved_values', $values );
644 }
645
646 die( 'ok' );
647 }
648
649 /**
650 * Method ajax_widget_order()
651 *
652 * Update saved widget order.
653 */
654 public function ajax_widgets_order() { //phpcs:ignore -- NOSONAR - complex.
655
656 $this->secure_request( 'mainwp_widgets_order' );
657 $user = wp_get_current_user();
658 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
659 if ( $user && ! empty( $_POST['page'] ) ) {
660 $page = isset( $_POST['page'] ) ? sanitize_text_field( wp_unslash( $_POST['page'] ) ) : '';
661 $order = isset( $_POST['order'] ) ? sanitize_text_field( wp_unslash( $_POST['order'] ) ) : '';
662 $wgids = isset( $_POST['wgids'] ) ? sanitize_text_field( wp_unslash( $_POST['wgids'] ) ) : '';
663 $page_widget = isset( $_POST['page_widget'] ) ? sanitize_text_field( wp_unslash( $_POST['page_widget'] ) ) : '';
664
665 $wgs_orders = array();
666
667 if ( ! empty( $wgids ) ) {
668 $wgids = json_decode( $wgids, true );
669 $order = json_decode( $order, true );
670 if ( is_array( $wgids ) && is_array( $order ) ) {
671 foreach ( $wgids as $idx => $wgid ) {
672 if ( isset( $order[ $idx ] ) ) {
673 $pre = 'widget-'; // #compatible-widgetid.
674 if ( 0 === strpos( $wgid, $pre ) ) {
675 $wgid = substr( $wgid, strlen( $pre ) );
676 }
677 $wgs_orders[ $wgid ] = $order[ $idx ];
678 }
679 }
680 }
681 }
682
683 if ( 'mainwp_page_manageclients' === $page ) {
684 $item_id = isset( $_POST['item_id'] ) ? intval( $_POST['item_id'] ) : 0;
685 $sorted_array = get_user_option( 'mainwp_widgets_sorted_' . strtolower( $page ) );
686 if ( ! empty( $sorted_array ) ) {
687 $sorted_array = json_decode( $sorted_array, true );
688 }
689 if ( ! is_array( $sorted_array ) ) {
690 $sorted_array = array();
691 }
692 $sorted_array[ $item_id ] = $wgs_orders;
693 update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $sorted_array ), true );
694 } else {
695 update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $wgs_orders ), true );
696 }
697 MainWP_Cache_Warm_Helper::invalidate_manage_pages( array( $page_widget ) );
698 die( 'ok' );
699 }
700 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
701 die( -1 );
702 }
703
704 /**
705 * Method ajax_mainwp_save_settings()
706 *
707 * Update saved MainWP Settings.
708 *
709 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
710 */
711 public function ajax_mainwp_save_settings() {
712 $this->secure_request( 'mainwp_save_settings' );
713 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
714 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
715 if ( ! empty( $name ) ) {
716 $option_name = 'mainwp_' . $name;
717 $val = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
718 MainWP_Utility::update_option( $option_name, $val );
719 }
720 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
721 die( 'ok' );
722 }
723
724 /**
725 * Method ajax_guided_tours_option_update()
726 *
727 * Update saved MainWP Settings.
728 *
729 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
730 */
731 public function ajax_guided_tours_option_update() {
732 $this->secure_request( 'mainwp_guided_tours_option_update' );
733 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
734 $enable = isset( $_POST['enable'] ) ? intval( $_POST['enable'] ) : 0;
735 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
736 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', $enable );
737 die( 'ok ' . intval( $enable ) );
738 }
739
740 /**
741 * Method mainwp_help_modal_content_update()
742 *
743 * Update saved MainWP Settings.
744 *
745 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
746 */
747 public function ajax_mainwp_help_modal_content_update() {
748 $this->secure_request( 'mainwp_help_modal_content_update' );
749 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', ( int)$_POST['enable_tour'] ); //phpcs:ignore -- NOSONAR verify.
750 MainWP_Utility::update_option( 'mainwp_enable_guided_video', (int)$_POST['enable_video'] ); //phpcs:ignore -- NOSONAR verify.
751 MainWP_Utility::update_option( 'mainwp_enable_guided_chatbase', (int)$_POST['enable_chatbase'] ); //phpcs:ignore -- NOSONAR verify.
752 die( 'ok' );
753 }
754
755 /**
756 * Method mainwp_leftmenu_filter_group()
757 *
758 * MainWP left menu filter by group.
759 *
760 * @uses \MainWP\Dashboard\MainWP_DB::query()
761 * @uses \MainWP\Dashboard\MainWP_DB::get_websites_by_group_id()
762 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
763 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
764 */
765 public function mainwp_leftmenu_filter_group() {
766 $this->secure_request( 'mainwp_leftmenu_filter_group' );
767
768 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
769 $gid = isset( $_POST['group_id'] ) ? intval( $_POST['group_id'] ) : false;
770 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
771
772 if ( ! empty( $gid ) ) {
773 $ids = '';
774 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $gid, true ) );
775 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
776 $ids .= $website->id . ',';
777 }
778 MainWP_DB::free_result( $websites );
779 $ids = rtrim( $ids, ',' );
780 die( $ids ); // phpcs:ignore WordPress.Security.EscapeOutput
781 }
782 die( '' );
783 }
784
785 /**
786 * Method dismiss_activate_notice()
787 *
788 * Dismiss activate notice.
789 */
790 public function dismiss_activate_notice() {
791 $this->secure_request( 'mainwp_dismiss_activate_notice' );
792
793 /**
794 * Current user global.
795 *
796 * @global string
797 */
798 global $current_user;
799 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
800 $user_id = $current_user->ID;
801 $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
802 if ( $user_id && ! empty( $slug ) ) {
803 $activate_notices = get_user_option( 'mainwp_hide_activate_notices' );
804 if ( ! is_array( $activate_notices ) ) {
805 $activate_notices = array();
806 }
807
808 $activate_notices[ $slug ] = time();
809 update_user_option( $user_id, 'mainwp_hide_activate_notices', $activate_notices );
810 }
811 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
812 die( 1 );
813 }
814
815
816
817 /**
818 * Method mainwp_security_issues_request()
819 *
820 * Post handler for,
821 * Page: SecurityIssues.
822 *
823 * @uses \MainWP\Dashboard\MainWP_Exception
824 * @uses \MainWP\Dashboard\MainWP_Security_Issues::fetch_security_issues()
825 */
826 public function mainwp_security_issues_request() {
827 $this->secure_request( 'mainwp_security_issues_request' );
828
829 try {
830 wp_send_json( array( 'result' => MainWP_Security_Issues::fetch_security_issues() ) );
831 } catch ( MainWP_Exception $e ) {
832 die(
833 wp_json_encode(
834 array(
835 'error' => array(
836 'message' => $e->getMessage(),
837 'extra' => $e->get_message_extra(),
838 ),
839 )
840 )
841 );
842 }
843 }
844
845 /**
846 * Method mainwp_security_issues_fix()
847 *
848 * Post handler for 'fix issues',
849 * Page: SecurityIssues.
850 *
851 * @uses \MainWP\Dashboard\MainWP_Exception
852 * @uses \MainWP\Dashboard\MainWP_Security_Issues::fix_security_issue()
853 */
854 public function mainwp_security_issues_fix() {
855 $this->secure_request( 'mainwp_security_issues_fix' );
856
857 try {
858 wp_send_json( array( 'result' => MainWP_Security_Issues::fix_security_issue() ) );
859 } catch ( MainWP_Exception $e ) {
860 die(
861 wp_json_encode(
862 array(
863 'error' => array(
864 'message' => $e->getMessage(),
865 'extra' => $e->get_message_extra(),
866 ),
867 )
868 )
869 );
870 }
871 }
872
873 /**
874 * Method mainwp_security_issues_unfix()
875 *
876 * Post handler for 'unfix issues',
877 * Page: SecurityIssues.
878 *
879 * @uses \MainWP\Dashboard\MainWP_Exception
880 * @uses \MainWP\Dashboard\MainWP_Security_Issues::unfix_security_issue()
881 */
882 public function mainwp_security_issues_unfix() {
883 $this->secure_request( 'mainwp_security_issues_unfix' );
884
885 try {
886 wp_send_json( array( 'result' => MainWP_Security_Issues::unfix_security_issue() ) );
887 } catch ( MainWP_Exception $e ) {
888 die(
889 wp_json_encode(
890 array(
891 'error' => array(
892 'message' => $e->getMessage(),
893 'extra' => $e->get_message_extra(),
894 ),
895 )
896 )
897 );
898 }
899 }
900
901 /**
902 * Method ajax_disconnect_site()
903 *
904 * Disconnect Child Site.
905 *
906 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
907 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
908 */
909 public function ajax_disconnect_site() {
910 $this->secure_request( 'mainwp_disconnect_site' );
911 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
912 $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
913 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
914
915 if ( empty( $siteid ) ) {
916 die( wp_json_encode( array( 'error' => 'Error: site id empty' ) ) );
917 }
918
919 $website = MainWP_DB::instance()->get_website_by_id( $siteid );
920
921 if ( ! $website ) {
922 die( wp_json_encode( array( 'error' => 'Not found site' ) ) );
923 }
924
925 try {
926 $information = MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
927 } catch ( \Exception $e ) {
928 $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
929 }
930
931 wp_send_json( $information );
932 }
933
934 /**
935 * Method ajax_sites_display_rows()
936 *
937 * Display rows via ajax,
938 * Page: Manage Sites.
939 *
940 * @uses \MainWP\Dashboard\MainWP_Manage_Sites::ajax_optimize_display_rows()
941 */
942 public function ajax_sites_display_rows() {
943 $this->secure_request( 'mainwp_manage_sites_display_rows' );
944 MainWP_Manage_Sites::ajax_optimize_display_rows();
945 }
946
947 /**
948 * Method ajax_monitoring_display_rows()
949 *
950 * Display rows via ajax,
951 * Page: Monitoring Sites.
952 *
953 * @uses \MainWP\Dashboard\MainWP_Monitoring::ajax_optimize_display_rows()
954 */
955 public function ajax_monitoring_display_rows() {
956 $this->secure_request( 'mainwp_monitoring_sites_display_rows' );
957 MainWP_Monitoring::ajax_optimize_display_rows();
958 }
959
960
961 /**
962 * Method mainwp_bulkadduser()
963 *
964 * Bulk Add User for,
965 * Page: BulkAddUser.
966 *
967 * @uses \MainWP\Dashboard\MainWP_User::do_bulk_add()
968 */
969 public function mainwp_bulkadduser() {
970 $this->check_security( 'mainwp_bulkadduser' );
971 MainWP_User::do_bulk_add();
972 die();
973 }
974
975 /**
976 * Method mainwp_importuser()
977 *
978 * Import user.
979 *
980 * @uses \MainWP\Dashboard\MainWP_User::do_import()
981 */
982 public function mainwp_importuser() {
983 $this->secure_request( 'mainwp_importuser' );
984 MainWP_User::do_import();
985 }
986
987 /**
988 * Method mainwp_clients_add_client()
989 *
990 * Add Client for,
991 * Page: BulkAddClient.
992 */
993 public function mainwp_clients_add_client() {
994 $this->check_security( 'mainwp_clients_add_client' );
995 MainWP_Client::add_client();
996 die();
997 }
998
999 /**
1000 * Method mainwp_clients_delete_client()
1001 *
1002 * Add Client for,
1003 * Page: BulkAddClient.
1004 */
1005 public function mainwp_clients_delete_client() {
1006 $this->check_security( 'mainwp_clients_delete_client' );
1007 $ret = array( 'success' => false );
1008 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1009 $client_id = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
1010 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1011 if ( $client_id ) {
1012 MainWP_DB_Client::instance()->delete_client( $client_id );
1013 $ret['success'] = 'SUCCESS';
1014 $ret['result'] = esc_html__( 'Client removed successfully.', 'mainwp' );
1015 MainWP_Client::invalidate_warm_cache();
1016 } else {
1017 $ret['result'] = esc_html__( 'Client ID empty.', 'mainwp' );
1018 }
1019
1020 echo wp_json_encode( $ret );
1021 exit;
1022 }
1023
1024 /**
1025 * Method mainwp_clients_save_field()
1026 *
1027 * Save client custom fields.
1028 */
1029 public function mainwp_clients_save_field() {
1030 $this->check_security( 'mainwp_clients_save_field' );
1031 MainWP_Client::invalidate_warm_cache();
1032 MainWP_Client::save_client_field();
1033 die();
1034 }
1035
1036
1037 /**
1038 * Method mainwp_clients_delete_general_field()
1039 *
1040 * Delete client general fields.
1041 */
1042 public function mainwp_clients_delete_general_field() {
1043 $this->check_security( 'mainwp_clients_delete_general_field' );
1044 $ret = array( 'success' => false );
1045 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1046 $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
1047 $client_id = 0; // 0 general fields.
1048 if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
1049 $ret['success'] = true;
1050 }
1051 MainWP_Client::invalidate_warm_cache();
1052 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1053 echo wp_json_encode( $ret );
1054 exit;
1055 }
1056
1057 /**
1058 * Method mainwp_clients_bulk_delete_fields()
1059 *
1060 * Bulk delete client general fields.
1061 */
1062 public function mainwp_clients_bulk_delete_fields() {
1063 $this->check_security( 'mainwp_clients_bulk_delete_fields' );
1064 $ret = array( 'success' => false );
1065 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1066 $field_ids = isset( $_POST['field_ids'] ) && is_array( $_POST['field_ids'] ) ? array_map( 'intval', $_POST['field_ids'] ) : array();
1067 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1068
1069 if ( empty( $field_ids ) ) {
1070 $ret['data'] = array( 'message' => __( 'No fields selected.', 'mainwp' ) );
1071 echo wp_json_encode( $ret );
1072 exit;
1073 }
1074
1075 $client_id = 0; // 0 general fields.
1076 $deleted_count = 0;
1077 foreach ( $field_ids as $field_id ) {
1078 if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
1079 ++$deleted_count;
1080 }
1081 }
1082
1083 if ( $deleted_count > 0 ) {
1084 $ret['success'] = true;
1085 MainWP_Client::invalidate_warm_cache();
1086 } else {
1087 $ret['data'] = array( 'message' => __( 'Failed to delete fields.', 'mainwp' ) );
1088 }
1089
1090 echo wp_json_encode( $ret );
1091 exit;
1092 }
1093
1094 /**
1095 * Method mainwp_clients_delete_field()
1096 *
1097 * Delete client custom fields.
1098 */
1099 public function mainwp_clients_delete_field() {
1100 $this->check_security( 'mainwp_clients_delete_field' );
1101 $ret = array( 'success' => false );
1102 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1103 $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
1104 $client_id = isset( $_POST['client_id'] ) ? intval( $_POST['client_id'] ) : 0; // $client_id > 0, individual token.
1105 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1106 if ( $client_id && MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
1107 $ret['success'] = true;
1108 }
1109 echo wp_json_encode( $ret );
1110 exit;
1111 }
1112
1113 /**
1114 * Method mainwp_notes_save()
1115 *
1116 * Post handler for save notes on,
1117 * Page: Manage Sites.
1118 *
1119 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1120 */
1121 public function mainwp_notes_save() {
1122 $this->secure_request( 'mainwp_notes_save' );
1123 MainWP_Manage_Sites_Handler::save_note();
1124 }
1125
1126 /**
1127 * Method mainwp_clients_notes_save()
1128 *
1129 * Post handler for save notes on,
1130 * Page: Manage Sites.
1131 *
1132 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1133 */
1134 public function mainwp_clients_notes_save() {
1135 $this->secure_request( 'mainwp_clients_notes_save' );
1136 MainWP_Client::save_note();
1137 }
1138
1139 /**
1140 * Method mainwp_clients_suspend_client()
1141 *
1142 * Post handler for suspend client,
1143 * Page: Manage Sites.
1144 *
1145 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1146 */
1147 public function mainwp_clients_suspend_client() {
1148 $this->secure_request( 'mainwp_clients_suspend_client' );
1149 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1150 $clientid = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
1151 $suspended = isset( $_POST['suspend_status'] ) && ! empty( $_POST['suspend_status'] ) ? 1 : 0;
1152 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1153
1154 if ( empty( $clientid ) ) {
1155 wp_die( 'Error - empty client id!' );
1156 }
1157
1158 $params = array(
1159 'client_id' => $clientid,
1160 'suspended' => $suspended,
1161 );
1162
1163 MainWP_DB_Client::instance()->update_client( $params );
1164
1165 $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $clientid );
1166
1167 /**
1168 * Fires immediately after update client suspend/unsuspend.
1169 *
1170 * @since 4.5.1.1
1171 *
1172 * @param object $client client data.
1173 * @param bool $suspended true|false.
1174 */
1175 do_action( 'mainwp_client_suspend', $client, $suspended );
1176
1177 MainWP_DB_Client::instance()->suspend_unsuspend_websites_by_client_id( $clientid, $suspended );
1178
1179 wp_die( 'success' );
1180 }
1181
1182 /**
1183 * Method mainwp_clients_check_client()
1184 *
1185 * The client check has been created in the system yet.
1186 *
1187 * @uses \MainWP_DB_Client::instance()->get_wp_client_by()
1188 */
1189 public function mainwp_clients_check_client() {
1190 $this->secure_request( 'mainwp_clients_check_client' );
1191 // phpcs:disable WordPress.Security.NonceVerification
1192 $client_email = isset( $_POST['email'] ) ? sanitize_text_field( wp_unslash( $_POST['email'] ) ) : '';
1193 // phpcs:enable WordPress.Security.NonceVerification
1194 $client_existed = MainWP_DB_Client::instance()->get_wp_client_by( 'client_email', $client_email, ARRAY_A );
1195 if ( is_array( $client_existed ) && isset( $client_existed['client_id'] ) ) {
1196 return wp_send_json_error( array( 'error' => esc_html__( 'Client email exists. Please try again.', 'mainwp' ) ) );
1197 }
1198 return wp_send_json_success( array( 'result' => esc_html__( 'Client email not exists.', 'mainwp' ) ) );
1199 }
1200
1201 /**
1202 * Method mainwp_clients_import_client()
1203 *
1204 * Import new client
1205 *
1206 * @uses \MainWP_DB::instance()->get_websites_by_url()
1207 * @uses \MainWP_Client_Handler::get_default_client_fields()
1208 * @uses \MainWP_DB_Client::instance()->update_client()
1209 * @uses \MainWP_DB_Client::instance()->update_selected_sites_for_client()
1210 */
1211 public function mainwp_clients_import_client() { // phpcs:ignore -- NOSONAR
1212 $this->secure_request( 'mainwp_clients_import_client' );
1213 // phpcs:disable
1214 // Set value from POST data.
1215 $default_values = array(
1216 'client.name' => ! empty( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '',
1217 'client.email' => ! empty( $_POST['email'] ) ? sanitize_text_field( wp_unslash( $_POST['email'] ) ) : '',
1218 'client.contact.address.1' => ! empty( $_POST['address_1'] ) ? sanitize_text_field( wp_unslash( $_POST['address_1'] ) ) : '',
1219 'client.contact.address.2' => ! empty( $_POST['address_2'] ) ? sanitize_text_field( wp_unslash( $_POST['address_2'] ) ) : '',
1220 'client.city' => ! empty( $_POST['city'] ) ? sanitize_text_field( wp_unslash( $_POST['city'] ) ) : '',
1221 'client.state' => ! empty( $_POST['state'] ) ? sanitize_text_field( wp_unslash( $_POST['state'] ) ) : '',
1222 'client.zip' => ! empty( $_POST['zip'] ) ? sanitize_text_field( wp_unslash( $_POST['zip'] ) ) : '',
1223 'client.country' => ! empty( $_POST['country'] ) ? sanitize_text_field( wp_unslash( $_POST['country'] ) ) : '',
1224 'client.suspended' => ! empty( $_POST['suspended'] ) ? sanitize_text_field( wp_unslash( $_POST['suspended'] ) ) : 0,
1225 );
1226 // Get Site id.
1227 $selected_sites = array();
1228 if ( ! empty( $_POST['urls'] ) ) {
1229 $urls = array_map( 'sanitize_text_field', wp_unslash( $_POST['urls'] ) );
1230 $selected_sites = array_filter(
1231 array_map(
1232 function ( $v_url ) {
1233 $url = esc_url( $v_url );
1234 $website = MainWP_DB::instance()->get_websites_by_url( $url );
1235 return ! empty( $website ) ? current( $website )->id : null;
1236 },
1237 $urls
1238 )
1239 );
1240 }
1241 // phpcs:enable
1242 $client_to_add = array();
1243 $default_client_fields = MainWP_Client_Handler::get_default_client_fields(); // Get client field database.
1244 foreach ( $default_values as $key_client => $val_client ) {
1245 if ( isset( $default_client_fields[ $key_client ] ) && ! empty( $default_client_fields[ $key_client ]['db_field'] ) && ! empty( $val_client ) ) {
1246 $client_to_add[ $default_client_fields[ $key_client ]['db_field'] ] = $val_client; // Assign data to customers according to DB Field.
1247 }
1248 }
1249
1250 if ( ! empty( $client_to_add ) ) {
1251 // Set default values.
1252 $client_to_add['created'] = time();
1253 $client_to_add['primary_contact_id'] = 0;
1254 // Inset client.
1255 $inserted = MainWP_DB_Client::instance()->update_client( $client_to_add, true );
1256
1257 if ( ! empty( $inserted ) && is_object( $inserted ) ) {
1258 if ( ! empty( $selected_sites ) ) {
1259 MainWP_DB_Client::instance()->update_selected_sites_for_client( $inserted->client_id, $selected_sites ); // Set client to selected sites.
1260 }
1261 // Set default color and icon .
1262 $update = array(
1263 'client_id' => $inserted->client_id,
1264 'selected_icon_info' => 'selected:wordpress;color:#34424d',
1265 );
1266 MainWP_DB_Client::instance()->update_client( $update ); // Update Client.
1267
1268 return wp_send_json_success(
1269 array(
1270 'message' => esc_html__( 'successful client.', 'mainwp' ),
1271 'client' => $inserted,
1272 )
1273 );
1274 }
1275 return wp_send_json_error(
1276 array(
1277 'message' => esc_html__( 'unsuccessful client.', 'mainwp' ),
1278 )
1279 );
1280 }
1281 return wp_send_json_error(
1282 array(
1283 'message' => esc_html__( 'Error, please try again later.', 'mainwp' ),
1284 )
1285 );
1286 }
1287
1288 /**
1289 * Method mainwp_syncerrors_dismiss()
1290 *
1291 * Dismiss Sync errors for,
1292 * Widget: RightNow.
1293 *
1294 * @uses \MainWP\Dashboard\MainWP_Updates_Overview::dismiss_sync_errors()
1295 */
1296 public function mainwp_syncerrors_dismiss() {
1297
1298 $this->secure_request( 'mainwp_syncerrors_dismiss' );
1299
1300 try {
1301 die( wp_json_encode( array( 'result' => MainWP_Updates_Overview::dismiss_sync_errors() ) ) );
1302 } catch ( \Exception $e ) {
1303 die( wp_json_encode( array( 'error' => sanitize_text_field( $e->getMessage() ) ) ) );
1304 }
1305 }
1306
1307 /**
1308 * Method mainwp_events_notice_hide()
1309 *
1310 * Hide events notice.
1311 */
1312 public function mainwp_events_notice_hide() {
1313 $this->secure_request( 'mainwp_events_notice_hide' );
1314 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1315 if ( isset( $_POST['notice'] ) ) {
1316 $current_options = get_option( 'mainwp_showhide_events_notice' );
1317 if ( ! is_array( $current_options ) ) {
1318 $current_options = array();
1319 }
1320 if ( 'first_site' === $_POST['notice'] ) {
1321 update_option( 'mainwp_first_site_events_notice', '' );
1322 } elseif ( 'request_reviews1' === $_POST['notice'] ) {
1323 $current_options['request_reviews1'] = 15;
1324 $current_options['request_reviews1_starttime'] = time();
1325 } elseif ( 'request_reviews1_forever' === $_POST['notice'] || 'request_reviews2_forever' === $_POST['notice'] ) {
1326 $current_options['request_reviews1'] = 'forever';
1327 $current_options['request_reviews2'] = 'forever';
1328 } elseif ( 'request_reviews2' === $_POST['notice'] ) {
1329 $current_options['request_reviews2'] = 15;
1330 $current_options['request_reviews2_starttime'] = time();
1331 } elseif ( 'trust_child' === $_POST['notice'] ) {
1332 $current_options['trust_child'] = 1;
1333 } elseif ( 'multi_site' === $_POST['notice'] ) {
1334 $current_options['hide_multi_site_notice'] = 1;
1335 }
1336 update_option( 'mainwp_showhide_events_notice', $current_options );
1337 }
1338 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1339 die( 'ok' );
1340 }
1341
1342 /**
1343 * Method mainwp_showhide_sections()
1344 *
1345 * Show/Hide sections.
1346 */
1347 public function mainwp_showhide_sections() {
1348 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1349 if ( isset( $_POST['sec'] ) && isset( $_POST['status'] ) ) {
1350 $opts = get_option( 'mainwp_opts_showhide_sections' );
1351 if ( ! is_array( $opts ) ) {
1352 $opts = array();
1353 }
1354 $opts[ sanitize_text_field( wp_unslash( $_POST['sec'] ) ) ] = sanitize_text_field( wp_unslash( $_POST['status'] ) );
1355 update_option( 'mainwp_opts_showhide_sections', $opts );
1356 die( 'ok' );
1357 }
1358 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1359 die( 'failed' );
1360 }
1361
1362 /**
1363 * Method mainwp_saving_status()
1364 *
1365 * MainWP Saving Status.
1366 */
1367 public function mainwp_saving_status() {
1368 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1369 if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'mainwp_ajax' ) ) {
1370 die( esc_html__( 'WP nonce could not be verified. Please reload the page and try again.', 'mainwp' ) );
1371 }
1372 $saving_status = isset( $_POST['saving_status'] ) ? sanitize_text_field( wp_unslash( $_POST['saving_status'] ) ) : false;
1373 if ( ! empty( $saving_status ) ) {
1374 $current_options = get_option( 'mainwp_opts_saving_status' );
1375 if ( ! is_array( $current_options ) ) {
1376 $current_options = array();
1377 }
1378 if ( isset( $_POST['value'] ) ) {
1379 $current_options[ $saving_status ] = sanitize_text_field( wp_unslash( $_POST['value'] ) );
1380 }
1381 update_option( 'mainwp_opts_saving_status', $current_options );
1382 }
1383 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1384 die( 'ok' );
1385 }
1386
1387 /**
1388 * Method ajax_recheck_http()
1389 *
1390 * Recheck Child Site http status code & message.
1391 *
1392 * @uses \MainWP\Dashboard\MainWP_Connect::check_ignored_http_code()
1393 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1394 * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_check_website()
1395 */
1396 public function ajax_recheck_http() {
1397 $this->check_security( 'mainwp_recheck_http' );
1398 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1399 if ( ! isset( $_POST['websiteid'] ) || empty( $_POST['websiteid'] ) ) {
1400 die( -1 );
1401 }
1402
1403 $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['websiteid'] ) );
1404 if ( empty( $website ) ) {
1405 die( -1 );
1406 }
1407 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1408
1409 $result = MainWP_Monitoring_Handler::handle_check_website( $website );
1410 $http_code = ( is_array( $result ) && isset( $result['httpCode'] ) ) ? $result['httpCode'] : 0;
1411 $check_result = MainWP_Connect::check_ignored_http_code( $http_code, $website );
1412
1413 if ( is_array( $result ) && isset( $result['new_uptime_status'] ) ) {
1414 $check_result = $result['new_uptime_status'];
1415 }
1416
1417 die(
1418 wp_json_encode(
1419 array(
1420 'httpcode' => esc_html( $http_code ),
1421 'status' => $check_result ? 1 : 0,
1422 )
1423 )
1424 );
1425 }
1426
1427 /**
1428 * Method mainwp_ignore_http_response()
1429 *
1430 * Ignore Child Site https response.
1431 *
1432 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1433 * @uses \MainWP\Dashboard\MainWP_DB::update_website_values()
1434 */
1435 public function mainwp_ignore_http_response() {
1436 $this->check_security( 'mainwp_ignore_http_response' );
1437 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1438 $siteid = isset( $_POST['websiteid'] ) ? intval( $_POST['websiteid'] ) : false;
1439 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1440 if ( empty( $siteid ) ) {
1441 die( -1 );
1442 }
1443
1444 $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1445 if ( empty( $website ) ) {
1446 die( -1 );
1447 }
1448
1449 MainWP_DB::instance()->update_website_values( $website->id, array( 'http_response_code' => '-1' ) );
1450 die( wp_json_encode( array( 'ok' => 1 ) ) );
1451 }
1452
1453 /**
1454 * Method mainwp_autoupdate_and_trust_child()
1455 *
1456 * Set MainWP Child Plugin to Trusted & AutoUpdate.
1457 *
1458 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_plugin()
1459 */
1460 public function mainwp_autoupdate_and_trust_child() {
1461 $this->secure_request( 'mainwp_autoupdate_and_trust_child' );
1462 if ( 1 !== (int) get_option( 'mainwp_pluginAutomaticDailyUpdate' ) ) {
1463 update_option( 'mainwp_pluginAutomaticDailyUpdate', 1 );
1464 }
1465 MainWP_Plugins_Handler::trust_plugin( 'mainwp-child/mainwp-child.php' );
1466 die( 'ok' );
1467 }
1468
1469 /**
1470 * Method mainwp_force_destroy_sessions()
1471 *
1472 * Force destroy sessions.
1473 *
1474 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
1475 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1476 *
1477 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
1478 */
1479 public function mainwp_force_destroy_sessions() {
1480 $this->secure_request( 'mainwp_force_destroy_sessions' );
1481
1482 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1483 $website_id = ( isset( $_POST['website_id'] ) ? (int) $_POST['website_id'] : 0 );
1484 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1485 if ( ! MainWP_DB::instance()->get_website_by_id( $website_id ) ) {
1486 die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'This website does not exist.', 'mainwp' ) ) ) ) );
1487 }
1488
1489 $website = MainWP_DB::instance()->get_website_by_id( $website_id );
1490 if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
1491 die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'You cannot edit this website.', 'mainwp' ) ) ) ) );
1492 }
1493
1494 try {
1495 $information = MainWP_Connect::fetch_url_authed(
1496 $website,
1497 'settings_tools',
1498 array(
1499 'action' => 'force_destroy_sessions',
1500 )
1501 );
1502 } catch ( \Exception $e ) {
1503 $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
1504 }
1505
1506 wp_send_json( $information );
1507 }
1508
1509 /**
1510 * Method ajax_refresh_icon()
1511 */
1512 public function ajax_refresh_icon() {
1513 $this->secure_request( 'mainwp_refresh_icon' );
1514 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1515 $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1516 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1517 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1518
1519 if ( empty( $slug ) ) {
1520 wp_die( 'failed' );
1521 }
1522
1523 $fet_icon = MainWP_System_Utility::handle_get_icon( $slug, $type );
1524
1525 if ( ! empty( $fet_icon ) ) {
1526 wp_die( 'success' );
1527 } else {
1528 wp_die( 'failed' );
1529 }
1530 }
1531
1532 /**
1533 * Method ajax_upload_custom_icon()
1534 */
1535 public function ajax_upload_custom_icon() { //phpcs:ignore -- NOSONAR -complex.
1536 $this->secure_request( 'mainwp_upload_custom_icon' );
1537 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1538 $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1539 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1540 $delete = isset( $_POST['delete'] ) ? intval( $_POST['delete'] ) : 0;
1541
1542 if ( empty( $slug ) || ( 'plugin' !== $type && 'theme' !== $type ) ) {
1543 wp_die( 'Invalid data! Type or empty slug' );
1544 }
1545
1546 $sub_folder = '';
1547
1548 if ( 'plugin' === $type ) {
1549 $sub_folder = 'plugin-icons';
1550 } elseif ( 'theme' === $type ) {
1551 $sub_folder = 'theme-icons';
1552 } else {
1553 wp_die( wp_json_encode( array( 'result' => 'invalid' ) ) );
1554 }
1555
1556 if ( $delete ) {
1557 MainWP_System_Utility::update_cached_icons( '', $slug, $type, true );
1558 wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1559 }
1560
1561 $output = isset( $_FILES['mainwp_upload_icon_uploader'] ) ? MainWP_System_Utility::handle_upload_image( $sub_folder, $_FILES['mainwp_upload_icon_uploader'], 0 ) : null;
1562 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1563
1564 $uploaded_icon = 'NOTCHANGE';
1565 if ( is_array( $output ) && isset( $output['filename'] ) && ! empty( $output['filename'] ) ) {
1566 $uploaded_icon = $output['filename'];
1567 }
1568
1569 if ( 'NOTCHANGE' !== $uploaded_icon ) {
1570 MainWP_System_Utility::update_cached_icons( $uploaded_icon, $slug, $type, true );
1571 wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1572 } else {
1573 $result = array(
1574 'result' => 'failed',
1575 );
1576 $error = static::get_upload_icon_error( $output );
1577 if ( ! empty( $error ) ) {
1578 $result['error'] = esc_html( $error );
1579 }
1580 wp_die( wp_json_encode( $result ) );
1581 }
1582 }
1583
1584 /**
1585 * Method get_upload_icon_error().
1586 *
1587 * @param mixed $results Upload results.
1588 *
1589 * @return string
1590 */
1591 public static function get_upload_icon_error( $results ) {
1592 $error = '';
1593 if ( is_array( $results ) && ! empty( $results['error'] ) && is_array( $results['error'] ) ) {
1594 $error_code = $results['error'][0];
1595 switch ( $error_code ) {
1596 case 3:
1597 $error = __( 'File size is too big. Please try a smaller file.', 'mainwp' );
1598 break;
1599 case 4:
1600 $error = __( 'File type is not allowed. Please use a different file type.', 'mainwp' );
1601 break;
1602 case 5:
1603 $error = __( 'File extension is not allowed. Please use a different file type.', 'mainwp' );
1604 break;
1605 case 6:
1606 $error = __( 'Cannot copy file. Please try again.', 'mainwp' );
1607 break;
1608 case 9:
1609 $error = __( 'Failed to crop file. Please try again.', 'mainwp' );
1610 break;
1611 default:
1612 $error = __( 'Undefined error. Please try again.', 'mainwp' );
1613 break;
1614 }
1615 }
1616 return $error;
1617 }
1618
1619 /**
1620 * Method ajax_select_custom_theme()
1621 */
1622 public function ajax_select_custom_theme() {
1623 $this->secure_request( 'mainwp_select_custom_theme' );
1624 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1625 $theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : '';
1626 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1627 if ( empty( $theme ) ) {
1628 wp_die( 'failed' );
1629 }
1630
1631 $user = wp_get_current_user();
1632 if ( empty( $user ) || empty( $user->ID ) ) {
1633 wp_die( 'failed' );
1634 }
1635
1636 update_user_option( $user->ID, 'mainwp_selected_theme', $theme );
1637 wp_die( 'success' );
1638 }
1639
1640 /**
1641 * Method ajax_import_demo_data().
1642 */
1643 public function ajax_import_demo_data() {
1644 $this->secure_request( 'mainwp_import_demo_data' );
1645 $data = MainWP_Demo_Handle::get_instance()->import_data_demo();
1646 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 1 );
1647 wp_die( wp_json_encode( $data ) );
1648 }
1649
1650 /**
1651 * Method ajax_delete_demo_data().
1652 */
1653 public function ajax_delete_demo_data() {
1654 $this->secure_request( 'mainwp_delete_demo_data' );
1655 $data = MainWP_Demo_Handle::get_instance()->delete_data_demo();
1656 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 0 );
1657 wp_die( wp_json_encode( $data ) );
1658 }
1659
1660 /**
1661 * Method ajax_save_temp_import_website()
1662 *
1663 * Save temp import website.
1664 *
1665 * @uses MainWP_DB::instance()->get_general_option()
1666 * @uses MainWP_DB::instance()->update_general_option(()
1667 */
1668 public function ajax_save_temp_import_website() {
1669 $this->secure_request( 'mainwp_save_temp_import_website' ); // Check secure.
1670 $error_msg = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1671 // Get previously saved temporary data (if any).
1672 $values = MainWP_DB::instance()->get_general_option( 'temp_import_sites', 'array' );
1673 $status = $this->mainwp_get_sanitized_post( 'status' );
1674 $index = $this->mainwp_get_sanitized_post( 'row_index', 'intval' ) ?? 1;
1675 if ( empty( $status ) || '' === $index ) {
1676 wp_die( wp_send_json_error( $error_msg ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1677 }
1678
1679 $is_update = false;
1680 if ( 'delete_temp' === $status ) { // Handling remove temp data.
1681 $is_update = $this->mainwp_handle_delete_temp_import_website( $values, $index );
1682 } elseif ( 'save_temp' === $status ) { // Handling save row data.
1683 // Update row data into array.
1684 $row_item = array(
1685 'site_url' => $this->mainwp_get_sanitized_post( 'site_url' ),
1686 'admin_name' => $this->mainwp_get_sanitized_post( 'admin_name' ),
1687 'admin_password' => $this->mainwp_get_sanitized_post( 'admin_password' ),
1688 'site_name' => $this->mainwp_get_sanitized_post( 'site_name' ),
1689 'tag' => $this->mainwp_get_sanitized_post( 'tag' ),
1690 'security_id' => $this->mainwp_get_sanitized_post( 'security_id' ),
1691 'http_username' => $this->mainwp_get_sanitized_post( 'http_username' ),
1692 'http_password' => $this->mainwp_get_sanitized_post( 'http_password' ),
1693 'verify_certificate' => $this->mainwp_get_sanitized_post( 'verify_certificate', 'intval' ) ?? 1,
1694 'ssl_version' => $this->mainwp_get_sanitized_post( 'ssl_version' ) ?? 'auto',
1695 );
1696
1697 $is_update = $this->mainwp_handle_save_temp_import_website( $values, $index, $row_item );
1698 }
1699 // Save data to options table.
1700 if ( $is_update ) {
1701 MainWP_DB::instance()->update_general_option( 'temp_import_sites', $values, 'array' );
1702 wp_die( wp_send_json_success( esc_html( __( 'Row data saved successfully.', 'mainwp' ) ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1703 }
1704
1705 // In case of no updates.
1706 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1707 }
1708
1709 /**
1710 * Method mainwp_handle_delete_temp_import_website()
1711 *
1712 * Handling remove temp data.
1713 *
1714 * @param mixed $values temp import sites.
1715 * @param int $index row key.
1716 *
1717 * @return bool true|false.
1718 */
1719 private function mainwp_handle_delete_temp_import_website( &$values, $index ) {
1720 // Check if row data stream exists.
1721 if ( ! empty( $values ) && is_array( $values ) && array_key_exists( $index, $values ) ) {
1722 unset( $values[ $index ] ); // Remove row data.
1723 return true;
1724 }
1725 return false;
1726 }
1727
1728 /**
1729 * Method mainwp_handle_save_temp_import_website()
1730 *
1731 * Create value if empty or array key exists.
1732 *
1733 * @param mixed $values temp import sites.
1734 * @param int $index row key.
1735 * @param array $row_item new row.
1736 *
1737 * @return bool true.
1738 */
1739 private function mainwp_handle_save_temp_import_website( &$values, $index, $row_item ) {
1740 if ( empty( $values ) || ! array_key_exists( $index, $values ) ) {
1741 $index = 0 !== $index ? $index : 0;
1742 $values[ $index ] = $row_item;
1743 } else {
1744 $values[ $index ] = $row_item;
1745 }
1746 return true;
1747 }
1748
1749 /**
1750 * Method ajax_delete_temp_import_website().
1751 *
1752 * Delete data temp if has been added website.
1753 *
1754 * @uses MainWP_DB::instance()->get_general_option().
1755 * @uses MainWP_DB::instance()->update_general_option().
1756 */
1757 public function ajax_delete_temp_import_website() {
1758 $this->secure_request( 'mainwp_delete_temp_import_website' ); // Check secure.
1759 $error_msg = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1760 // Get option temp import sites data.
1761 $temp_sites = MainWP_DB::instance()->get_general_option( 'temp_import_sites', 'array' );
1762 if ( empty( $temp_sites ) || ! is_array( $temp_sites ) ) { // Check if temp_sites data exists and is an array.
1763 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1764 }
1765
1766 // Get wpurl, wpadmin from POST.
1767 $wp_url = $this->mainwp_get_sanitized_post( 'managesites_add_wpurl' );
1768 $wp_admin = $this->mainwp_get_sanitized_post( 'managesites_add_wpadmin' );
1769 if ( empty( $wp_url ) || empty( $wp_admin ) ) { // Check wpurl, wpadmin has data or empty.
1770 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1771 }
1772 $is_delete = false;
1773
1774 if ( ! empty( $temp_sites ) && is_array( $temp_sites ) ) {
1775 foreach ( $temp_sites as $k_site => $val_site ) { // Loop through data to remove added website.
1776 // Check if row data stream exists.
1777 if ( rtrim( $wp_url, '/' ) === $val_site['site_url'] && $wp_admin === $val_site['admin_name'] ) {
1778 // Remove row data.
1779 unset( $temp_sites[ $k_site ] );
1780 $is_delete = true;
1781 break;
1782 }
1783 }
1784 }
1785
1786 // Save data to options table.
1787 if ( $is_delete ) {
1788 MainWP_DB::instance()->update_general_option( 'temp_import_sites', $temp_sites, 'array' );
1789 wp_die( wp_send_json_success( esc_html__( 'Delete import row successfully.', 'mainwp' ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1790 }
1791
1792 // In case of no delete.
1793 wp_die( wp_send_json_error( $error_msg ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1794 }
1795
1796 /**
1797 * Method ajax_import_website_add_client()
1798 *
1799 * Create client.
1800 */
1801 public function ajax_import_website_add_client() {
1802 $this->secure_request( 'mainwp_import_website_add_client' ); // Check secure.
1803 $error_msg = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1804 try {
1805 // Retrieve client data.
1806 $data = $this->mainwp_get_sanitized_post( 'client' );
1807 $site_id = $this->mainwp_get_sanitized_post( 'site_id' );
1808
1809 if ( empty( $data ) ) {
1810 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1811 }
1812
1813 $client_data = json_decode( $data, true );
1814 // Create client.
1815 $client = $this->mainwp_handle_create_client( $client_data );
1816 if ( $client ) {
1817 // Add groups website and client.
1818 if ( ! empty( $site_id ) ) {
1819 $this->mainwp_handle_selected_sites_for_client( $client, $site_id );
1820 }
1821
1822 wp_die( wp_send_json_success( esc_html__( 'Created client successfully.', 'mainwp' ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1823 }
1824 } catch ( \Exception $e ) {
1825 wp_die( wp_send_json_error( sanitize_text_field( $e->getMessage() ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1826 }
1827 // In case of no created.
1828 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1829 }
1830
1831 /**
1832 * Method ajax_import_website_add_client_no_site()
1833 *
1834 * Create client dont has a website.
1835 */
1836 public function ajax_import_website_add_client_no_site() {
1837 $this->secure_request( 'mainwp_import_website_add_client_no_site' ); // Check secure.
1838 $error_msg = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1839 try {
1840 $data = ! empty( $_POST['client'] ) ? rest_sanitize_array( $_POST['client'] ) : array(); //phpcs:ignore -- NonceVerification.
1841
1842 if ( empty( $data ) || ! is_array( $data ) ) {
1843 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1844 }
1845
1846 foreach ( $data as $val_data ) {
1847 $client_data = json_decode( stripslashes( $val_data ), true ); // Decode client data.
1848 $this->mainwp_handle_create_client( $client_data ); // Update or instert new client.
1849 }
1850 } catch ( \Exception $e ) {
1851 wp_die( wp_send_json_error( sanitize_text_field( $e->getMessage() ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1852 }
1853 // In case of no created.
1854 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1855 }
1856
1857 /**
1858 * Method ajax_clients_add_multi_client
1859 *
1860 * Create Multi Client form QSW.
1861 */
1862 public function ajax_clients_add_multi_client() {
1863 $error_msg = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1864 $this->check_security( 'mainwp_clients_add_multi_client' );
1865 $dataes = isset( $_POST['data'] ) ? $_POST['data'] : array(); //phpcs:ignore -- NonceVerification.
1866 try {
1867 if ( ! empty( $dataes ) ) {
1868 foreach ( $dataes as $val_data ) {
1869 $client_data = array(
1870 'image' => '',
1871 'name' => $val_data['client_name'] ?? '',
1872 'address_1' => '',
1873 'address_2' => '',
1874 'city' => '',
1875 'zip' => '',
1876 'state' => '',
1877 'country' => '',
1878 'note' => '',
1879 'selected_icon_info' => 'selected:wordpress;color:#34424d',
1880 'client_email' => $val_data['client_email'] ?? '',
1881 'client_phone' => '',
1882 'client_facebook' => '',
1883 'client_twitter' => '',
1884 'client_instagram' => '',
1885 'client_linkedin' => '',
1886 'suspended' => 0,
1887 'primary_contact_id' => 0,
1888 );
1889
1890 // Create client.
1891 $client = $this->mainwp_handle_create_client( $client_data );
1892
1893 // Create client successfy.
1894 if ( ! empty( $client ) && ! empty( $val_data['website_id'] ) ) {
1895 // Add groups website and client.
1896 $this->mainwp_handle_selected_sites_for_client( $client, $val_data['website_id'] );
1897 }
1898 // Create client contact.
1899 if ( ! empty( $val_data['contacts_field'] ) ) {
1900 $this->mainwp_handle_create_contact_for_client( $client, $val_data['contacts_field'] );
1901 }
1902 }
1903 wp_die( wp_send_json_success( esc_html__( 'Created client successfully.', 'mainwp' ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1904 }
1905 } catch ( \Exception $e ) {
1906 wp_die( wp_send_json_error( sanitize_text_field( $e->getMessage() ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1907 }
1908
1909 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1910 }
1911
1912 /**
1913 * Method ajax_increase_connection_security
1914 */
1915 public function ajax_increase_connection_security() {
1916 $this->check_security( 'mainwp_increase_connection_security' );
1917 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
1918 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1919 // try to decrypt priv key.
1920 $de_privkey = MainWP_Encrypt_Data_Lib::instance()->decrypt_privkey( base64_decode( $website->privkey ), $website->id ); // phpcs:ignore -- NOSONAR - base64_encode trust.
1921 if ( empty( $de_privkey ) ) { // key is not encrypted.
1922 $en_privkey = MainWP_Encrypt_Data_Lib::instance()->encrypt_privkey( base64_decode( $website->privkey ), $website->id, true ); //phpcs:ignore -- NOSONAR - trust - create encrypt priv key for the site.
1923 if ( ! empty( $en_privkey['en_data'] ) ) {
1924 MainWP_DB::instance()->update_website_values(
1925 $website->id,
1926 array(
1927 'privkey' => base64_encode( $en_privkey['en_data'] ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- NOSONAR - base64_encode trust.
1928 )
1929 );
1930 }
1931 }
1932 }
1933 MainWP_DB::free_result( $websites );
1934 $this->hide_dashboard_notice_status( 'mainwp_secure_priv_key_notice' );
1935 delete_option( 'mainwp_not_start_encrypt_keys' );
1936 wp_die( wp_json_encode( array( 'success' => 1 ) ) );
1937 }
1938
1939 /**
1940 * Method ajax_ui_mode_detected
1941 */
1942 public function ajax_ui_mode_detected() {
1943 $this->check_security( 'mainwp_qsw_ui_mode_detected' );
1944
1945 $detected_ui = isset( $_POST['ui_mode'] ) ? sanitize_text_field( wp_unslash( $_POST['ui_mode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1946
1947 $current_user_theme = get_user_option( 'mainwp_selected_theme' );
1948 if ( empty( $current_user_theme ) ) {
1949 if ( 'dark' === $detected_ui ) {
1950 MainWP_Utility::update_user_option( 'mainwp_selected_theme', 'default-dark' );
1951 } else {
1952 MainWP_Utility::update_user_option( 'mainwp_selected_theme', 'default' );
1953 }
1954 }
1955
1956 wp_die( wp_json_encode( array( 'success' => 1 ) ) );
1957 }
1958
1959
1960
1961 /**
1962 * Handle ajax get changes logs for plugins/themes.
1963 */
1964 public function ajax_get_item_changes_logs() { //phpcs:ignore -- NOSONAR -complex.
1965 $this->check_security( 'mainwp_changes_logs_get_item_changes' );
1966
1967 $siteId = isset( $_POST['siteId'] ) ? intval( $_POST['siteId'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1968 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1969 $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1970 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( urldecode( $_POST['name'] ) ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1971
1972 if ( 'plugin' === $type && ! empty( $slug ) ) {
1973 if ( false !== strpos( $slug, '/' ) ) {
1974 $parts = explode( '/', $slug );
1975 $slug = $parts[0];
1976 } else {
1977 $slug = basename( $slug, '.php' );
1978 }
1979 } elseif ( 'theme' === $type && ! empty( $slug ) ) {
1980 $slug = strtolower( $slug );
1981 }
1982
1983 // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1984 $target_dt = ! empty( $_POST['target_date'] ) ? sanitize_text_field( wp_unslash( $_POST['target_date'] ) ) : '';
1985
1986 if ( ! in_array( $type, array( 'plugin', 'theme' ) ) || ( empty( $target_dt ) && ( empty( $siteId ) || ( empty( $slug ) && empty( $name ) ) ) ) ) {
1987 wp_send_json( array( 'error' => esc_html__( 'Invalid request data. Please try again.', 'mainwp' ) ) );
1988 }
1989
1990 // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1991 $from_date = isset( $_POST['from_date'] ) ? sanitize_text_field( wp_unslash( $_POST['from_date'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1992
1993 $results = Log_Changes_Logs_Helper::instance()->get_history_changes(
1994 array(
1995 'wpid' => $siteId,
1996 'from_date' => $from_date,
1997 'days_number' => 10,
1998 'slug' => $slug,
1999 'type' => $type,
2000 'name' => $name,
2001 'target_date' => $target_dt,
2002 )
2003 );
2004
2005 if ( ! is_array( $results ) ) {
2006 $results = array();
2007 }
2008
2009 wp_send_json( $results );
2010 }
2011
2012 /**
2013 * Handle self_connect action.
2014 */
2015 public function ajax_self_connect() {
2016
2017 $mainwp_run = isset( $_POST['mainwp_run'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_run'] ) ) : ''; // phpcs:ignore -- NOSONAR -ok.
2018
2019 if ( 'self_connect' !== $mainwp_run ) {
2020 status_header( 400 );
2021 exit;
2022 }
2023
2024 MainWP_System_Utility::instance()->handle_self_connect();
2025
2026 exit;
2027 }
2028
2029
2030 /**
2031 * Method mainwp_get_sanitized_post()
2032 *
2033 * Sanitized post field.
2034 *
2035 * @param string $key key to get from POST.
2036 * @param string $callback cleaning method.
2037 *
2038 * @return mixed data value.
2039 */
2040 public function mainwp_get_sanitized_post( $key, $callback = 'sanitize_text_field' ) {
2041 return isset( $_POST[ $key ] ) ? $callback( wp_unslash( $_POST[ $key ] ) ) : ''; //phpcs:ignore -- NonceVerification.
2042 }
2043
2044 /**
2045 * Method mainwp_handle_create_client()
2046 *
2047 * Create new client or return client data.
2048 *
2049 * @uses MainWP_DB_Client::instance()->get_wp_client_by()
2050 * @uses MainWP_DB_Client::instance()->update_client()
2051 *
2052 * @param array $client_data new client creation data.
2053 *
2054 * @return object client data.
2055 */
2056 public function mainwp_handle_create_client( $client_data ) {
2057 // Check if client does not exist then create new one.
2058 $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_email', $client_data['client_email'], OBJECT );
2059 if ( empty( $client ) ) {
2060 $client = MainWP_DB_Client::instance()->update_client( $client_data ); // Create client.
2061 }
2062
2063 return $client;
2064 }
2065
2066 /**
2067 * Method mainwp_handle_selected_sites_for_client()
2068 *
2069 * Update selected sites for client.
2070 *
2071 * @uses MainWP_DB_Client::instance()->get_websites_by_client_ids()
2072 * @uses MainWP_DB_Client::instance()->update_selected_sites_for_client()
2073 *
2074 * @param object $client client data.
2075 * @param int $website_id id.
2076 */
2077 public function mainwp_handle_selected_sites_for_client( $client, $website_id ) {
2078 $sites_ids = MainWP_DB_Client::instance()->get_websites_by_client_ids( $client->client_id );
2079 $ids = isset( $sites_ids ) && ! empty( $sites_ids ) ? array_column( $sites_ids, 'id' ) : array();
2080 $ids[] = $website_id;
2081 MainWP_DB_Client::instance()->update_selected_sites_for_client( $client->client_id, $ids );
2082 }
2083
2084 /**
2085 * Method mainwp_handle_create_contact_for_client()
2086 *
2087 * Handle create contact for client.
2088 *
2089 * @uses MainWP_DB_Client::instance()->update_client_contact()
2090 * @uses MMainWP_DB_Client::instance()->update_client()
2091 *
2092 * @param object $client client data.
2093 * @param array $contacts_data contacts Data.
2094 */
2095 public function mainwp_handle_create_contact_for_client( $client, $contacts_data ) {
2096 $contacts = array_filter( $contacts_data );
2097 // Check required fields.
2098 if ( ( isset( $contacts['contact_name'] ) && '' !== $contacts['contact_name'] ) && ( isset( $contacts['contact_email'] ) && $contacts['contact_email'] ) ) {
2099 $contact_data = array(
2100 'contact_name' => $contacts['contact_name'] ?? '',
2101 'contact_email' => $contacts['contact_email'] ?? '',
2102 'contact_role' => $contacts['contact_role'] ?? '',
2103 'contact_client_id' => $client->client_id,
2104 'contact_phone' => '',
2105 'facebook' => '',
2106 'twitter' => '',
2107 'instagram' => '',
2108 'linkedin' => '',
2109 'contact_icon_info' => '',
2110 );
2111 $inserted = MainWP_DB_Client::instance()->update_client_contact( $contact_data ); // Create or update contact of client.
2112 // If the update is successful, the client will be updated again.
2113 if ( $inserted ) {
2114 $update = array(
2115 'client_id' => $client->client_id,
2116 'primary_contact_id' => $inserted->contact_id,
2117 );
2118 MainWP_DB_Client::instance()->update_client( $update );
2119 }
2120 }
2121 }
2122 }
2123