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

2,136 lines 89.0 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
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
556 if ( 'mail_failed' === $no_id ) {
557 MainWP_Utility::update_option( 'mainwp_notice_wp_mail_failed', 'hide' );
558 die( 'ok' );
559 }
560
561 if ( 'phpver_8_0' === $no_id ) {
562 MainWP_Utility::update_user_option( 'lasttime_hidden_phpver_8_0', time() );
563 }
564
565 $time_set = isset( $_POST['time_set'] ) && 1 === intval( $_POST['time_set'] ) ? true : false;
566 $this->hide_dashboard_notice_status( $no_id, $time_set );
567 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
568 die( 1 );
569 }
570
571 /**
572 * Method hide dashboard notice status.
573 *
574 * @param mixed $no_id notice id.
575 * @param mixed $time_set time.
576 * @param bool $hide_noti hide notice.
577 * @return void
578 */
579 public function hide_dashboard_notice_status( $no_id, $time_set = false, $hide_noti = true ) { //phpcs:ignore -- NOSONAR - complexity.
580 /**
581 * Current user global.
582 *
583 * @global string
584 */
585 global $current_user;
586 $user_id = $current_user->ID;
587 if ( $user_id ) {
588 $status = get_user_option( 'mainwp_notice_saved_status' );
589 if ( ! is_array( $status ) ) {
590 $status = array();
591 }
592 if ( ! empty( $no_id ) ) {
593 if ( 'mainwp_secure_priv_key_notice' === $no_id ) {
594 MainWP_Utility::update_option( 'mainwp_not_start_encrypt_keys', 1 ); // to show the button.
595 }
596 if ( $hide_noti ) {
597 if ( $time_set ) {
598 $status[ $no_id ] = time();
599 } else {
600 $status[ $no_id ] = 1;
601 }
602 } elseif ( ! empty( $status[ $no_id ] ) ) {
603 unset( $status[ $no_id ] );
604 }
605 update_user_option( $user_id, 'mainwp_notice_saved_status', $status );
606 }
607 }
608 }
609
610 /**
611 * Method mainwp_status_saving()
612 *
613 * Save last_sync_sites time().
614 */
615 public function mainwp_status_saving() { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR - complexity.
616 $this->secure_request( 'mainwp_status_saving' );
617 $values = get_option( 'mainwp_status_saved_values' );
618
619 if ( ! is_array( $values ) ) {
620 $values = array();
621 }
622
623 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
624 if ( ! isset( $_POST['status'] ) ) {
625 die( -1 );
626 }
627
628 if ( 'last_sync_sites' === $_POST['status'] ) {
629 if ( isset( $_POST['isGlobalSync'] ) && ! empty( $_POST['isGlobalSync'] ) ) {
630 update_option( 'mainwp_last_synced_all_sites', time() );
631
632 /**
633 * Action: mainwp_synced_all_sites
634 *
635 * Fires upon successfull synchronization process.
636 *
637 * @since 3.5.1
638 */
639 do_action( 'mainwp_synced_all_sites' );
640 }
641 die( 'ok' );
642 }
643
644 $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
645 $value = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
646 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
647
648 if ( ! empty( $status ) ) {
649 if ( empty( $value ) ) {
650 if ( isset( $values[ $status ] ) ) {
651 unset( $values[ $status ] );
652 }
653 } else {
654 $values[ $status ] = $value;
655 }
656 update_option( 'mainwp_status_saved_values', $values );
657 }
658
659 die( 'ok' );
660 }
661
662 /**
663 * Method ajax_widget_order()
664 *
665 * Update saved widget order.
666 */
667 public function ajax_widgets_order() { //phpcs:ignore -- NOSONAR - complex.
668
669 $this->secure_request( 'mainwp_widgets_order' );
670 $user = wp_get_current_user();
671 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
672 if ( $user && ! empty( $_POST['page'] ) ) {
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'] ) ) : '';
677
678 $wgs_orders = array();
679
680 if ( ! empty( $wgids ) ) {
681 $wgids = json_decode( $wgids, true );
682 $order = json_decode( $order, true );
683 if ( is_array( $wgids ) && is_array( $order ) ) {
684 foreach ( $wgids as $idx => $wgid ) {
685 if ( isset( $order[ $idx ] ) ) {
686 $pre = 'widget-'; // #compatible-widgetid.
687 if ( 0 === strpos( $wgid, $pre ) ) {
688 $wgid = substr( $wgid, strlen( $pre ) );
689 }
690 $wgs_orders[ $wgid ] = $order[ $idx ];
691 }
692 }
693 }
694 }
695
696 if ( 'mainwp_page_manageclients' === $page ) {
697 $item_id = isset( $_POST['item_id'] ) ? intval( $_POST['item_id'] ) : 0;
698 $sorted_array = get_user_option( 'mainwp_widgets_sorted_' . strtolower( $page ) );
699 if ( ! empty( $sorted_array ) ) {
700 $sorted_array = json_decode( $sorted_array, true );
701 }
702 if ( ! is_array( $sorted_array ) ) {
703 $sorted_array = array();
704 }
705 $sorted_array[ $item_id ] = $wgs_orders;
706 update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $sorted_array ), true );
707 } else {
708 update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $wgs_orders ), true );
709 }
710 MainWP_Cache_Warm_Helper::invalidate_manage_pages( array( $page_widget ) );
711 die( 'ok' );
712 }
713 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
714 die( -1 );
715 }
716
717 /**
718 * Method ajax_mainwp_save_settings()
719 *
720 * Update saved MainWP Settings.
721 *
722 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
723 */
724 public function ajax_mainwp_save_settings() {
725 $this->secure_request( 'mainwp_save_settings' );
726 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
727 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
728 if ( ! empty( $name ) ) {
729 $option_name = 'mainwp_' . $name;
730 $val = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
731 MainWP_Utility::update_option( $option_name, $val );
732 }
733 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
734 die( 'ok' );
735 }
736
737 /**
738 * Method ajax_guided_tours_option_update()
739 *
740 * Update saved MainWP Settings.
741 *
742 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
743 */
744 public function ajax_guided_tours_option_update() {
745 $this->secure_request( 'mainwp_guided_tours_option_update' );
746 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
747 $enable = isset( $_POST['enable'] ) ? intval( $_POST['enable'] ) : 0;
748 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
749 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', $enable );
750 die( 'ok ' . intval( $enable ) );
751 }
752
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 /**
769 * Method mainwp_leftmenu_filter_group()
770 *
771 * MainWP left menu filter by group.
772 *
773 * @uses \MainWP\Dashboard\MainWP_DB::query()
774 * @uses \MainWP\Dashboard\MainWP_DB::get_websites_by_group_id()
775 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
776 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
777 */
778 public function mainwp_leftmenu_filter_group() {
779 $this->secure_request( 'mainwp_leftmenu_filter_group' );
780
781 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
782 $gid = isset( $_POST['group_id'] ) ? intval( $_POST['group_id'] ) : false;
783 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
784
785 if ( ! empty( $gid ) ) {
786 $ids = '';
787 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $gid, true ) );
788 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
789 $ids .= $website->id . ',';
790 }
791 MainWP_DB::free_result( $websites );
792 $ids = rtrim( $ids, ',' );
793 die( $ids ); // phpcs:ignore WordPress.Security.EscapeOutput
794 }
795 die( '' );
796 }
797
798 /**
799 * Method dismiss_activate_notice()
800 *
801 * Dismiss activate notice.
802 */
803 public function dismiss_activate_notice() {
804 $this->secure_request( 'mainwp_dismiss_activate_notice' );
805
806 /**
807 * Current user global.
808 *
809 * @global string
810 */
811 global $current_user;
812 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
813 $user_id = $current_user->ID;
814 $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
815 if ( $user_id && ! empty( $slug ) ) {
816 $activate_notices = get_user_option( 'mainwp_hide_activate_notices' );
817 if ( ! is_array( $activate_notices ) ) {
818 $activate_notices = array();
819 }
820
821 $activate_notices[ $slug ] = time();
822 update_user_option( $user_id, 'mainwp_hide_activate_notices', $activate_notices );
823 }
824 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
825 die( 1 );
826 }
827
828
829
830 /**
831 * Method mainwp_security_issues_request()
832 *
833 * Post handler for,
834 * Page: SecurityIssues.
835 *
836 * @uses \MainWP\Dashboard\MainWP_Exception
837 * @uses \MainWP\Dashboard\MainWP_Security_Issues::fetch_security_issues()
838 */
839 public function mainwp_security_issues_request() {
840 $this->secure_request( 'mainwp_security_issues_request' );
841
842 try {
843 wp_send_json( array( 'result' => MainWP_Security_Issues::fetch_security_issues() ) );
844 } catch ( MainWP_Exception $e ) {
845 die(
846 wp_json_encode(
847 array(
848 'error' => array(
849 'message' => $e->getMessage(),
850 'extra' => $e->get_message_extra(),
851 ),
852 )
853 )
854 );
855 }
856 }
857
858 /**
859 * Method mainwp_security_issues_fix()
860 *
861 * Post handler for 'fix issues',
862 * Page: SecurityIssues.
863 *
864 * @uses \MainWP\Dashboard\MainWP_Exception
865 * @uses \MainWP\Dashboard\MainWP_Security_Issues::fix_security_issue()
866 */
867 public function mainwp_security_issues_fix() {
868 $this->secure_request( 'mainwp_security_issues_fix' );
869
870 try {
871 wp_send_json( array( 'result' => MainWP_Security_Issues::fix_security_issue() ) );
872 } catch ( MainWP_Exception $e ) {
873 die(
874 wp_json_encode(
875 array(
876 'error' => array(
877 'message' => $e->getMessage(),
878 'extra' => $e->get_message_extra(),
879 ),
880 )
881 )
882 );
883 }
884 }
885
886 /**
887 * Method mainwp_security_issues_unfix()
888 *
889 * Post handler for 'unfix issues',
890 * Page: SecurityIssues.
891 *
892 * @uses \MainWP\Dashboard\MainWP_Exception
893 * @uses \MainWP\Dashboard\MainWP_Security_Issues::unfix_security_issue()
894 */
895 public function mainwp_security_issues_unfix() {
896 $this->secure_request( 'mainwp_security_issues_unfix' );
897
898 try {
899 wp_send_json( array( 'result' => MainWP_Security_Issues::unfix_security_issue() ) );
900 } catch ( MainWP_Exception $e ) {
901 die(
902 wp_json_encode(
903 array(
904 'error' => array(
905 'message' => $e->getMessage(),
906 'extra' => $e->get_message_extra(),
907 ),
908 )
909 )
910 );
911 }
912 }
913
914 /**
915 * Method ajax_disconnect_site()
916 *
917 * Disconnect Child Site.
918 *
919 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
920 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
921 */
922 public function ajax_disconnect_site() {
923 $this->secure_request( 'mainwp_disconnect_site' );
924 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
925 $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
926 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
927
928 if ( empty( $siteid ) ) {
929 die( wp_json_encode( array( 'error' => 'Error: site id empty' ) ) );
930 }
931
932 $website = MainWP_DB::instance()->get_website_by_id( $siteid );
933
934 if ( ! $website ) {
935 die( wp_json_encode( array( 'error' => 'Not found site' ) ) );
936 }
937
938 try {
939 $information = MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
940 } catch ( \Exception $e ) {
941 $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
942 }
943
944 wp_send_json( $information );
945 }
946
947 /**
948 * Method ajax_sites_display_rows()
949 *
950 * Display rows via ajax,
951 * Page: Manage Sites.
952 *
953 * @uses \MainWP\Dashboard\MainWP_Manage_Sites::ajax_optimize_display_rows()
954 */
955 public function ajax_sites_display_rows() {
956 $this->secure_request( 'mainwp_manage_sites_display_rows' );
957 MainWP_Manage_Sites::ajax_optimize_display_rows();
958 }
959
960 /**
961 * Method ajax_monitoring_display_rows()
962 *
963 * Display rows via ajax,
964 * Page: Monitoring Sites.
965 *
966 * @uses \MainWP\Dashboard\MainWP_Monitoring::ajax_optimize_display_rows()
967 */
968 public function ajax_monitoring_display_rows() {
969 $this->secure_request( 'mainwp_monitoring_sites_display_rows' );
970 MainWP_Monitoring::ajax_optimize_display_rows();
971 }
972
973
974 /**
975 * Method mainwp_bulkadduser()
976 *
977 * Bulk Add User for,
978 * Page: BulkAddUser.
979 *
980 * @uses \MainWP\Dashboard\MainWP_User::do_bulk_add()
981 */
982 public function mainwp_bulkadduser() {
983 $this->check_security( 'mainwp_bulkadduser' );
984 MainWP_User::do_bulk_add();
985 die();
986 }
987
988 /**
989 * Method mainwp_importuser()
990 *
991 * Import user.
992 *
993 * @uses \MainWP\Dashboard\MainWP_User::do_import()
994 */
995 public function mainwp_importuser() {
996 $this->secure_request( 'mainwp_importuser' );
997 MainWP_User::do_import();
998 }
999
1000 /**
1001 * Method mainwp_clients_add_client()
1002 *
1003 * Add Client for,
1004 * Page: BulkAddClient.
1005 */
1006 public function mainwp_clients_add_client() {
1007 $this->check_security( 'mainwp_clients_add_client' );
1008 MainWP_Client::add_client();
1009 die();
1010 }
1011
1012 /**
1013 * Method mainwp_clients_delete_client()
1014 *
1015 * Add Client for,
1016 * Page: BulkAddClient.
1017 */
1018 public function mainwp_clients_delete_client() {
1019 $this->check_security( 'mainwp_clients_delete_client' );
1020 $ret = array( 'success' => false );
1021 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1022 $client_id = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
1023 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1024 if ( $client_id ) {
1025 MainWP_DB_Client::instance()->delete_client( $client_id );
1026 $ret['success'] = 'SUCCESS';
1027 $ret['result'] = esc_html__( 'Client removed successfully.', 'mainwp' );
1028 MainWP_Client::invalidate_warm_cache();
1029 } else {
1030 $ret['result'] = esc_html__( 'Client ID empty.', 'mainwp' );
1031 }
1032
1033 echo wp_json_encode( $ret );
1034 exit;
1035 }
1036
1037 /**
1038 * Method mainwp_clients_save_field()
1039 *
1040 * Save client custom fields.
1041 */
1042 public function mainwp_clients_save_field() {
1043 $this->check_security( 'mainwp_clients_save_field' );
1044 MainWP_Client::invalidate_warm_cache();
1045 MainWP_Client::save_client_field();
1046 die();
1047 }
1048
1049
1050 /**
1051 * Method mainwp_clients_delete_general_field()
1052 *
1053 * Delete client general fields.
1054 */
1055 public function mainwp_clients_delete_general_field() {
1056 $this->check_security( 'mainwp_clients_delete_general_field' );
1057 $ret = array( 'success' => false );
1058 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1059 $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
1060 $client_id = 0; // 0 general fields.
1061 if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
1062 $ret['success'] = true;
1063 }
1064 MainWP_Client::invalidate_warm_cache();
1065 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1066 echo wp_json_encode( $ret );
1067 exit;
1068 }
1069
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 /**
1108 * Method mainwp_clients_delete_field()
1109 *
1110 * Delete client custom fields.
1111 */
1112 public function mainwp_clients_delete_field() {
1113 $this->check_security( 'mainwp_clients_delete_field' );
1114 $ret = array( 'success' => false );
1115 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1116 $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
1117 $client_id = isset( $_POST['client_id'] ) ? intval( $_POST['client_id'] ) : 0; // $client_id > 0, individual token.
1118 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1119 if ( $client_id && MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
1120 $ret['success'] = true;
1121 }
1122 echo wp_json_encode( $ret );
1123 exit;
1124 }
1125
1126 /**
1127 * Method mainwp_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_notes_save() {
1135 $this->secure_request( 'mainwp_notes_save' );
1136 MainWP_Manage_Sites_Handler::save_note();
1137 }
1138
1139 /**
1140 * Method mainwp_clients_notes_save()
1141 *
1142 * Post handler for save notes on,
1143 * Page: Manage Sites.
1144 *
1145 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1146 */
1147 public function mainwp_clients_notes_save() {
1148 $this->secure_request( 'mainwp_clients_notes_save' );
1149 MainWP_Client::save_note();
1150 }
1151
1152 /**
1153 * Method mainwp_clients_suspend_client()
1154 *
1155 * Post handler for suspend client,
1156 * Page: Manage Sites.
1157 *
1158 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1159 */
1160 public function mainwp_clients_suspend_client() {
1161 $this->secure_request( 'mainwp_clients_suspend_client' );
1162 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1163 $clientid = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
1164 $suspended = isset( $_POST['suspend_status'] ) && ! empty( $_POST['suspend_status'] ) ? 1 : 0;
1165 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1166
1167 if ( empty( $clientid ) ) {
1168 wp_die( 'Error - empty client id!' );
1169 }
1170
1171 $params = array(
1172 'client_id' => $clientid,
1173 'suspended' => $suspended,
1174 );
1175
1176 MainWP_DB_Client::instance()->update_client( $params );
1177
1178 $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $clientid );
1179
1180 /**
1181 * Fires immediately after update client suspend/unsuspend.
1182 *
1183 * @since 4.5.1.1
1184 *
1185 * @param object $client client data.
1186 * @param bool $suspended true|false.
1187 */
1188 do_action( 'mainwp_client_suspend', $client, $suspended );
1189
1190 MainWP_DB_Client::instance()->suspend_unsuspend_websites_by_client_id( $clientid, $suspended );
1191
1192 wp_die( 'success' );
1193 }
1194
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 /**
1302 * Method mainwp_syncerrors_dismiss()
1303 *
1304 * Dismiss Sync errors for,
1305 * Widget: RightNow.
1306 *
1307 * @uses \MainWP\Dashboard\MainWP_Updates_Overview::dismiss_sync_errors()
1308 */
1309 public function mainwp_syncerrors_dismiss() {
1310
1311 $this->secure_request( 'mainwp_syncerrors_dismiss' );
1312
1313 try {
1314 die( wp_json_encode( array( 'result' => MainWP_Updates_Overview::dismiss_sync_errors() ) ) );
1315 } catch ( \Exception $e ) {
1316 die( wp_json_encode( array( 'error' => sanitize_text_field( $e->getMessage() ) ) ) );
1317 }
1318 }
1319
1320 /**
1321 * Method mainwp_events_notice_hide()
1322 *
1323 * Hide events notice.
1324 */
1325 public function mainwp_events_notice_hide() {
1326 $this->secure_request( 'mainwp_events_notice_hide' );
1327 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1328 if ( isset( $_POST['notice'] ) ) {
1329 $current_options = get_option( 'mainwp_showhide_events_notice' );
1330 if ( ! is_array( $current_options ) ) {
1331 $current_options = array();
1332 }
1333 if ( 'first_site' === $_POST['notice'] ) {
1334 update_option( 'mainwp_first_site_events_notice', '' );
1335 } elseif ( 'request_reviews1' === $_POST['notice'] ) {
1336 $current_options['request_reviews1'] = 15;
1337 $current_options['request_reviews1_starttime'] = time();
1338 } elseif ( 'request_reviews1_forever' === $_POST['notice'] || 'request_reviews2_forever' === $_POST['notice'] ) {
1339 $current_options['request_reviews1'] = 'forever';
1340 $current_options['request_reviews2'] = 'forever';
1341 } elseif ( 'request_reviews2' === $_POST['notice'] ) {
1342 $current_options['request_reviews2'] = 15;
1343 $current_options['request_reviews2_starttime'] = time();
1344 } elseif ( 'trust_child' === $_POST['notice'] ) {
1345 $current_options['trust_child'] = 1;
1346 } elseif ( 'multi_site' === $_POST['notice'] ) {
1347 $current_options['hide_multi_site_notice'] = 1;
1348 }
1349 update_option( 'mainwp_showhide_events_notice', $current_options );
1350 }
1351 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1352 die( 'ok' );
1353 }
1354
1355 /**
1356 * Method mainwp_showhide_sections()
1357 *
1358 * Show/Hide sections.
1359 */
1360 public function mainwp_showhide_sections() {
1361 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1362 if ( isset( $_POST['sec'] ) && isset( $_POST['status'] ) ) {
1363 $opts = get_option( 'mainwp_opts_showhide_sections' );
1364 if ( ! is_array( $opts ) ) {
1365 $opts = array();
1366 }
1367 $opts[ sanitize_text_field( wp_unslash( $_POST['sec'] ) ) ] = sanitize_text_field( wp_unslash( $_POST['status'] ) );
1368 update_option( 'mainwp_opts_showhide_sections', $opts );
1369 die( 'ok' );
1370 }
1371 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1372 die( 'failed' );
1373 }
1374
1375 /**
1376 * Method mainwp_saving_status()
1377 *
1378 * MainWP Saving Status.
1379 */
1380 public function mainwp_saving_status() {
1381 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1382 if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'mainwp_ajax' ) ) {
1383 die( esc_html__( 'WP nonce could not be verified. Please reload the page and try again.', 'mainwp' ) );
1384 }
1385 $saving_status = isset( $_POST['saving_status'] ) ? sanitize_text_field( wp_unslash( $_POST['saving_status'] ) ) : false;
1386 if ( ! empty( $saving_status ) ) {
1387 $current_options = get_option( 'mainwp_opts_saving_status' );
1388 if ( ! is_array( $current_options ) ) {
1389 $current_options = array();
1390 }
1391 if ( isset( $_POST['value'] ) ) {
1392 $current_options[ $saving_status ] = sanitize_text_field( wp_unslash( $_POST['value'] ) );
1393 }
1394 update_option( 'mainwp_opts_saving_status', $current_options );
1395 }
1396 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1397 die( 'ok' );
1398 }
1399
1400 /**
1401 * Method ajax_recheck_http()
1402 *
1403 * Recheck Child Site http status code & message.
1404 *
1405 * @uses \MainWP\Dashboard\MainWP_Connect::check_ignored_http_code()
1406 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1407 * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_check_website()
1408 */
1409 public function ajax_recheck_http() {
1410 $this->check_security( 'mainwp_recheck_http' );
1411 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1412 if ( ! isset( $_POST['websiteid'] ) || empty( $_POST['websiteid'] ) ) {
1413 die( -1 );
1414 }
1415
1416 $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['websiteid'] ) );
1417 if ( empty( $website ) ) {
1418 die( -1 );
1419 }
1420 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1421
1422 $result = MainWP_Monitoring_Handler::handle_check_website( $website );
1423 $http_code = ( is_array( $result ) && isset( $result['httpCode'] ) ) ? $result['httpCode'] : 0;
1424 $check_result = MainWP_Connect::check_ignored_http_code( $http_code, $website );
1425
1426 if ( is_array( $result ) && isset( $result['new_uptime_status'] ) ) {
1427 $check_result = $result['new_uptime_status'];
1428 }
1429
1430 die(
1431 wp_json_encode(
1432 array(
1433 'httpcode' => esc_html( $http_code ),
1434 'status' => $check_result ? 1 : 0,
1435 )
1436 )
1437 );
1438 }
1439
1440 /**
1441 * Method mainwp_ignore_http_response()
1442 *
1443 * Ignore Child Site https response.
1444 *
1445 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1446 * @uses \MainWP\Dashboard\MainWP_DB::update_website_values()
1447 */
1448 public function mainwp_ignore_http_response() {
1449 $this->check_security( 'mainwp_ignore_http_response' );
1450 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1451 $siteid = isset( $_POST['websiteid'] ) ? intval( $_POST['websiteid'] ) : false;
1452 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1453 if ( empty( $siteid ) ) {
1454 die( -1 );
1455 }
1456
1457 $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1458 if ( empty( $website ) ) {
1459 die( -1 );
1460 }
1461
1462 MainWP_DB::instance()->update_website_values( $website->id, array( 'http_response_code' => '-1' ) );
1463 die( wp_json_encode( array( 'ok' => 1 ) ) );
1464 }
1465
1466 /**
1467 * Method mainwp_autoupdate_and_trust_child()
1468 *
1469 * Set MainWP Child Plugin to Trusted & AutoUpdate.
1470 *
1471 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_plugin()
1472 */
1473 public function mainwp_autoupdate_and_trust_child() {
1474 $this->secure_request( 'mainwp_autoupdate_and_trust_child' );
1475 if ( 1 !== (int) get_option( 'mainwp_pluginAutomaticDailyUpdate' ) ) {
1476 update_option( 'mainwp_pluginAutomaticDailyUpdate', 1 );
1477 }
1478 MainWP_Plugins_Handler::trust_plugin( 'mainwp-child/mainwp-child.php' );
1479 die( 'ok' );
1480 }
1481
1482 /**
1483 * Method mainwp_force_destroy_sessions()
1484 *
1485 * Force destroy sessions.
1486 *
1487 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
1488 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1489 *
1490 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
1491 */
1492 public function mainwp_force_destroy_sessions() {
1493 $this->secure_request( 'mainwp_force_destroy_sessions' );
1494
1495 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1496 $website_id = ( isset( $_POST['website_id'] ) ? (int) $_POST['website_id'] : 0 );
1497 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1498 if ( ! MainWP_DB::instance()->get_website_by_id( $website_id ) ) {
1499 die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'This website does not exist.', 'mainwp' ) ) ) ) );
1500 }
1501
1502 $website = MainWP_DB::instance()->get_website_by_id( $website_id );
1503 if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
1504 die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'You cannot edit this website.', 'mainwp' ) ) ) ) );
1505 }
1506
1507 try {
1508 $information = MainWP_Connect::fetch_url_authed(
1509 $website,
1510 'settings_tools',
1511 array(
1512 'action' => 'force_destroy_sessions',
1513 )
1514 );
1515 } catch ( \Exception $e ) {
1516 $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
1517 }
1518
1519 wp_send_json( $information );
1520 }
1521
1522 /**
1523 * Method ajax_refresh_icon()
1524 */
1525 public function ajax_refresh_icon() {
1526 $this->secure_request( 'mainwp_refresh_icon' );
1527 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1528 $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1529 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1530 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1531
1532 if ( empty( $slug ) ) {
1533 wp_die( 'failed' );
1534 }
1535
1536 $fet_icon = MainWP_System_Utility::handle_get_icon( $slug, $type );
1537
1538 if ( ! empty( $fet_icon ) ) {
1539 wp_die( 'success' );
1540 } else {
1541 wp_die( 'failed' );
1542 }
1543 }
1544
1545 /**
1546 * Method ajax_upload_custom_icon()
1547 */
1548 public function ajax_upload_custom_icon() { //phpcs:ignore -- NOSONAR -complex.
1549 $this->secure_request( 'mainwp_upload_custom_icon' );
1550 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1551 $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1552 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1553 $delete = isset( $_POST['delete'] ) ? intval( $_POST['delete'] ) : 0;
1554
1555 if ( empty( $slug ) || ( 'plugin' !== $type && 'theme' !== $type ) ) {
1556 wp_die( 'Invalid data! Type or empty slug' );
1557 }
1558
1559 $sub_folder = '';
1560
1561 if ( 'plugin' === $type ) {
1562 $sub_folder = 'plugin-icons';
1563 } elseif ( 'theme' === $type ) {
1564 $sub_folder = 'theme-icons';
1565 } else {
1566 wp_die( wp_json_encode( array( 'result' => 'invalid' ) ) );
1567 }
1568
1569 if ( $delete ) {
1570 MainWP_System_Utility::update_cached_icons( '', $slug, $type, true );
1571 wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1572 }
1573
1574 $output = isset( $_FILES['mainwp_upload_icon_uploader'] ) ? MainWP_System_Utility::handle_upload_image( $sub_folder, $_FILES['mainwp_upload_icon_uploader'], 0 ) : null;
1575 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1576
1577 $uploaded_icon = 'NOTCHANGE';
1578 if ( is_array( $output ) && isset( $output['filename'] ) && ! empty( $output['filename'] ) ) {
1579 $uploaded_icon = $output['filename'];
1580 }
1581
1582 if ( 'NOTCHANGE' !== $uploaded_icon ) {
1583 MainWP_System_Utility::update_cached_icons( $uploaded_icon, $slug, $type, true );
1584 wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1585 } else {
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 ) );
1594 }
1595 }
1596
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 /**
1633 * Method ajax_select_custom_theme()
1634 */
1635 public function ajax_select_custom_theme() {
1636 $this->secure_request( 'mainwp_select_custom_theme' );
1637 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1638 $theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : '';
1639 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1640 if ( empty( $theme ) ) {
1641 wp_die( 'failed' );
1642 }
1643
1644 $user = wp_get_current_user();
1645 if ( empty( $user ) || empty( $user->ID ) ) {
1646 wp_die( 'failed' );
1647 }
1648
1649 update_user_option( $user->ID, 'mainwp_selected_theme', $theme );
1650 wp_die( 'success' );
1651 }
1652
1653 /**
1654 * Method ajax_import_demo_data().
1655 */
1656 public function ajax_import_demo_data() {
1657 $this->secure_request( 'mainwp_import_demo_data' );
1658 $data = MainWP_Demo_Handle::get_instance()->import_data_demo();
1659 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 1 );
1660 wp_die( wp_json_encode( $data ) );
1661 }
1662
1663 /**
1664 * Method ajax_delete_demo_data().
1665 */
1666 public function ajax_delete_demo_data() {
1667 $this->secure_request( 'mainwp_delete_demo_data' );
1668 $data = MainWP_Demo_Handle::get_instance()->delete_data_demo();
1669 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 0 );
1670 wp_die( wp_json_encode( $data ) );
1671 }
1672
1673 /**
1674 * Method ajax_save_temp_import_website()
1675 *
1676 * Save temp import website.
1677 *
1678 * @uses MainWP_DB::instance()->get_general_option()
1679 * @uses MainWP_DB::instance()->update_general_option(()
1680 */
1681 public function ajax_save_temp_import_website() {
1682 $this->secure_request( 'mainwp_save_temp_import_website' ); // Check secure.
1683 $error_msg = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1684 // Get previously saved temporary data (if any).
1685 $values = MainWP_DB::instance()->get_general_option( 'temp_import_sites', 'array' );
1686 $status = $this->mainwp_get_sanitized_post( 'status' );
1687 $index = $this->mainwp_get_sanitized_post( 'row_index', 'intval' ) ?? 1;
1688 if ( empty( $status ) || '' === $index ) {
1689 wp_die( wp_send_json_error( $error_msg ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1690 }
1691
1692 $is_update = false;
1693 if ( 'delete_temp' === $status ) { // Handling remove temp data.
1694 $is_update = $this->mainwp_handle_delete_temp_import_website( $values, $index );
1695 } elseif ( 'save_temp' === $status ) { // Handling save row data.
1696 // Update row data into array.
1697 $row_item = array(
1698 'site_url' => $this->mainwp_get_sanitized_post( 'site_url' ),
1699 'admin_name' => $this->mainwp_get_sanitized_post( 'admin_name' ),
1700 'admin_password' => $this->mainwp_get_sanitized_post( 'admin_password' ),
1701 'site_name' => $this->mainwp_get_sanitized_post( 'site_name' ),
1702 'tag' => $this->mainwp_get_sanitized_post( 'tag' ),
1703 'security_id' => $this->mainwp_get_sanitized_post( 'security_id' ),
1704 'http_username' => $this->mainwp_get_sanitized_post( 'http_username' ),
1705 'http_password' => $this->mainwp_get_sanitized_post( 'http_password' ),
1706 'verify_certificate' => $this->mainwp_get_sanitized_post( 'verify_certificate', 'intval' ) ?? 1,
1707 'ssl_version' => $this->mainwp_get_sanitized_post( 'ssl_version' ) ?? 'auto',
1708 );
1709
1710 $is_update = $this->mainwp_handle_save_temp_import_website( $values, $index, $row_item );
1711 }
1712 // Save data to options table.
1713 if ( $is_update ) {
1714 MainWP_DB::instance()->update_general_option( 'temp_import_sites', $values, 'array' );
1715 wp_die( wp_send_json_success( esc_html( __( 'Row data saved successfully.', 'mainwp' ) ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1716 }
1717
1718 // In case of no updates.
1719 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1720 }
1721
1722 /**
1723 * Method mainwp_handle_delete_temp_import_website()
1724 *
1725 * Handling remove temp data.
1726 *
1727 * @param mixed $values temp import sites.
1728 * @param int $index row key.
1729 *
1730 * @return bool true|false.
1731 */
1732 private function mainwp_handle_delete_temp_import_website( &$values, $index ) {
1733 // Check if row data stream exists.
1734 if ( ! empty( $values ) && is_array( $values ) && array_key_exists( $index, $values ) ) {
1735 unset( $values[ $index ] ); // Remove row data.
1736 return true;
1737 }
1738 return false;
1739 }
1740
1741 /**
1742 * Method mainwp_handle_save_temp_import_website()
1743 *
1744 * Create value if empty or array key exists.
1745 *
1746 * @param mixed $values temp import sites.
1747 * @param int $index row key.
1748 * @param array $row_item new row.
1749 *
1750 * @return bool true.
1751 */
1752 private function mainwp_handle_save_temp_import_website( &$values, $index, $row_item ) {
1753 if ( empty( $values ) || ! array_key_exists( $index, $values ) ) {
1754 $index = 0 !== $index ? $index : 0;
1755 $values[ $index ] = $row_item;
1756 } else {
1757 $values[ $index ] = $row_item;
1758 }
1759 return true;
1760 }
1761
1762 /**
1763 * Method ajax_delete_temp_import_website().
1764 *
1765 * Delete data temp if has been added website.
1766 *
1767 * @uses MainWP_DB::instance()->get_general_option().
1768 * @uses MainWP_DB::instance()->update_general_option().
1769 */
1770 public function ajax_delete_temp_import_website() {
1771 $this->secure_request( 'mainwp_delete_temp_import_website' ); // Check secure.
1772 $error_msg = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1773 // Get option temp import sites data.
1774 $temp_sites = MainWP_DB::instance()->get_general_option( 'temp_import_sites', 'array' );
1775 if ( empty( $temp_sites ) || ! is_array( $temp_sites ) ) { // Check if temp_sites data exists and is an array.
1776 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1777 }
1778
1779 // Get wpurl, wpadmin from POST.
1780 $wp_url = $this->mainwp_get_sanitized_post( 'managesites_add_wpurl' );
1781 $wp_admin = $this->mainwp_get_sanitized_post( 'managesites_add_wpadmin' );
1782 if ( empty( $wp_url ) || empty( $wp_admin ) ) { // Check wpurl, wpadmin has data or empty.
1783 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1784 }
1785 $is_delete = false;
1786
1787 if ( ! empty( $temp_sites ) && is_array( $temp_sites ) ) {
1788 foreach ( $temp_sites as $k_site => $val_site ) { // Loop through data to remove added website.
1789 // Check if row data stream exists.
1790 if ( rtrim( $wp_url, '/' ) === $val_site['site_url'] && $wp_admin === $val_site['admin_name'] ) {
1791 // Remove row data.
1792 unset( $temp_sites[ $k_site ] );
1793 $is_delete = true;
1794 break;
1795 }
1796 }
1797 }
1798
1799 // Save data to options table.
1800 if ( $is_delete ) {
1801 MainWP_DB::instance()->update_general_option( 'temp_import_sites', $temp_sites, 'array' );
1802 wp_die( wp_send_json_success( esc_html__( 'Delete import row successfully.', 'mainwp' ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1803 }
1804
1805 // In case of no delete.
1806 wp_die( wp_send_json_error( $error_msg ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1807 }
1808
1809 /**
1810 * Method ajax_import_website_add_client()
1811 *
1812 * Create client.
1813 */
1814 public function ajax_import_website_add_client() {
1815 $this->secure_request( 'mainwp_import_website_add_client' ); // Check secure.
1816 $error_msg = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1817 try {
1818 // Retrieve client data.
1819 $data = $this->mainwp_get_sanitized_post( 'client' );
1820 $site_id = $this->mainwp_get_sanitized_post( 'site_id' );
1821
1822 if ( empty( $data ) ) {
1823 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1824 }
1825
1826 $client_data = json_decode( $data, true );
1827 // Create client.
1828 $client = $this->mainwp_handle_create_client( $client_data );
1829 if ( $client ) {
1830 // Add groups website and client.
1831 if ( ! empty( $site_id ) ) {
1832 $this->mainwp_handle_selected_sites_for_client( $client, $site_id );
1833 }
1834
1835 wp_die( wp_send_json_success( esc_html__( 'Created client successfully.', 'mainwp' ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1836 }
1837 } catch ( \Exception $e ) {
1838 wp_die( wp_send_json_error( sanitize_text_field( $e->getMessage() ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1839 }
1840 // In case of no created.
1841 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1842 }
1843
1844 /**
1845 * Method ajax_import_website_add_client_no_site()
1846 *
1847 * Create client dont has a website.
1848 */
1849 public function ajax_import_website_add_client_no_site() {
1850 $this->secure_request( 'mainwp_import_website_add_client_no_site' ); // Check secure.
1851 $error_msg = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1852 try {
1853 $data = ! empty( $_POST['client'] ) ? rest_sanitize_array( $_POST['client'] ) : array(); //phpcs:ignore -- NonceVerification.
1854
1855 if ( empty( $data ) || ! is_array( $data ) ) {
1856 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1857 }
1858
1859 foreach ( $data as $val_data ) {
1860 $client_data = json_decode( stripslashes( $val_data ), true ); // Decode client data.
1861 $this->mainwp_handle_create_client( $client_data ); // Update or instert new client.
1862 }
1863 } catch ( \Exception $e ) {
1864 wp_die( wp_send_json_error( sanitize_text_field( $e->getMessage() ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1865 }
1866 // In case of no created.
1867 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1868 }
1869
1870 /**
1871 * Method ajax_clients_add_multi_client
1872 *
1873 * Create Multi Client form QSW.
1874 */
1875 public function ajax_clients_add_multi_client() {
1876 $error_msg = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1877 $this->check_security( 'mainwp_clients_add_multi_client' );
1878 $dataes = isset( $_POST['data'] ) ? $_POST['data'] : array(); //phpcs:ignore -- NonceVerification.
1879 try {
1880 if ( ! empty( $dataes ) ) {
1881 foreach ( $dataes as $val_data ) {
1882 $client_data = array(
1883 'image' => '',
1884 'name' => $val_data['client_name'] ?? '',
1885 'address_1' => '',
1886 'address_2' => '',
1887 'city' => '',
1888 'zip' => '',
1889 'state' => '',
1890 'country' => '',
1891 'note' => '',
1892 'selected_icon_info' => 'selected:wordpress;color:#34424d',
1893 'client_email' => $val_data['client_email'] ?? '',
1894 'client_phone' => '',
1895 'client_facebook' => '',
1896 'client_twitter' => '',
1897 'client_instagram' => '',
1898 'client_linkedin' => '',
1899 'suspended' => 0,
1900 'primary_contact_id' => 0,
1901 );
1902
1903 // Create client.
1904 $client = $this->mainwp_handle_create_client( $client_data );
1905
1906 // Create client successfy.
1907 if ( ! empty( $client ) && ! empty( $val_data['website_id'] ) ) {
1908 // Add groups website and client.
1909 $this->mainwp_handle_selected_sites_for_client( $client, $val_data['website_id'] );
1910 }
1911 // Create client contact.
1912 if ( ! empty( $val_data['contacts_field'] ) ) {
1913 $this->mainwp_handle_create_contact_for_client( $client, $val_data['contacts_field'] );
1914 }
1915 }
1916 wp_die( wp_send_json_success( esc_html__( 'Created client successfully.', 'mainwp' ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1917 }
1918 } catch ( \Exception $e ) {
1919 wp_die( wp_send_json_error( sanitize_text_field( $e->getMessage() ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1920 }
1921
1922 wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1923 }
1924
1925 /**
1926 * Method ajax_increase_connection_security
1927 */
1928 public function ajax_increase_connection_security() {
1929 $this->check_security( 'mainwp_increase_connection_security' );
1930 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
1931 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1932 // try to decrypt priv key.
1933 $de_privkey = MainWP_Encrypt_Data_Lib::instance()->decrypt_privkey( base64_decode( $website->privkey ), $website->id ); // phpcs:ignore -- NOSONAR - base64_encode trust.
1934 if ( empty( $de_privkey ) ) { // key is not encrypted.
1935 $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.
1936 if ( ! empty( $en_privkey['en_data'] ) ) {
1937 MainWP_DB::instance()->update_website_values(
1938 $website->id,
1939 array(
1940 'privkey' => base64_encode( $en_privkey['en_data'] ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- NOSONAR - base64_encode trust.
1941 )
1942 );
1943 }
1944 }
1945 }
1946 MainWP_DB::free_result( $websites );
1947 $this->hide_dashboard_notice_status( 'mainwp_secure_priv_key_notice' );
1948 delete_option( 'mainwp_not_start_encrypt_keys' );
1949 wp_die( wp_json_encode( array( 'success' => 1 ) ) );
1950 }
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 }
2041
2042
2043 /**
2044 * Method mainwp_get_sanitized_post()
2045 *
2046 * Sanitized post field.
2047 *
2048 * @param string $key key to get from POST.
2049 * @param string $callback cleaning method.
2050 *
2051 * @return mixed data value.
2052 */
2053 public function mainwp_get_sanitized_post( $key, $callback = 'sanitize_text_field' ) {
2054 return isset( $_POST[ $key ] ) ? $callback( wp_unslash( $_POST[ $key ] ) ) : ''; //phpcs:ignore -- NonceVerification.
2055 }
2056
2057 /**
2058 * Method mainwp_handle_create_client()
2059 *
2060 * Create new client or return client data.
2061 *
2062 * @uses MainWP_DB_Client::instance()->get_wp_client_by()
2063 * @uses MainWP_DB_Client::instance()->update_client()
2064 *
2065 * @param array $client_data new client creation data.
2066 *
2067 * @return object client data.
2068 */
2069 public function mainwp_handle_create_client( $client_data ) {
2070 // Check if client does not exist then create new one.
2071 $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_email', $client_data['client_email'], OBJECT );
2072 if ( empty( $client ) ) {
2073 $client = MainWP_DB_Client::instance()->update_client( $client_data ); // Create client.
2074 }
2075
2076 return $client;
2077 }
2078
2079 /**
2080 * Method mainwp_handle_selected_sites_for_client()
2081 *
2082 * Update selected sites for client.
2083 *
2084 * @uses MainWP_DB_Client::instance()->get_websites_by_client_ids()
2085 * @uses MainWP_DB_Client::instance()->update_selected_sites_for_client()
2086 *
2087 * @param object $client client data.
2088 * @param int $website_id id.
2089 */
2090 public function mainwp_handle_selected_sites_for_client( $client, $website_id ) {
2091 $sites_ids = MainWP_DB_Client::instance()->get_websites_by_client_ids( $client->client_id );
2092 $ids = isset( $sites_ids ) && ! empty( $sites_ids ) ? array_column( $sites_ids, 'id' ) : array();
2093 $ids[] = $website_id;
2094 MainWP_DB_Client::instance()->update_selected_sites_for_client( $client->client_id, $ids );
2095 }
2096
2097 /**
2098 * Method mainwp_handle_create_contact_for_client()
2099 *
2100 * Handle create contact for client.
2101 *
2102 * @uses MainWP_DB_Client::instance()->update_client_contact()
2103 * @uses MMainWP_DB_Client::instance()->update_client()
2104 *
2105 * @param object $client client data.
2106 * @param array $contacts_data contacts Data.
2107 */
2108 public function mainwp_handle_create_contact_for_client( $client, $contacts_data ) {
2109 $contacts = array_filter( $contacts_data );
2110 // Check required fields.
2111 if ( ( isset( $contacts['contact_name'] ) && '' !== $contacts['contact_name'] ) && ( isset( $contacts['contact_email'] ) && $contacts['contact_email'] ) ) {
2112 $contact_data = array(
2113 'contact_name' => $contacts['contact_name'] ?? '',
2114 'contact_email' => $contacts['contact_email'] ?? '',
2115 'contact_role' => $contacts['contact_role'] ?? '',
2116 'contact_client_id' => $client->client_id,
2117 'contact_phone' => '',
2118 'facebook' => '',
2119 'twitter' => '',
2120 'instagram' => '',
2121 'linkedin' => '',
2122 'contact_icon_info' => '',
2123 );
2124 $inserted = MainWP_DB_Client::instance()->update_client_contact( $contact_data ); // Create or update contact of client.
2125 // If the update is successful, the client will be updated again.
2126 if ( $inserted ) {
2127 $update = array(
2128 'client_id' => $client->client_id,
2129 'primary_contact_id' => $inserted->contact_id,
2130 );
2131 MainWP_DB_Client::instance()->update_client( $update );
2132 }
2133 }
2134 }
2135 }
2136