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

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