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

1,440 lines 49.8 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::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 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
541 if ( ! isset( $_POST['status'] ) ) {
542 die( -1 );
543 }
544
545 if ( 'last_sync_sites' === $_POST['status'] ) {
546 if ( isset( $_POST['isGlobalSync'] ) && ! empty( $_POST['isGlobalSync'] ) ) {
547 update_option( 'mainwp_last_synced_all_sites', time() );
548
549 /**
550 * Action: mainwp_synced_all_sites
551 *
552 * Fires upon successfull synchronization process.
553 *
554 * @since 3.5.1
555 */
556 do_action( 'mainwp_synced_all_sites' );
557 }
558 die( 'ok' );
559 }
560
561 $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
562 $value = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
563 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
564
565 if ( ! empty( $status ) ) {
566 if ( empty( $value ) ) {
567 if ( isset( $values[ $status ] ) ) {
568 unset( $values[ $status ] );
569 }
570 } else {
571 $values[ $status ] = $value;
572 }
573 update_option( 'mainwp_status_saved_values', $values );
574 }
575
576 die( 'ok' );
577 }
578
579 /**
580 * Method ajax_widget_order()
581 *
582 * Update saved widget order.
583 */
584 public function ajax_widgets_order() {
585
586 $this->secure_request( 'mainwp_widgets_order' );
587 $user = wp_get_current_user();
588 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
589 if ( $user && ! empty( $_POST['page'] ) ) {
590 $page = isset( $_POST['page'] ) ? sanitize_text_field( wp_unslash( $_POST['page'] ) ) : '';
591 $order = isset( $_POST['order'] ) ? sanitize_text_field( wp_unslash( $_POST['order'] ) ) : '';
592 $wgids = isset( $_POST['wgids'] ) ? sanitize_text_field( wp_unslash( $_POST['wgids'] ) ) : '';
593
594 $wgs_orders = array();
595
596 if ( ! empty( $wgids ) ) {
597 $wgids = json_decode( $wgids, true );
598 $order = json_decode( $order, true );
599 if ( is_array( $wgids ) && is_array( $order ) ) {
600 foreach ( $wgids as $idx => $wgid ) {
601 if ( isset( $order[ $idx ] ) ) {
602 $pre = 'widget-';
603 if ( 0 === strpos( $wgid, $pre ) ) {
604 $wgid = substr( $wgid, strlen( $pre ) );
605 }
606 $wgs_orders[ $wgid ] = $order[ $idx ];
607 }
608 }
609 }
610 }
611
612 if ( 'mainwp_page_manageclients' === $page ) {
613 $item_id = isset( $_POST['item_id'] ) ? intval( $_POST['item_id'] ) : 0;
614 $sorted_array = get_user_option( 'mainwp_widgets_sorted_' . strtolower( $page ) );
615 if ( ! empty( $sorted_array ) ) {
616 $sorted_array = json_decode( $sorted_array, true );
617 }
618 if ( ! is_array( $sorted_array ) ) {
619 $sorted_array = array();
620 }
621 $sorted_array[ $item_id ] = $wgs_orders;
622 update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $sorted_array ), true );
623 } else {
624 update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $wgs_orders ), true );
625 }
626 die( 'ok' );
627 }
628 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
629 die( -1 );
630 }
631
632 /**
633 * Method ajax_mainwp_save_settings()
634 *
635 * Update saved MainWP Settings.
636 *
637 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
638 */
639 public function ajax_mainwp_save_settings() {
640 $this->secure_request( 'mainwp_save_settings' );
641 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
642 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
643 if ( ! empty( $name ) ) {
644 $option_name = 'mainwp_' . $name;
645 $val = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
646 MainWP_Utility::update_option( $option_name, $val );
647 }
648 // phpcs:enable
649 die( 'ok' );
650 }
651
652 /**
653 * Method ajax_guided_tours_option_update()
654 *
655 * Update saved MainWP Settings.
656 *
657 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
658 */
659 public function ajax_guided_tours_option_update() {
660 $this->secure_request( 'mainwp_guided_tours_option_update' );
661 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
662 $enable = isset( $_POST['enable'] ) ? intval( $_POST['enable'] ) : 0;
663 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
664 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', $enable );
665 die( 'ok' );
666 }
667
668 /**
669 * Method mainwp_leftmenu_filter_group()
670 *
671 * MainWP left menu filter by group.
672 *
673 * @uses \MainWP\Dashboard\MainWP_DB::query()
674 * @uses \MainWP\Dashboard\MainWP_DB::get_websites_by_group_id()
675 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
676 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
677 */
678 public function mainwp_leftmenu_filter_group() {
679 $this->secure_request( 'mainwp_leftmenu_filter_group' );
680
681 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
682 $gid = isset( $_POST['group_id'] ) ? intval( $_POST['group_id'] ) : false;
683 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
684
685 if ( ! empty( $gid ) ) {
686 $ids = '';
687 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $gid, true ) );
688 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
689 $ids .= $website->id . ',';
690 }
691 MainWP_DB::free_result( $websites );
692 $ids = rtrim( $ids, ',' );
693 die( $ids ); // phpcs:ignore WordPress.Security.EscapeOutput
694 }
695 die( '' );
696 }
697
698 /**
699 * Method dismiss_activate_notice()
700 *
701 * Dismiss activate notice.
702 */
703 public function dismiss_activate_notice() {
704 $this->secure_request( 'mainwp_dismiss_activate_notice' );
705
706 /**
707 * Current user global.
708 *
709 * @global string
710 */
711 global $current_user;
712 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
713 $user_id = $current_user->ID;
714 $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
715 if ( $user_id && ! empty( $slug ) ) {
716 $activate_notices = get_user_option( 'mainwp_hide_activate_notices' );
717 if ( ! is_array( $activate_notices ) ) {
718 $activate_notices = array();
719 }
720
721 $activate_notices[ $slug ] = time();
722 update_user_option( $user_id, 'mainwp_hide_activate_notices', $activate_notices );
723 }
724 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
725 die( 1 );
726 }
727
728
729
730 /**
731 * Method mainwp_security_issues_request()
732 *
733 * Post handler for,
734 * Page: SecurityIssues.
735 *
736 * @uses \MainWP\Dashboard\MainWP_Exception
737 * @uses \MainWP\Dashboard\MainWP_Security_Issues::fetch_security_issues()
738 */
739 public function mainwp_security_issues_request() {
740 $this->secure_request( 'mainwp_security_issues_request' );
741
742 try {
743 wp_send_json( array( 'result' => MainWP_Security_Issues::fetch_security_issues() ) );
744 } catch ( MainWP_Exception $e ) {
745 die(
746 wp_json_encode(
747 array(
748 'error' => array(
749 'message' => $e->getMessage(),
750 'extra' => $e->get_message_extra(),
751 ),
752 )
753 )
754 );
755 }
756 }
757
758 /**
759 * Method mainwp_security_issues_fix()
760 *
761 * Post handler for 'fix issues',
762 * Page: SecurityIssues.
763 *
764 * @uses \MainWP\Dashboard\MainWP_Exception
765 * @uses \MainWP\Dashboard\MainWP_Security_Issues::fix_security_issue()
766 */
767 public function mainwp_security_issues_fix() {
768 $this->secure_request( 'mainwp_security_issues_fix' );
769
770 try {
771 wp_send_json( array( 'result' => MainWP_Security_Issues::fix_security_issue() ) );
772 } catch ( MainWP_Exception $e ) {
773 die(
774 wp_json_encode(
775 array(
776 'error' => array(
777 'message' => $e->getMessage(),
778 'extra' => $e->get_message_extra(),
779 ),
780 )
781 )
782 );
783 }
784 }
785
786 /**
787 * Method mainwp_security_issues_unfix()
788 *
789 * Post handler for 'unfix issues',
790 * Page: SecurityIssues.
791 *
792 * @uses \MainWP\Dashboard\MainWP_Exception
793 * @uses \MainWP\Dashboard\MainWP_Security_Issues::unfix_security_issue()
794 */
795 public function mainwp_security_issues_unfix() {
796 $this->secure_request( 'mainwp_security_issues_unfix' );
797
798 try {
799 wp_send_json( array( 'result' => MainWP_Security_Issues::unfix_security_issue() ) );
800 } catch ( MainWP_Exception $e ) {
801 die(
802 wp_json_encode(
803 array(
804 'error' => array(
805 'message' => $e->getMessage(),
806 'extra' => $e->get_message_extra(),
807 ),
808 )
809 )
810 );
811 }
812 }
813
814 /**
815 * Method ajax_disconnect_site()
816 *
817 * Disconnect Child Site.
818 *
819 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
820 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
821 */
822 public function ajax_disconnect_site() {
823 $this->secure_request( 'mainwp_disconnect_site' );
824 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
825 $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
826 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
827
828 if ( empty( $siteid ) ) {
829 die( wp_json_encode( array( 'error' => 'Error: site id empty' ) ) );
830 }
831
832 $website = MainWP_DB::instance()->get_website_by_id( $siteid );
833
834 if ( ! $website ) {
835 die( wp_json_encode( array( 'error' => 'Not found site' ) ) );
836 }
837
838 try {
839 $information = MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
840 } catch ( \Exception $e ) {
841 $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
842 }
843
844 wp_send_json( $information );
845 }
846
847 /**
848 * Method ajax_sites_display_rows()
849 *
850 * Display rows via ajax,
851 * Page: Manage Sites.
852 *
853 * @uses \MainWP\Dashboard\MainWP_Manage_Sites::ajax_optimize_display_rows()
854 */
855 public function ajax_sites_display_rows() {
856 $this->secure_request( 'mainwp_manage_sites_display_rows' );
857 MainWP_Manage_Sites::ajax_optimize_display_rows();
858 }
859
860 /**
861 * Method ajax_monitoring_display_rows()
862 *
863 * Display rows via ajax,
864 * Page: Monitoring Sites.
865 *
866 * @uses \MainWP\Dashboard\MainWP_Monitoring::ajax_optimize_display_rows()
867 */
868 public function ajax_monitoring_display_rows() {
869 $this->secure_request( 'mainwp_monitoring_sites_display_rows' );
870 MainWP_Monitoring::ajax_optimize_display_rows();
871 }
872
873
874 /**
875 * Method mainwp_bulkadduser()
876 *
877 * Bulk Add User for,
878 * Page: BulkAddUser.
879 *
880 * @uses \MainWP\Dashboard\MainWP_User::do_bulk_add()
881 */
882 public function mainwp_bulkadduser() {
883 $this->check_security( 'mainwp_bulkadduser' );
884 MainWP_User::do_bulk_add();
885 die();
886 }
887
888 /**
889 * Method mainwp_importuser()
890 *
891 * Import user.
892 *
893 * @uses \MainWP\Dashboard\MainWP_User::do_import()
894 */
895 public function mainwp_importuser() {
896 $this->secure_request( 'mainwp_importuser' );
897 MainWP_User::do_import();
898 }
899
900 /**
901 * Method mainwp_clients_add_client()
902 *
903 * Add Client for,
904 * Page: BulkAddClient.
905 */
906 public function mainwp_clients_add_client() {
907 $this->check_security( 'mainwp_clients_add_client' );
908 MainWP_Client::add_client();
909 die();
910 }
911
912 /**
913 * Method mainwp_clients_delete_client()
914 *
915 * Add Client for,
916 * Page: BulkAddClient.
917 */
918 public function mainwp_clients_delete_client() {
919 $this->check_security( 'mainwp_clients_delete_client' );
920 $ret = array( 'success' => false );
921 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
922 $client_id = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
923 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
924 if ( $client_id ) {
925 MainWP_DB_Client::instance()->delete_client( $client_id );
926 $ret['success'] = 'SUCCESS';
927 $ret['result'] = esc_html__( 'Client removed successfully.', 'mainwp' );
928 } else {
929 $ret['result'] = esc_html__( 'Client ID empty.', 'mainwp' );
930 }
931
932 echo wp_json_encode( $ret );
933 exit;
934 }
935
936 /**
937 * Method mainwp_clients_save_field()
938 *
939 * Save client custom fields.
940 */
941 public function mainwp_clients_save_field() {
942 $this->check_security( 'mainwp_clients_save_field' );
943 MainWP_Client::save_client_field();
944 die();
945 }
946
947
948 /**
949 * Method mainwp_clients_delete_general_field()
950 *
951 * Delete client general fields.
952 */
953 public function mainwp_clients_delete_general_field() {
954 $this->check_security( 'mainwp_clients_delete_general_field' );
955 $ret = array( 'success' => false );
956 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
957 $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
958 $client_id = 0; // 0 general fields.
959 if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
960 $ret['success'] = true;
961 }
962 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
963 echo wp_json_encode( $ret );
964 exit;
965 }
966
967
968 /**
969 * Method mainwp_clients_delete_field()
970 *
971 * Delete client custom fields.
972 */
973 public function mainwp_clients_delete_field() {
974 $this->check_security( 'mainwp_clients_delete_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 = isset( $_POST['client_id'] ) ? intval( $_POST['client_id'] ) : 0; // $client_id > 0, individual token.
979 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
980 if ( $client_id ) {
981 if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
982 $ret['success'] = true;
983 }
984 }
985 echo wp_json_encode( $ret );
986 exit;
987 }
988
989 /**
990 * Method mainwp_notes_save()
991 *
992 * Post handler for save notes on,
993 * Page: Manage Sites.
994 *
995 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
996 */
997 public function mainwp_notes_save() {
998 $this->secure_request( 'mainwp_notes_save' );
999 MainWP_Manage_Sites_Handler::save_note();
1000 }
1001
1002 /**
1003 * Method mainwp_clients_notes_save()
1004 *
1005 * Post handler for save notes on,
1006 * Page: Manage Sites.
1007 *
1008 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1009 */
1010 public function mainwp_clients_notes_save() {
1011 $this->secure_request( 'mainwp_clients_notes_save' );
1012 MainWP_Client::save_note();
1013 }
1014
1015 /**
1016 * Method mainwp_clients_suspend_client()
1017 *
1018 * Post handler for suspend client,
1019 * Page: Manage Sites.
1020 *
1021 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1022 */
1023 public function mainwp_clients_suspend_client() {
1024 $this->secure_request( 'mainwp_clients_suspend_client' );
1025 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1026 $clientid = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
1027 $suspended = isset( $_POST['suspend_status'] ) && ! empty( $_POST['suspend_status'] ) ? 1 : 0;
1028 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1029
1030 if ( empty( $clientid ) ) {
1031 wp_die( 'Error - empty client id!' );
1032 }
1033
1034 $params = array(
1035 'client_id' => $clientid,
1036 'suspended' => $suspended,
1037 );
1038
1039 MainWP_DB_Client::instance()->update_client( $params );
1040
1041 $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $clientid );
1042
1043 /**
1044 * Fires immediately after update client suspend/unsuspend.
1045 *
1046 * @since 4.5.1.1
1047 *
1048 * @param object $client client data.
1049 * @param bool $suspended true|false.
1050 */
1051 do_action( 'mainwp_client_suspend', $client, $suspended );
1052
1053 MainWP_DB_Client::instance()->suspend_unsuspend_websites_by_client_id( $clientid, $suspended );
1054
1055 wp_die( 'success' );
1056 }
1057
1058 /**
1059 * Method mainwp_syncerrors_dismiss()
1060 *
1061 * Dismiss Sync errors for,
1062 * Widget: RightNow.
1063 *
1064 * @uses \MainWP\Dashboard\MainWP_Updates_Overview::dismiss_sync_errors()
1065 */
1066 public function mainwp_syncerrors_dismiss() {
1067
1068 $this->secure_request( 'mainwp_syncerrors_dismiss' );
1069
1070 try {
1071 die( wp_json_encode( array( 'result' => MainWP_Updates_Overview::dismiss_sync_errors() ) ) );
1072 } catch ( \Exception $e ) {
1073 die( wp_json_encode( array( 'error' => $e->getMessage() ) ) );
1074 }
1075 }
1076
1077 /**
1078 * Method mainwp_events_notice_hide()
1079 *
1080 * Hide events notice.
1081 */
1082 public function mainwp_events_notice_hide() {
1083 $this->secure_request( 'mainwp_events_notice_hide' );
1084 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1085 if ( isset( $_POST['notice'] ) ) {
1086 $current_options = get_option( 'mainwp_showhide_events_notice' );
1087 if ( ! is_array( $current_options ) ) {
1088 $current_options = array();
1089 }
1090 if ( 'first_site' === $_POST['notice'] ) {
1091 update_option( 'mainwp_first_site_events_notice', '' );
1092 } elseif ( 'request_reviews1' === $_POST['notice'] ) {
1093 $current_options['request_reviews1'] = 15;
1094 $current_options['request_reviews1_starttime'] = time();
1095 } elseif ( 'request_reviews1_forever' === $_POST['notice'] || 'request_reviews2_forever' === $_POST['notice'] ) {
1096 $current_options['request_reviews1'] = 'forever';
1097 $current_options['request_reviews2'] = 'forever';
1098 } elseif ( 'request_reviews2' === $_POST['notice'] ) {
1099 $current_options['request_reviews2'] = 15;
1100 $current_options['request_reviews2_starttime'] = time();
1101 } elseif ( 'trust_child' === $_POST['notice'] ) {
1102 $current_options['trust_child'] = 1;
1103 } elseif ( 'multi_site' === $_POST['notice'] ) {
1104 $current_options['hide_multi_site_notice'] = 1;
1105 }
1106 update_option( 'mainwp_showhide_events_notice', $current_options );
1107 }
1108 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1109 die( 'ok' );
1110 }
1111
1112 /**
1113 * Method mainwp_showhide_sections()
1114 *
1115 * Show/Hide sections.
1116 */
1117 public function mainwp_showhide_sections() {
1118 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1119 if ( isset( $_POST['sec'] ) && isset( $_POST['status'] ) ) {
1120 $opts = get_option( 'mainwp_opts_showhide_sections' );
1121 if ( ! is_array( $opts ) ) {
1122 $opts = array();
1123 }
1124 $opts[ sanitize_text_field( wp_unslash( $_POST['sec'] ) ) ] = sanitize_text_field( wp_unslash( $_POST['status'] ) );
1125 update_option( 'mainwp_opts_showhide_sections', $opts );
1126 die( 'ok' );
1127 }
1128 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1129 die( 'failed' );
1130 }
1131
1132 /**
1133 * Method mainwp_saving_status()
1134 *
1135 * MainWP Saving Status.
1136 */
1137 public function mainwp_saving_status() {
1138 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1139 if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'mainwp_ajax' ) ) {
1140 die( esc_html__( 'WP nonce could not be verified. Please reload the page and try again.', 'mainwp' ) );
1141 }
1142 $saving_status = isset( $_POST['saving_status'] ) ? sanitize_text_field( wp_unslash( $_POST['saving_status'] ) ) : false;
1143 if ( ! empty( $saving_status ) ) {
1144 $current_options = get_option( 'mainwp_opts_saving_status' );
1145 if ( ! is_array( $current_options ) ) {
1146 $current_options = array();
1147 }
1148 if ( isset( $_POST['value'] ) ) {
1149 $current_options[ $saving_status ] = sanitize_text_field( wp_unslash( $_POST['value'] ) );
1150 }
1151 update_option( 'mainwp_opts_saving_status', $current_options );
1152 }
1153 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1154 die( 'ok' );
1155 }
1156
1157 /**
1158 * Method ajax_recheck_http()
1159 *
1160 * Recheck Child Site http status code & message.
1161 *
1162 * @uses \MainWP\Dashboard\MainWP_Connect::check_ignored_http_code()
1163 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1164 * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_check_website()
1165 */
1166 public function ajax_recheck_http() {
1167 $this->check_security( 'mainwp_recheck_http' );
1168 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1169 if ( ! isset( $_POST['websiteid'] ) || empty( $_POST['websiteid'] ) ) {
1170 die( -1 );
1171 }
1172
1173 $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['websiteid'] ) );
1174 if ( empty( $website ) ) {
1175 die( -1 );
1176 }
1177 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1178
1179 $result = MainWP_Monitoring_Handler::handle_check_website( $website );
1180 $http_code = ( is_array( $result ) && isset( $result['httpCode'] ) ) ? $result['httpCode'] : 0;
1181 $check_result = MainWP_Connect::check_ignored_http_code( $http_code );
1182 die(
1183 wp_json_encode(
1184 array(
1185 'httpcode' => esc_html( $http_code ),
1186 'status' => $check_result ? 1 : 0,
1187 )
1188 )
1189 );
1190 }
1191
1192 /**
1193 * Method mainwp_ignore_http_response()
1194 *
1195 * Ignore Child Site https response.
1196 *
1197 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1198 * @uses \MainWP\Dashboard\MainWP_DB::update_website_values()
1199 */
1200 public function mainwp_ignore_http_response() {
1201 $this->check_security( 'mainwp_ignore_http_response' );
1202 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1203 $siteid = isset( $_POST['websiteid'] ) ? intval( $_POST['websiteid'] ) : false;
1204 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1205 if ( empty( $siteid ) ) {
1206 die( -1 );
1207 }
1208
1209 $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1210 if ( empty( $website ) ) {
1211 die( -1 );
1212 }
1213
1214 MainWP_DB::instance()->update_website_values( $website->id, array( 'http_response_code' => '-1' ) );
1215 die( wp_json_encode( array( 'ok' => 1 ) ) );
1216 }
1217
1218 /**
1219 * Method mainwp_autoupdate_and_trust_child()
1220 *
1221 * Set MainWP Child Plugin to Trusted & AutoUpdate.
1222 *
1223 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_plugin()
1224 */
1225 public function mainwp_autoupdate_and_trust_child() {
1226 $this->secure_request( 'mainwp_autoupdate_and_trust_child' );
1227 if ( 1 !== (int) get_option( 'mainwp_pluginAutomaticDailyUpdate' ) ) {
1228 update_option( 'mainwp_pluginAutomaticDailyUpdate', 1 );
1229 }
1230 MainWP_Plugins_Handler::trust_plugin( 'mainwp-child/mainwp-child.php' );
1231 die( 'ok' );
1232 }
1233
1234 /**
1235 * Method mainwp_force_destroy_sessions()
1236 *
1237 * Force destroy sessions.
1238 *
1239 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
1240 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1241 *
1242 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
1243 */
1244 public function mainwp_force_destroy_sessions() {
1245 $this->secure_request( 'mainwp_force_destroy_sessions' );
1246
1247 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1248 $website_id = ( isset( $_POST['website_id'] ) ? (int) $_POST['website_id'] : 0 );
1249 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1250 if ( ! MainWP_DB::instance()->get_website_by_id( $website_id ) ) {
1251 die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'This website does not exist.', 'mainwp' ) ) ) ) );
1252 }
1253
1254 $website = MainWP_DB::instance()->get_website_by_id( $website_id );
1255 if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
1256 die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'You cannot edit this website.', 'mainwp' ) ) ) ) );
1257 }
1258
1259 try {
1260 $information = MainWP_Connect::fetch_url_authed(
1261 $website,
1262 'settings_tools',
1263 array(
1264 'action' => 'force_destroy_sessions',
1265 )
1266 );
1267 } catch ( \Exception $e ) {
1268 $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
1269 }
1270
1271 wp_send_json( $information );
1272 }
1273
1274 /**
1275 * Method ajax_refresh_icon()
1276 */
1277 public function ajax_refresh_icon() {
1278 $this->secure_request( 'mainwp_refresh_icon' );
1279 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1280 $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1281 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1282 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1283
1284 if ( empty( $slug ) ) {
1285 wp_die( 'failed' );
1286 }
1287
1288 $fet_icon = MainWP_System_Utility::handle_get_icon( $slug, $type );
1289
1290 if ( ! empty( $fet_icon ) ) {
1291 wp_die( 'success' );
1292 } else {
1293 wp_die( 'failed' );
1294 }
1295 }
1296
1297 /**
1298 * Method ajax_upload_custom_icon()
1299 */
1300 public function ajax_upload_custom_icon() {
1301 $this->secure_request( 'mainwp_upload_custom_icon' );
1302 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1303 $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1304 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1305 $delete = isset( $_POST['delete'] ) ? intval( $_POST['delete'] ) : 0;
1306
1307 if ( empty( $slug ) || ( 'plugin' !== $type && 'theme' !== $type ) ) {
1308 wp_die( 'failed' );
1309 }
1310
1311 $sub_folder = '';
1312
1313 if ( 'plugin' === $type ) {
1314 $sub_folder = 'plugin-icons';
1315 } elseif ( 'theme' === $type ) {
1316 $sub_folder = 'theme-icons';
1317 } else {
1318 wp_die( wp_json_encode( array( 'result' => 'invalid' ) ) );
1319 }
1320
1321 if ( $delete ) {
1322 MainWP_System_Utility::update_cached_icons( '', $slug, $type, true );
1323 wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1324 }
1325
1326 $output = isset( $_FILES['mainwp_upload_icon_uploader'] ) ? MainWP_System_Utility::handle_upload_image( $sub_folder, $_FILES['mainwp_upload_icon_uploader'], 0 ) : null;
1327 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1328
1329 $uploaded_icon = 'NOTCHANGE';
1330 if ( is_array( $output ) && isset( $output['filename'] ) && ! empty( $output['filename'] ) ) {
1331 $uploaded_icon = $output['filename'];
1332 }
1333
1334 if ( 'NOTCHANGE' !== $uploaded_icon ) {
1335 MainWP_System_Utility::update_cached_icons( $uploaded_icon, $slug, $type, true );
1336 wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1337 } else {
1338 wp_die( wp_json_encode( array( 'result' => 'failed' ) ) );
1339 }
1340 }
1341
1342 /**
1343 * Method ajax_select_custom_theme()
1344 */
1345 public function ajax_select_custom_theme() {
1346 $this->secure_request( 'mainwp_select_custom_theme' );
1347 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1348 $theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : '';
1349 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1350 if ( empty( $theme ) ) {
1351 wp_die( 'failed' );
1352 }
1353
1354 $user = wp_get_current_user();
1355 if ( empty( $user ) || empty( $user->ID ) ) {
1356 wp_die( 'failed' );
1357 }
1358
1359 update_user_option( $user->ID, 'mainwp_selected_theme', $theme );
1360 wp_die( 'success' );
1361 }
1362
1363
1364 /**
1365 * Method ajax_site_actions_dismiss()
1366 */
1367 public function ajax_site_actions_dismiss() {
1368 $this->secure_request( 'mainwp_site_actions_dismiss' );
1369 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1370 $action_id = isset( $_POST['action_id'] ) ? intval( $_POST['action_id'] ) : 0;
1371 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1372
1373 if ( empty( $action_id ) ) {
1374 wp_die( 'failed' );
1375 }
1376 $update = array(
1377 'dismiss' => 1,
1378 );
1379 MainWP_DB_Site_Actions::instance()->update_action_by_id( $action_id, $update );
1380 wp_die( 'success' );
1381 }
1382
1383 /**
1384 * Method ajax_site_actions_dismiss()
1385 */
1386 public function ajax_delete_non_mainwp_actions() {
1387 $this->secure_request( 'mainwp_delete_non_mainwp_actions' );
1388 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1389 $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
1390 if ( empty( $siteid ) ) {
1391 wp_die( wp_json_encode( array( 'error' => 'Empty site ID' ) ) );
1392 }
1393 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1394 $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1395 $success = false;
1396 $error = '';
1397 try {
1398 $response = MainWP_Connect::fetch_url_authed( $website, 'delete_actions', array( 'del' => 'act' ) );
1399 if ( is_array( $response ) ) {
1400 if ( isset( $response['success'] ) ) {
1401 $success = true;
1402 } elseif ( isset( $response['error'] ) ) {
1403 $error = $response['error'];
1404 }
1405 }
1406 } catch ( \Exception $e ) {
1407 // ok!
1408 }
1409 if ( $success ) {
1410 MainWP_DB_Site_Actions::instance()->delete_action_by( 'wpid', $siteid );
1411 wp_die( wp_json_encode( array( 'success' => 'ok' ) ) );
1412 }
1413
1414 if ( empty( $error ) ) {
1415 $error = __( 'Undefined error. Please try again.', 'mainwp' );
1416 }
1417 wp_die( wp_json_encode( array( 'error' => $error ) ) );
1418 }
1419
1420 /**
1421 * Method ajax_import_demo_data().
1422 */
1423 public function ajax_import_demo_data() {
1424 $this->secure_request( 'mainwp_import_demo_data' );
1425 $data = MainWP_Demo_Handle::get_instance()->import_data_demo();
1426 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 1 );
1427 wp_die( wp_json_encode( $data ) );
1428 }
1429
1430 /**
1431 * Method ajax_delete_demo_data().
1432 */
1433 public function ajax_delete_demo_data() {
1434 $this->secure_request( 'mainwp_delete_demo_data' );
1435 $data = MainWP_Demo_Handle::get_instance()->delete_data_demo();
1436 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 0 );
1437 wp_die( wp_json_encode( $data ) );
1438 }
1439 }
1440