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

1,460 lines 50.5 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 /**
11 * Class MainWP_Post_Handler
12 *
13 * @package MainWP\Dashboard
14 *
15 * @uses \MainWP\Dashboard\MainWP_Post_Base_Handler
16 */
17 class MainWP_Post_Handler extends MainWP_Post_Base_Handler {
18
19 // phpcs:disable Generic.Metrics.CyclomaticComplexity -- This is the only way to achieve desired results, pull request solutions appreciated.
20
21 /**
22 * Private static variable to hold the single instance of the class.
23 *
24 * @static
25 *
26 * @var mixed Default null
27 */
28 private static $instance = null;
29
30 /**
31 * Method instance()
32 *
33 * Create a public static instance.
34 *
35 * @static
36 * @return MainWP_Post_Handler
37 */
38 public static function instance() {
39 if ( null === self::$instance ) {
40 self::$instance = new self();
41 }
42 return self::$instance;
43 }
44
45 /**
46 * Initiate all actions.
47 *
48 * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_class_name()
49 */
50 public function init() {
51 // Page: ManageSites.
52 $this->add_action( 'mainwp_notes_save', array( &$this, 'mainwp_notes_save' ) );
53
54 // Page: BulkAddUser.
55 $this->add_action( 'mainwp_bulkadduser', array( &$this, 'mainwp_bulkadduser' ) );
56 $this->add_action( 'mainwp_importuser', array( &$this, 'mainwp_importuser' ) );
57
58 // Widget: RightNow.
59 $this->add_action( 'mainwp_syncerrors_dismiss', array( &$this, 'mainwp_syncerrors_dismiss' ) );
60
61 if ( mainwp_current_user_have_right( 'dashboard', 'manage_security_issues' ) ) {
62 // Page: SecurityIssues.
63 $this->add_action( 'mainwp_security_issues_request', array( &$this, 'mainwp_security_issues_request' ) );
64 $this->add_action( 'mainwp_security_issues_fix', array( &$this, 'mainwp_security_issues_fix' ) );
65 $this->add_action( 'mainwp_security_issues_unfix', array( &$this, 'mainwp_security_issues_unfix' ) );
66 }
67
68 $this->add_action( 'mainwp_notice_status_update', array( &$this, 'mainwp_notice_status_update' ) );
69 $this->add_action( 'mainwp_dismiss_activate_notice', array( &$this, 'dismiss_activate_notice' ) );
70 $this->add_action( 'mainwp_status_saving', array( &$this, 'mainwp_status_saving' ) );
71 $this->add_action( 'mainwp_leftmenu_filter_group', array( &$this, 'mainwp_leftmenu_filter_group' ) );
72 $this->add_action( 'mainwp_widgets_order', array( &$this, 'ajax_widgets_order' ) );
73 $this->add_action( 'mainwp_save_settings', array( &$this, 'ajax_mainwp_save_settings' ) );
74 $this->add_action( 'mainwp_guided_tours_option_update', array( &$this, 'ajax_guided_tours_option_update' ) );
75
76 // Page: Recent Posts.
77 if ( mainwp_current_user_have_right( 'dashboard', 'manage_posts' ) ) {
78 $this->add_action( 'mainwp_post_unpublish', array( &$this, 'mainwp_post_unpublish' ) );
79 $this->add_action( 'mainwp_post_publish', array( &$this, 'mainwp_post_publish' ) );
80 $this->add_action( 'mainwp_post_trash', array( &$this, 'mainwp_post_trash' ) );
81 $this->add_action( 'mainwp_post_delete', array( &$this, 'mainwp_post_delete' ) );
82 $this->add_action( 'mainwp_post_restore', array( &$this, 'mainwp_post_restore' ) );
83 $this->add_action( 'mainwp_post_approve', array( &$this, 'mainwp_post_approve' ) );
84 }
85 $this->add_action( 'mainwp_post_addmeta', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_add_meta' ) );
86 // Page: Pages.
87 if ( mainwp_current_user_have_right( 'dashboard', 'manage_pages' ) ) {
88 $this->add_action( 'mainwp_page_unpublish', array( &$this, 'mainwp_page_unpublish' ) );
89 $this->add_action( 'mainwp_page_publish', array( &$this, 'mainwp_page_publish' ) );
90 $this->add_action( 'mainwp_page_trash', array( &$this, 'mainwp_page_trash' ) );
91 $this->add_action( 'mainwp_page_delete', array( &$this, 'mainwp_page_delete' ) );
92 $this->add_action( 'mainwp_page_restore', array( &$this, 'mainwp_page_restore' ) );
93 }
94 // Page: Users.
95 $this->add_action( 'mainwp_user_delete', array( &$this, 'mainwp_user_delete' ) );
96 $this->add_action( 'mainwp_user_edit', array( &$this, 'mainwp_user_edit' ) );
97 $this->add_action( 'mainwp_user_update_password', array( &$this, 'mainwp_user_update_password' ) );
98 $this->add_action( 'mainwp_user_update_user', array( &$this, 'mainwp_user_update_user' ) );
99
100 // Page: Posts.
101 $this->add_action( 'mainwp_posts_search', array( &$this, 'mainwp_posts_search' ) );
102 $this->add_action( 'mainwp_get_categories', array( &$this, 'mainwp_get_categories' ) );
103 $this->add_action( 'mainwp_post_get_edit', array( &$this, 'mainwp_post_get_edit' ) );
104 $this->add_action( 'mainwp_post_postingbulk', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_posting_posts' ) );
105 $this->add_action( 'mainwp_get_sites_of_groups', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_get_sites_of_groups' ) );
106
107 // Page: Pages.
108 $this->add_action( 'mainwp_pages_search', array( &$this, 'mainwp_pages_search' ) );
109 // Page: User.
110 $this->add_action( 'mainwp_users_search', array( &$this, 'mainwp_users_search' ) );
111
112 $this->add_action( 'mainwp_events_notice_hide', array( &$this, 'mainwp_events_notice_hide' ) );
113 $this->add_action( 'mainwp_showhide_sections', array( &$this, 'mainwp_showhide_sections' ) );
114 $this->add_action( 'mainwp_saving_status', array( &$this, 'mainwp_saving_status' ) );
115 $this->add_action( 'mainwp_autoupdate_and_trust_child', array( &$this, 'mainwp_autoupdate_and_trust_child' ) );
116 $this->add_action( 'mainwp_installation_warning_hide', array( &$this, 'mainwp_installation_warning_hide' ) );
117 $this->add_action( 'mainwp_force_destroy_sessions', array( &$this, 'mainwp_force_destroy_sessions' ) );
118 $this->add_action( 'mainwp_recheck_http', array( &$this, 'ajax_recheck_http' ) );
119 $this->add_action( 'mainwp_ignore_http_response', array( &$this, 'mainwp_ignore_http_response' ) );
120 $this->add_action( 'mainwp_disconnect_site', array( &$this, 'ajax_disconnect_site' ) );
121 $this->add_action( 'mainwp_manage_sites_display_rows', array( &$this, 'ajax_sites_display_rows' ) );
122 $this->add_action( 'mainwp_monitoring_sites_display_rows', array( &$this, 'ajax_monitoring_display_rows' ) );
123
124 $this->add_action_nonce( 'mainwp-common-nonce' );
125
126 // Page: Clients.
127 $this->add_action( 'mainwp_clients_add_client', array( &$this, 'mainwp_clients_add_client' ) );
128 $this->add_action( 'mainwp_clients_delete_client', array( &$this, 'mainwp_clients_delete_client' ) );
129
130 $this->add_action( 'mainwp_clients_save_field', array( &$this, 'mainwp_clients_save_field' ) );
131 $this->add_action( 'mainwp_clients_delete_general_field', array( &$this, 'mainwp_clients_delete_general_field' ) );
132 $this->add_action( 'mainwp_clients_delete_field', array( &$this, 'mainwp_clients_delete_field' ) );
133 $this->add_action( 'mainwp_clients_notes_save', array( &$this, 'mainwp_clients_notes_save' ) );
134 $this->add_action( 'mainwp_clients_suspend_client', array( &$this, 'mainwp_clients_suspend_client' ) );
135 $this->add_action( 'mainwp_refresh_icon', array( &$this, 'ajax_refresh_icon' ) );
136 $this->add_action( 'mainwp_upload_custom_icon', array( &$this, 'ajax_upload_custom_icon' ) );
137 $this->add_action( 'mainwp_select_custom_theme', array( &$this, 'ajax_select_custom_theme' ) );
138 $this->add_action( 'mainwp_site_actions_dismiss', array( &$this, 'ajax_site_actions_dismiss' ) );
139 $this->add_action( 'mainwp_delete_non_mainwp_actions', array( &$this, 'ajax_delete_non_mainwp_actions' ) );
140 $this->add_action( 'mainwp_import_demo_data', array( &$this, 'ajax_import_demo_data' ) );
141 $this->add_action( 'mainwp_delete_demo_data', array( &$this, 'ajax_delete_demo_data' ) );
142 $this->add_action( 'mainwp_prepare_renew_connections', array( MainWP_Connect_Helper::instance(), 'ajax_prepare_renew_connections' ) );
143 $this->add_action( 'mainwp_renew_connections', array( MainWP_Connect_Helper::instance(), 'ajax_renew_connections' ) );
144 }
145
146 /**
147 * Method add_post_action()
148 *
149 * Add ajax action.
150 *
151 * @param string $action Action to perform.
152 * @param string $callback Callback to perform.
153 */
154 public function add_post_action( $action, $callback ) {
155 $this->add_action( $action, $callback );
156 }
157
158 /**
159 * Method mainwp_installation_warning_hide()
160 *
161 * Hide the installation warning.
162 */
163 public function mainwp_installation_warning_hide() {
164 $this->secure_request( 'mainwp_installation_warning_hide' );
165
166 update_option( 'mainwp_installation_warning_hide_the_notice', 'yes' );
167 die( 'ok' );
168 }
169
170 /**
171 * Method mainwp_users_search()
172 *
173 * Search Post handler,
174 * Page: User.
175 *
176 * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
177 * @uses \MainWP\Dashboard\MainWP_User::render_table()
178 */
179 public function mainwp_users_search() {
180 $this->secure_request( 'mainwp_users_search' );
181 MainWP_Cache::init_session();
182
183 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
184 $role = isset( $_POST['role'] ) ? sanitize_text_field( wp_unslash( $_POST['role'] ) ) : '';
185 $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
186 $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
187 $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
188 $search = isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '';
189 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
190 MainWP_User::render_table( false, $role, $groups, $sites, $search, $clients );
191 die();
192 }
193
194 /**
195 * Method mainwp_posts_search()
196 *
197 * Search Post handler,
198 * Page: Posts.
199 *
200 * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
201 * @uses \MainWP\Dashboard\MainWP_Post::render_table()
202 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
203 */
204 public function mainwp_posts_search() { // phpcs:ignore -- complex.
205 $this->secure_request( 'mainwp_posts_search' );
206 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
207 $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' );
208 if ( isset( $_POST['maximum'] ) ) {
209 MainWP_Utility::update_option( 'mainwp_maximumPosts', isset( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 );
210 }
211 $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
212 $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( trim( wp_unslash( $_POST['dtsstart'] ) ) ) : '';
213 $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( trim( wp_unslash( $_POST['dtsstop'] ) ) ) : '';
214 $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
215 $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
216 $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
217 $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
218 $postId = isset( $_POST['postId'] ) ? sanitize_text_field( wp_unslash( $_POST['postId'] ) ) : '';
219 $userId = isset( $_POST['userId'] ) ? sanitize_text_field( wp_unslash( $_POST['userId'] ) ) : '';
220 $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
221 $table_content_only = isset( $_POST['table_content'] ) && wp_unslash( $_POST['table_content'] ) ? true : false;
222 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
223
224 MainWP_Cache::init_session();
225 if ( $table_content_only ) {
226 MainWP_Post::render_table_body( $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId, $post_type, $search_on, true, $clients );
227 } else {
228 MainWP_Post::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId, $post_type, $search_on, $clients );
229 }
230 die();
231 }
232 /**
233 * Method mainwp_pages_search()
234 *
235 * Search Post handler,
236 * Page: Pages.
237 *
238 * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
239 * @uses \MainWP\Dashboard\MainWP_Page::render_table()
240 *
241 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
242 */
243 public function mainwp_pages_search() {
244 $this->secure_request( 'mainwp_pages_search' );
245 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
246 if ( isset( $_POST['maximum'] ) ) {
247 MainWP_Utility::update_option( 'mainwp_maximumPages', intval( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 );
248 }
249 $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
250 $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) : '';
251 $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) : '';
252 $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
253 $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
254 $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
255 $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
256 $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
257 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
258 MainWP_Cache::init_session();
259 MainWP_Page::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $search_on, $clients );
260 die();
261 }
262
263 /**
264 * Method mainwp_get_categories()
265 *
266 * Get post/page categories.
267 *
268 * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_categories()
269 */
270 public function mainwp_get_categories() {
271 $this->secure_request( 'mainwp_get_categories' );
272 MainWP_Post_Page_Handler::ajax_handle_get_categories();
273 die();
274 }
275
276 /**
277 * Method mainwp_post_get_edit()
278 *
279 * Get post to edit.
280 *
281 * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_post()
282 */
283 public function mainwp_post_get_edit() {
284 $this->secure_request( 'mainwp_post_get_edit' );
285 MainWP_Post_Page_Handler::get_post();
286 die();
287 }
288
289 /**
290 * Method mainwp_user_delete()
291 *
292 * Delete User from Child Site,
293 * Page: Users.
294 *
295 * @uses \MainWP\Dashboard\MainWP_User::delete()
296 */
297 public function mainwp_user_delete() {
298 $this->secure_request( 'mainwp_user_delete' );
299 MainWP_User::delete();
300 }
301
302 /**
303 * Method mainwp_user_edit()
304 *
305 * Edit User from Child Site,
306 * Page: Users.
307 *
308 * @uses \MainWP\Dashboard\MainWP_User::edit()
309 */
310 public function mainwp_user_edit() {
311 $this->secure_request( 'mainwp_user_edit' );
312 MainWP_User::edit();
313 }
314
315 /**
316 * Method mainwp_user_update_password(
317 *
318 * Update User password from Child Site,
319 * Page: Users.
320 *
321 * @uses \MainWP\Dashboard\MainWP_User::update_password()
322 */
323 public function mainwp_user_update_password() {
324 $this->secure_request( 'mainwp_user_update_password' );
325 MainWP_User::update_password();
326 }
327
328 /**
329 * Method mainwp_user_update_user()
330 *
331 * Update User from Child Site,
332 * Page: Users.
333 *
334 * @uses \MainWP\Dashboard\MainWP_User::update_user()
335 */
336 public function mainwp_user_update_user() {
337 $this->secure_request( 'mainwp_user_update_user' );
338 MainWP_User::update_user();
339 }
340
341 /**
342 * Method mainwp_post_unpublish()
343 *
344 * Unpublish post from Child Site,
345 * Page: Recent Posts.
346 *
347 * @uses \MainWP\Dashboard\MainWP_Recent_Posts::unpublish()
348 */
349 public function mainwp_post_unpublish() {
350 $this->secure_request( 'mainwp_post_unpublish' );
351 MainWP_Recent_Posts::unpublish();
352 }
353
354 /**
355 * Method mainwp_post_publish()
356 *
357 * Publish post on Child Site,
358 * Page: Recent Posts.
359 *
360 * @uses \MainWP\Dashboard\MainWP_Recent_Posts::publish()
361 */
362 public function mainwp_post_publish() {
363 $this->secure_request( 'mainwp_post_publish' );
364 MainWP_Recent_Posts::publish();
365 }
366
367 /**
368 * Method mainwp_post_approve()
369 *
370 * Approve post on Child Site,
371 * Page: Recent Posts.
372 *
373 * @uses \MainWP\Dashboard\MainWP_Recent_Posts::approve()
374 */
375 public function mainwp_post_approve() {
376 $this->secure_request( 'mainwp_post_approve' );
377 MainWP_Recent_Posts::approve();
378 }
379
380 /**
381 * Method mainwp_post_trash()
382 *
383 * Trash post on Child Site,
384 * Page: Recent Posts.
385 *
386 * @uses \MainWP\Dashboard\MainWP_Recent_Posts::trash()
387 */
388 public function mainwp_post_trash() {
389 $this->secure_request( 'mainwp_post_trash' );
390
391 MainWP_Recent_Posts::trash();
392 }
393
394 /**
395 * Method mainwp_post_delete()
396 *
397 * Delete post on Child Site,
398 * Page: Recent Posts.
399 *
400 * @uses \MainWP\Dashboard\MainWP_Recent_Posts::delete()
401 */
402 public function mainwp_post_delete() {
403 $this->secure_request( 'mainwp_post_delete' );
404
405 MainWP_Recent_Posts::delete();
406 }
407
408 /**
409 * Method mainwp_post_restore()
410 *
411 * Restore post,
412 * Page: Recent Posts.
413 *
414 * @uses \MainWP\Dashboard\MainWP_Recent_Posts::restore()
415 */
416 public function mainwp_post_restore() {
417 $this->secure_request( 'mainwp_post_restore' );
418
419 MainWP_Recent_Posts::restore();
420 }
421
422 /**
423 * Method mainwp_page_unpublish()
424 *
425 * Unpublish page,
426 * Page: Recent Pages.
427 *
428 * @uses \MainWP\Dashboard\MainWP_Page::unpublish()
429 */
430 public function mainwp_page_unpublish() {
431 $this->secure_request( 'mainwp_page_unpublish' );
432 MainWP_Page::unpublish();
433 }
434
435 /**
436 * Method mainwp_page_publish()
437 *
438 * Publish page,
439 * Page: Recent Pages.
440 *
441 * @uses \MainWP\Dashboard\MainWP_Page::publish()
442 */
443 public function mainwp_page_publish() {
444 $this->secure_request( 'mainwp_page_publish' );
445 MainWP_Page::publish();
446 }
447
448 /**
449 * Method mainwp_page_trash()
450 *
451 * Trash page,
452 * Page: Recent Pages.
453 *
454 * @uses \MainWP\Dashboard\MainWP_Page::trash()
455 */
456 public function mainwp_page_trash() {
457 $this->secure_request( 'mainwp_page_trash' );
458 MainWP_Page::trash();
459 }
460
461 /**
462 * Method mainwp_page_delete()
463 *
464 * Delete page,
465 * Page: Recent Pages.
466 *
467 * @uses \MainWP\Dashboard\MainWP_Page::delete()
468 */
469 public function mainwp_page_delete() {
470 $this->secure_request( 'mainwp_page_delete' );
471 MainWP_Page::delete();
472 }
473
474 /**
475 * Method mainwp_page_restor()
476 *
477 * Restore page,
478 * Page: Recent Pages.
479 *
480 * @uses \MainWP\Dashboard\MainWP_Page::restore()
481 */
482 public function mainwp_page_restore() {
483 $this->secure_request( 'mainwp_page_restore' );
484 MainWP_Page::restore();
485 }
486
487 /**
488 * Method mainwp_notice_status_update()
489 *
490 * Hide after installation notices,
491 * (PHP version, Trust MainWP Child, Multisite Warning and OpenSSL warning).
492 *
493 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
494 */
495 public function mainwp_notice_status_update() {
496 $this->secure_request( 'mainwp_notice_status_update' );
497
498 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
499 $no_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : false;
500 if ( 'mail_failed' === $no_id ) {
501 MainWP_Utility::update_option( 'mainwp_notice_wp_mail_failed', 'hide' );
502 die( 'ok' );
503 }
504
505 /**
506 * Current user global.
507 *
508 * @global string
509 */
510 global $current_user;
511 $user_id = $current_user->ID;
512 if ( $user_id ) {
513 $status = get_user_option( 'mainwp_notice_saved_status' );
514 if ( ! is_array( $status ) ) {
515 $status = array();
516 }
517 if ( ! empty( $no_id ) ) {
518 $time_set = isset( $_POST['time_set'] ) && 1 === intval( $_POST['time_set'] ) ? true : false;
519 if ( $time_set ) {
520 $status[ $no_id ] = time();
521 } else {
522 $status[ $no_id ] = 1;
523 }
524 update_user_option( $user_id, 'mainwp_notice_saved_status', $status );
525 }
526 }
527 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
528 die( 1 );
529 }
530
531 /**
532 * Method mainwp_status_saving()
533 *
534 * Save last_sync_sites time() or mainwp_status_saved_values.
535 */
536 public function mainwp_status_saving() {
537 $this->secure_request( 'mainwp_status_saving' );
538 $values = get_option( 'mainwp_status_saved_values' );
539
540 if ( ! is_array( $values ) ) {
541 $values = array();
542 }
543
544 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
545 if ( ! isset( $_POST['status'] ) ) {
546 die( -1 );
547 }
548
549 if ( 'save_indicator_values' === $_POST['status'] ) {
550
551 if ( ! empty( $_POST['name'] ) ) {
552 $current_values = is_array( $values ) && isset( $values['save_indicator_values'] ) && ! empty( $values['save_indicator_values'] ) ? json_decode( $values['save_indicator_values'], true ) : array();
553 if ( ! is_array( $current_values ) ) {
554 $current_values = array();
555 }
556 $current_values[ sanitize_text_field( wp_unslash( $_POST['name'] ) ) ] = isset( $_POST['value'] ) ? intval( wp_unslash( $_POST['value'] ) ) : 0;
557
558 $values['save_indicator_values'] = wp_json_encode( $current_values );
559 update_option( 'mainwp_status_saved_values', $values );
560 die( 'ok' );
561 }
562 die( 'failed' );
563 }
564
565 if ( 'last_sync_sites' === $_POST['status'] ) {
566 if ( isset( $_POST['isGlobalSync'] ) && ! empty( $_POST['isGlobalSync'] ) ) {
567 update_option( 'mainwp_last_synced_all_sites', time() );
568
569 /**
570 * Action: mainwp_synced_all_sites
571 *
572 * Fires upon successfull synchronization process.
573 *
574 * @since 3.5.1
575 */
576 do_action( 'mainwp_synced_all_sites' );
577 }
578 die( 'ok' );
579 }
580
581 $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
582 $value = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
583 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
584
585 if ( ! empty( $status ) ) {
586 if ( empty( $value ) ) {
587 if ( isset( $values[ $status ] ) ) {
588 unset( $values[ $status ] );
589 }
590 } else {
591 $values[ $status ] = $value;
592 }
593 update_option( 'mainwp_status_saved_values', $values );
594 }
595
596 die( 'ok' );
597 }
598
599 /**
600 * Method ajax_widget_order()
601 *
602 * Update saved widget order.
603 */
604 public function ajax_widgets_order() {
605
606 $this->secure_request( 'mainwp_widgets_order' );
607 $user = wp_get_current_user();
608 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
609 if ( $user && ! empty( $_POST['page'] ) ) {
610 $page = isset( $_POST['page'] ) ? sanitize_text_field( wp_unslash( $_POST['page'] ) ) : '';
611 $order = isset( $_POST['order'] ) ? sanitize_text_field( wp_unslash( $_POST['order'] ) ) : '';
612 $wgids = isset( $_POST['wgids'] ) ? sanitize_text_field( wp_unslash( $_POST['wgids'] ) ) : '';
613
614 $wgs_orders = array();
615
616 if ( ! empty( $wgids ) ) {
617 $wgids = json_decode( $wgids, true );
618 $order = json_decode( $order, true );
619 if ( is_array( $wgids ) && is_array( $order ) ) {
620 foreach ( $wgids as $idx => $wgid ) {
621 if ( isset( $order[ $idx ] ) ) {
622 $pre = 'widget-';
623 if ( 0 === strpos( $wgid, $pre ) ) {
624 $wgid = substr( $wgid, strlen( $pre ) );
625 }
626 $wgs_orders[ $wgid ] = $order[ $idx ];
627 }
628 }
629 }
630 }
631
632 if ( 'mainwp_page_manageclients' === $page ) {
633 $item_id = isset( $_POST['item_id'] ) ? intval( $_POST['item_id'] ) : 0;
634 $sorted_array = get_user_option( 'mainwp_widgets_sorted_' . strtolower( $page ) );
635 if ( ! empty( $sorted_array ) ) {
636 $sorted_array = json_decode( $sorted_array, true );
637 }
638 if ( ! is_array( $sorted_array ) ) {
639 $sorted_array = array();
640 }
641 $sorted_array[ $item_id ] = $wgs_orders;
642 update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $sorted_array ), true );
643 } else {
644 update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $wgs_orders ), true );
645 }
646 die( 'ok' );
647 }
648 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
649 die( -1 );
650 }
651
652 /**
653 * Method ajax_mainwp_save_settings()
654 *
655 * Update saved MainWP Settings.
656 *
657 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
658 */
659 public function ajax_mainwp_save_settings() {
660 $this->secure_request( 'mainwp_save_settings' );
661 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
662 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
663 if ( ! empty( $name ) ) {
664 $option_name = 'mainwp_' . $name;
665 $val = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
666 MainWP_Utility::update_option( $option_name, $val );
667 }
668 // phpcs:enable
669 die( 'ok' );
670 }
671
672 /**
673 * Method ajax_guided_tours_option_update()
674 *
675 * Update saved MainWP Settings.
676 *
677 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
678 */
679 public function ajax_guided_tours_option_update() {
680 $this->secure_request( 'mainwp_guided_tours_option_update' );
681 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
682 $enable = isset( $_POST['enable'] ) ? intval( $_POST['enable'] ) : 0;
683 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
684 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', $enable );
685 die( 'ok' );
686 }
687
688 /**
689 * Method mainwp_leftmenu_filter_group()
690 *
691 * MainWP left menu filter by group.
692 *
693 * @uses \MainWP\Dashboard\MainWP_DB::query()
694 * @uses \MainWP\Dashboard\MainWP_DB::get_websites_by_group_id()
695 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
696 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
697 */
698 public function mainwp_leftmenu_filter_group() {
699 $this->secure_request( 'mainwp_leftmenu_filter_group' );
700
701 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
702 $gid = isset( $_POST['group_id'] ) ? intval( $_POST['group_id'] ) : false;
703 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
704
705 if ( ! empty( $gid ) ) {
706 $ids = '';
707 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $gid, true ) );
708 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
709 $ids .= $website->id . ',';
710 }
711 MainWP_DB::free_result( $websites );
712 $ids = rtrim( $ids, ',' );
713 die( $ids ); // phpcs:ignore WordPress.Security.EscapeOutput
714 }
715 die( '' );
716 }
717
718 /**
719 * Method dismiss_activate_notice()
720 *
721 * Dismiss activate notice.
722 */
723 public function dismiss_activate_notice() {
724 $this->secure_request( 'mainwp_dismiss_activate_notice' );
725
726 /**
727 * Current user global.
728 *
729 * @global string
730 */
731 global $current_user;
732 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
733 $user_id = $current_user->ID;
734 $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
735 if ( $user_id && ! empty( $slug ) ) {
736 $activate_notices = get_user_option( 'mainwp_hide_activate_notices' );
737 if ( ! is_array( $activate_notices ) ) {
738 $activate_notices = array();
739 }
740
741 $activate_notices[ $slug ] = time();
742 update_user_option( $user_id, 'mainwp_hide_activate_notices', $activate_notices );
743 }
744 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
745 die( 1 );
746 }
747
748
749
750 /**
751 * Method mainwp_security_issues_request()
752 *
753 * Post handler for,
754 * Page: SecurityIssues.
755 *
756 * @uses \MainWP\Dashboard\MainWP_Exception
757 * @uses \MainWP\Dashboard\MainWP_Security_Issues::fetch_security_issues()
758 */
759 public function mainwp_security_issues_request() {
760 $this->secure_request( 'mainwp_security_issues_request' );
761
762 try {
763 wp_send_json( array( 'result' => MainWP_Security_Issues::fetch_security_issues() ) );
764 } catch ( MainWP_Exception $e ) {
765 die(
766 wp_json_encode(
767 array(
768 'error' => array(
769 'message' => $e->getMessage(),
770 'extra' => $e->get_message_extra(),
771 ),
772 )
773 )
774 );
775 }
776 }
777
778 /**
779 * Method mainwp_security_issues_fix()
780 *
781 * Post handler for 'fix issues',
782 * Page: SecurityIssues.
783 *
784 * @uses \MainWP\Dashboard\MainWP_Exception
785 * @uses \MainWP\Dashboard\MainWP_Security_Issues::fix_security_issue()
786 */
787 public function mainwp_security_issues_fix() {
788 $this->secure_request( 'mainwp_security_issues_fix' );
789
790 try {
791 wp_send_json( array( 'result' => MainWP_Security_Issues::fix_security_issue() ) );
792 } catch ( MainWP_Exception $e ) {
793 die(
794 wp_json_encode(
795 array(
796 'error' => array(
797 'message' => $e->getMessage(),
798 'extra' => $e->get_message_extra(),
799 ),
800 )
801 )
802 );
803 }
804 }
805
806 /**
807 * Method mainwp_security_issues_unfix()
808 *
809 * Post handler for 'unfix issues',
810 * Page: SecurityIssues.
811 *
812 * @uses \MainWP\Dashboard\MainWP_Exception
813 * @uses \MainWP\Dashboard\MainWP_Security_Issues::unfix_security_issue()
814 */
815 public function mainwp_security_issues_unfix() {
816 $this->secure_request( 'mainwp_security_issues_unfix' );
817
818 try {
819 wp_send_json( array( 'result' => MainWP_Security_Issues::unfix_security_issue() ) );
820 } catch ( MainWP_Exception $e ) {
821 die(
822 wp_json_encode(
823 array(
824 'error' => array(
825 'message' => $e->getMessage(),
826 'extra' => $e->get_message_extra(),
827 ),
828 )
829 )
830 );
831 }
832 }
833
834 /**
835 * Method ajax_disconnect_site()
836 *
837 * Disconnect Child Site.
838 *
839 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
840 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
841 */
842 public function ajax_disconnect_site() {
843 $this->secure_request( 'mainwp_disconnect_site' );
844 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
845 $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
846 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
847
848 if ( empty( $siteid ) ) {
849 die( wp_json_encode( array( 'error' => 'Error: site id empty' ) ) );
850 }
851
852 $website = MainWP_DB::instance()->get_website_by_id( $siteid );
853
854 if ( ! $website ) {
855 die( wp_json_encode( array( 'error' => 'Not found site' ) ) );
856 }
857
858 try {
859 $information = MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
860 } catch ( \Exception $e ) {
861 $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
862 }
863
864 wp_send_json( $information );
865 }
866
867 /**
868 * Method ajax_sites_display_rows()
869 *
870 * Display rows via ajax,
871 * Page: Manage Sites.
872 *
873 * @uses \MainWP\Dashboard\MainWP_Manage_Sites::ajax_optimize_display_rows()
874 */
875 public function ajax_sites_display_rows() {
876 $this->secure_request( 'mainwp_manage_sites_display_rows' );
877 MainWP_Manage_Sites::ajax_optimize_display_rows();
878 }
879
880 /**
881 * Method ajax_monitoring_display_rows()
882 *
883 * Display rows via ajax,
884 * Page: Monitoring Sites.
885 *
886 * @uses \MainWP\Dashboard\MainWP_Monitoring::ajax_optimize_display_rows()
887 */
888 public function ajax_monitoring_display_rows() {
889 $this->secure_request( 'mainwp_monitoring_sites_display_rows' );
890 MainWP_Monitoring::ajax_optimize_display_rows();
891 }
892
893
894 /**
895 * Method mainwp_bulkadduser()
896 *
897 * Bulk Add User for,
898 * Page: BulkAddUser.
899 *
900 * @uses \MainWP\Dashboard\MainWP_User::do_bulk_add()
901 */
902 public function mainwp_bulkadduser() {
903 $this->check_security( 'mainwp_bulkadduser' );
904 MainWP_User::do_bulk_add();
905 die();
906 }
907
908 /**
909 * Method mainwp_importuser()
910 *
911 * Import user.
912 *
913 * @uses \MainWP\Dashboard\MainWP_User::do_import()
914 */
915 public function mainwp_importuser() {
916 $this->secure_request( 'mainwp_importuser' );
917 MainWP_User::do_import();
918 }
919
920 /**
921 * Method mainwp_clients_add_client()
922 *
923 * Add Client for,
924 * Page: BulkAddClient.
925 */
926 public function mainwp_clients_add_client() {
927 $this->check_security( 'mainwp_clients_add_client' );
928 MainWP_Client::add_client();
929 die();
930 }
931
932 /**
933 * Method mainwp_clients_delete_client()
934 *
935 * Add Client for,
936 * Page: BulkAddClient.
937 */
938 public function mainwp_clients_delete_client() {
939 $this->check_security( 'mainwp_clients_delete_client' );
940 $ret = array( 'success' => false );
941 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
942 $client_id = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
943 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
944 if ( $client_id ) {
945 MainWP_DB_Client::instance()->delete_client( $client_id );
946 $ret['success'] = 'SUCCESS';
947 $ret['result'] = esc_html__( 'Client removed successfully.', 'mainwp' );
948 } else {
949 $ret['result'] = esc_html__( 'Client ID empty.', 'mainwp' );
950 }
951
952 echo wp_json_encode( $ret );
953 exit;
954 }
955
956 /**
957 * Method mainwp_clients_save_field()
958 *
959 * Save client custom fields.
960 */
961 public function mainwp_clients_save_field() {
962 $this->check_security( 'mainwp_clients_save_field' );
963 MainWP_Client::save_client_field();
964 die();
965 }
966
967
968 /**
969 * Method mainwp_clients_delete_general_field()
970 *
971 * Delete client general fields.
972 */
973 public function mainwp_clients_delete_general_field() {
974 $this->check_security( 'mainwp_clients_delete_general_field' );
975 $ret = array( 'success' => false );
976 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
977 $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
978 $client_id = 0; // 0 general fields.
979 if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
980 $ret['success'] = true;
981 }
982 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
983 echo wp_json_encode( $ret );
984 exit;
985 }
986
987
988 /**
989 * Method mainwp_clients_delete_field()
990 *
991 * Delete client custom fields.
992 */
993 public function mainwp_clients_delete_field() {
994 $this->check_security( 'mainwp_clients_delete_field' );
995 $ret = array( 'success' => false );
996 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
997 $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
998 $client_id = isset( $_POST['client_id'] ) ? intval( $_POST['client_id'] ) : 0; // $client_id > 0, individual token.
999 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1000 if ( $client_id ) {
1001 if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
1002 $ret['success'] = true;
1003 }
1004 }
1005 echo wp_json_encode( $ret );
1006 exit;
1007 }
1008
1009 /**
1010 * Method mainwp_notes_save()
1011 *
1012 * Post handler for save notes on,
1013 * Page: Manage Sites.
1014 *
1015 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1016 */
1017 public function mainwp_notes_save() {
1018 $this->secure_request( 'mainwp_notes_save' );
1019 MainWP_Manage_Sites_Handler::save_note();
1020 }
1021
1022 /**
1023 * Method mainwp_clients_notes_save()
1024 *
1025 * Post handler for save notes on,
1026 * Page: Manage Sites.
1027 *
1028 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1029 */
1030 public function mainwp_clients_notes_save() {
1031 $this->secure_request( 'mainwp_clients_notes_save' );
1032 MainWP_Client::save_note();
1033 }
1034
1035 /**
1036 * Method mainwp_clients_suspend_client()
1037 *
1038 * Post handler for suspend client,
1039 * Page: Manage Sites.
1040 *
1041 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1042 */
1043 public function mainwp_clients_suspend_client() {
1044 $this->secure_request( 'mainwp_clients_suspend_client' );
1045 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1046 $clientid = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
1047 $suspended = isset( $_POST['suspend_status'] ) && ! empty( $_POST['suspend_status'] ) ? 1 : 0;
1048 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1049
1050 if ( empty( $clientid ) ) {
1051 wp_die( 'Error - empty client id!' );
1052 }
1053
1054 $params = array(
1055 'client_id' => $clientid,
1056 'suspended' => $suspended,
1057 );
1058
1059 MainWP_DB_Client::instance()->update_client( $params );
1060
1061 $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $clientid );
1062
1063 /**
1064 * Fires immediately after update client suspend/unsuspend.
1065 *
1066 * @since 4.5.1.1
1067 *
1068 * @param object $client client data.
1069 * @param bool $suspended true|false.
1070 */
1071 do_action( 'mainwp_client_suspend', $client, $suspended );
1072
1073 MainWP_DB_Client::instance()->suspend_unsuspend_websites_by_client_id( $clientid, $suspended );
1074
1075 wp_die( 'success' );
1076 }
1077
1078 /**
1079 * Method mainwp_syncerrors_dismiss()
1080 *
1081 * Dismiss Sync errors for,
1082 * Widget: RightNow.
1083 *
1084 * @uses \MainWP\Dashboard\MainWP_Updates_Overview::dismiss_sync_errors()
1085 */
1086 public function mainwp_syncerrors_dismiss() {
1087
1088 $this->secure_request( 'mainwp_syncerrors_dismiss' );
1089
1090 try {
1091 die( wp_json_encode( array( 'result' => MainWP_Updates_Overview::dismiss_sync_errors() ) ) );
1092 } catch ( \Exception $e ) {
1093 die( wp_json_encode( array( 'error' => $e->getMessage() ) ) );
1094 }
1095 }
1096
1097 /**
1098 * Method mainwp_events_notice_hide()
1099 *
1100 * Hide events notice.
1101 */
1102 public function mainwp_events_notice_hide() {
1103 $this->secure_request( 'mainwp_events_notice_hide' );
1104 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1105 if ( isset( $_POST['notice'] ) ) {
1106 $current_options = get_option( 'mainwp_showhide_events_notice' );
1107 if ( ! is_array( $current_options ) ) {
1108 $current_options = array();
1109 }
1110 if ( 'first_site' === $_POST['notice'] ) {
1111 update_option( 'mainwp_first_site_events_notice', '' );
1112 } elseif ( 'request_reviews1' === $_POST['notice'] ) {
1113 $current_options['request_reviews1'] = 15;
1114 $current_options['request_reviews1_starttime'] = time();
1115 } elseif ( 'request_reviews1_forever' === $_POST['notice'] || 'request_reviews2_forever' === $_POST['notice'] ) {
1116 $current_options['request_reviews1'] = 'forever';
1117 $current_options['request_reviews2'] = 'forever';
1118 } elseif ( 'request_reviews2' === $_POST['notice'] ) {
1119 $current_options['request_reviews2'] = 15;
1120 $current_options['request_reviews2_starttime'] = time();
1121 } elseif ( 'trust_child' === $_POST['notice'] ) {
1122 $current_options['trust_child'] = 1;
1123 } elseif ( 'multi_site' === $_POST['notice'] ) {
1124 $current_options['hide_multi_site_notice'] = 1;
1125 }
1126 update_option( 'mainwp_showhide_events_notice', $current_options );
1127 }
1128 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1129 die( 'ok' );
1130 }
1131
1132 /**
1133 * Method mainwp_showhide_sections()
1134 *
1135 * Show/Hide sections.
1136 */
1137 public function mainwp_showhide_sections() {
1138 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1139 if ( isset( $_POST['sec'] ) && isset( $_POST['status'] ) ) {
1140 $opts = get_option( 'mainwp_opts_showhide_sections' );
1141 if ( ! is_array( $opts ) ) {
1142 $opts = array();
1143 }
1144 $opts[ sanitize_text_field( wp_unslash( $_POST['sec'] ) ) ] = sanitize_text_field( wp_unslash( $_POST['status'] ) );
1145 update_option( 'mainwp_opts_showhide_sections', $opts );
1146 die( 'ok' );
1147 }
1148 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1149 die( 'failed' );
1150 }
1151
1152 /**
1153 * Method mainwp_saving_status()
1154 *
1155 * MainWP Saving Status.
1156 */
1157 public function mainwp_saving_status() {
1158 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1159 if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'mainwp_ajax' ) ) {
1160 die( esc_html__( 'WP nonce could not be verified. Please reload the page and try again.', 'mainwp' ) );
1161 }
1162 $saving_status = isset( $_POST['saving_status'] ) ? sanitize_text_field( wp_unslash( $_POST['saving_status'] ) ) : false;
1163 if ( ! empty( $saving_status ) ) {
1164 $current_options = get_option( 'mainwp_opts_saving_status' );
1165 if ( ! is_array( $current_options ) ) {
1166 $current_options = array();
1167 }
1168 if ( isset( $_POST['value'] ) ) {
1169 $current_options[ $saving_status ] = sanitize_text_field( wp_unslash( $_POST['value'] ) );
1170 }
1171 update_option( 'mainwp_opts_saving_status', $current_options );
1172 }
1173 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1174 die( 'ok' );
1175 }
1176
1177 /**
1178 * Method ajax_recheck_http()
1179 *
1180 * Recheck Child Site http status code & message.
1181 *
1182 * @uses \MainWP\Dashboard\MainWP_Connect::check_ignored_http_code()
1183 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1184 * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_check_website()
1185 */
1186 public function ajax_recheck_http() {
1187 $this->check_security( 'mainwp_recheck_http' );
1188 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1189 if ( ! isset( $_POST['websiteid'] ) || empty( $_POST['websiteid'] ) ) {
1190 die( -1 );
1191 }
1192
1193 $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['websiteid'] ) );
1194 if ( empty( $website ) ) {
1195 die( -1 );
1196 }
1197 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1198
1199 $result = MainWP_Monitoring_Handler::handle_check_website( $website );
1200 $http_code = ( is_array( $result ) && isset( $result['httpCode'] ) ) ? $result['httpCode'] : 0;
1201 $check_result = MainWP_Connect::check_ignored_http_code( $http_code );
1202 die(
1203 wp_json_encode(
1204 array(
1205 'httpcode' => esc_html( $http_code ),
1206 'status' => $check_result ? 1 : 0,
1207 )
1208 )
1209 );
1210 }
1211
1212 /**
1213 * Method mainwp_ignore_http_response()
1214 *
1215 * Ignore Child Site https response.
1216 *
1217 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1218 * @uses \MainWP\Dashboard\MainWP_DB::update_website_values()
1219 */
1220 public function mainwp_ignore_http_response() {
1221 $this->check_security( 'mainwp_ignore_http_response' );
1222 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1223 $siteid = isset( $_POST['websiteid'] ) ? intval( $_POST['websiteid'] ) : false;
1224 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1225 if ( empty( $siteid ) ) {
1226 die( -1 );
1227 }
1228
1229 $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1230 if ( empty( $website ) ) {
1231 die( -1 );
1232 }
1233
1234 MainWP_DB::instance()->update_website_values( $website->id, array( 'http_response_code' => '-1' ) );
1235 die( wp_json_encode( array( 'ok' => 1 ) ) );
1236 }
1237
1238 /**
1239 * Method mainwp_autoupdate_and_trust_child()
1240 *
1241 * Set MainWP Child Plugin to Trusted & AutoUpdate.
1242 *
1243 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_plugin()
1244 */
1245 public function mainwp_autoupdate_and_trust_child() {
1246 $this->secure_request( 'mainwp_autoupdate_and_trust_child' );
1247 if ( 1 !== (int) get_option( 'mainwp_pluginAutomaticDailyUpdate' ) ) {
1248 update_option( 'mainwp_pluginAutomaticDailyUpdate', 1 );
1249 }
1250 MainWP_Plugins_Handler::trust_plugin( 'mainwp-child/mainwp-child.php' );
1251 die( 'ok' );
1252 }
1253
1254 /**
1255 * Method mainwp_force_destroy_sessions()
1256 *
1257 * Force destroy sessions.
1258 *
1259 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
1260 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1261 *
1262 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
1263 */
1264 public function mainwp_force_destroy_sessions() {
1265 $this->secure_request( 'mainwp_force_destroy_sessions' );
1266
1267 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1268 $website_id = ( isset( $_POST['website_id'] ) ? (int) $_POST['website_id'] : 0 );
1269 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1270 if ( ! MainWP_DB::instance()->get_website_by_id( $website_id ) ) {
1271 die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'This website does not exist.', 'mainwp' ) ) ) ) );
1272 }
1273
1274 $website = MainWP_DB::instance()->get_website_by_id( $website_id );
1275 if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
1276 die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'You cannot edit this website.', 'mainwp' ) ) ) ) );
1277 }
1278
1279 try {
1280 $information = MainWP_Connect::fetch_url_authed(
1281 $website,
1282 'settings_tools',
1283 array(
1284 'action' => 'force_destroy_sessions',
1285 )
1286 );
1287 } catch ( \Exception $e ) {
1288 $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
1289 }
1290
1291 wp_send_json( $information );
1292 }
1293
1294 /**
1295 * Method ajax_refresh_icon()
1296 */
1297 public function ajax_refresh_icon() {
1298 $this->secure_request( 'mainwp_refresh_icon' );
1299 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1300 $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1301 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1302 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1303
1304 if ( empty( $slug ) ) {
1305 wp_die( 'failed' );
1306 }
1307
1308 $fet_icon = MainWP_System_Utility::handle_get_icon( $slug, $type );
1309
1310 if ( ! empty( $fet_icon ) ) {
1311 wp_die( 'success' );
1312 } else {
1313 wp_die( 'failed' );
1314 }
1315 }
1316
1317 /**
1318 * Method ajax_upload_custom_icon()
1319 */
1320 public function ajax_upload_custom_icon() {
1321 $this->secure_request( 'mainwp_upload_custom_icon' );
1322 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1323 $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1324 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1325 $delete = isset( $_POST['delete'] ) ? intval( $_POST['delete'] ) : 0;
1326
1327 if ( empty( $slug ) || ( 'plugin' !== $type && 'theme' !== $type ) ) {
1328 wp_die( 'invalid data!' );
1329 }
1330
1331 $sub_folder = '';
1332
1333 if ( 'plugin' === $type ) {
1334 $sub_folder = 'plugin-icons';
1335 } elseif ( 'theme' === $type ) {
1336 $sub_folder = 'theme-icons';
1337 } else {
1338 wp_die( wp_json_encode( array( 'result' => 'invalid' ) ) );
1339 }
1340
1341 if ( $delete ) {
1342 MainWP_System_Utility::update_cached_icons( '', $slug, $type, true );
1343 wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1344 }
1345
1346 $output = isset( $_FILES['mainwp_upload_icon_uploader'] ) ? MainWP_System_Utility::handle_upload_image( $sub_folder, $_FILES['mainwp_upload_icon_uploader'], 0 ) : null;
1347 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1348
1349 $uploaded_icon = 'NOTCHANGE';
1350 if ( is_array( $output ) && isset( $output['filename'] ) && ! empty( $output['filename'] ) ) {
1351 $uploaded_icon = $output['filename'];
1352 }
1353
1354 if ( 'NOTCHANGE' !== $uploaded_icon ) {
1355 MainWP_System_Utility::update_cached_icons( $uploaded_icon, $slug, $type, true );
1356 wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1357 } else {
1358 wp_die( wp_json_encode( array( 'result' => 'failed' ) ) );
1359 }
1360 }
1361
1362 /**
1363 * Method ajax_select_custom_theme()
1364 */
1365 public function ajax_select_custom_theme() {
1366 $this->secure_request( 'mainwp_select_custom_theme' );
1367 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1368 $theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : '';
1369 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1370 if ( empty( $theme ) ) {
1371 wp_die( 'failed' );
1372 }
1373
1374 $user = wp_get_current_user();
1375 if ( empty( $user ) || empty( $user->ID ) ) {
1376 wp_die( 'failed' );
1377 }
1378
1379 update_user_option( $user->ID, 'mainwp_selected_theme', $theme );
1380 wp_die( 'success' );
1381 }
1382
1383
1384 /**
1385 * Method ajax_site_actions_dismiss()
1386 */
1387 public function ajax_site_actions_dismiss() {
1388 $this->secure_request( 'mainwp_site_actions_dismiss' );
1389 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1390 $action_id = isset( $_POST['action_id'] ) ? intval( $_POST['action_id'] ) : 0;
1391 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1392
1393 if ( empty( $action_id ) ) {
1394 wp_die( 'failed' );
1395 }
1396 $update = array(
1397 'dismiss' => 1,
1398 );
1399 MainWP_DB_Site_Actions::instance()->update_action_by_id( $action_id, $update );
1400 wp_die( 'success' );
1401 }
1402
1403 /**
1404 * Method ajax_site_actions_dismiss()
1405 */
1406 public function ajax_delete_non_mainwp_actions() {
1407 $this->secure_request( 'mainwp_delete_non_mainwp_actions' );
1408 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1409 $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
1410 if ( empty( $siteid ) ) {
1411 wp_die( wp_json_encode( array( 'error' => 'Empty site ID' ) ) );
1412 }
1413 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1414 $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1415 $success = false;
1416 $error = '';
1417 try {
1418 $response = MainWP_Connect::fetch_url_authed( $website, 'delete_actions', array( 'del' => 'act' ) );
1419 if ( is_array( $response ) ) {
1420 if ( isset( $response['success'] ) ) {
1421 $success = true;
1422 } elseif ( isset( $response['error'] ) ) {
1423 $error = $response['error'];
1424 }
1425 }
1426 } catch ( \Exception $e ) {
1427 // ok!
1428 }
1429 if ( $success ) {
1430 MainWP_DB_Site_Actions::instance()->delete_action_by( 'wpid', $siteid );
1431 wp_die( wp_json_encode( array( 'success' => 'ok' ) ) );
1432 }
1433
1434 if ( empty( $error ) ) {
1435 $error = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1436 }
1437 wp_die( wp_json_encode( array( 'error' => $error ) ) );
1438 }
1439
1440 /**
1441 * Method ajax_import_demo_data().
1442 */
1443 public function ajax_import_demo_data() {
1444 $this->secure_request( 'mainwp_import_demo_data' );
1445 $data = MainWP_Demo_Handle::get_instance()->import_data_demo();
1446 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 1 );
1447 wp_die( wp_json_encode( $data ) );
1448 }
1449
1450 /**
1451 * Method ajax_delete_demo_data().
1452 */
1453 public function ajax_delete_demo_data() {
1454 $this->secure_request( 'mainwp_delete_demo_data' );
1455 $data = MainWP_Demo_Handle::get_instance()->delete_data_demo();
1456 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 0 );
1457 wp_die( wp_json_encode( $data ) );
1458 }
1459 }
1460