PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.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-plugin-theme-handler.php

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

718 lines 23.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Post Plugin Theme Handler.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 /**
11 * Class MainWP_Post_Plugin_Theme_Handler
12 *
13 * @package MainWP\Dashboard
14 */
15 class MainWP_Post_Plugin_Theme_Handler extends MainWP_Post_Base_Handler {
16
17 /**
18 * Protected static variable to hold the single instance of the class.
19 *
20 * @var mixed Default null
21 */
22 private static $instance = null;
23
24 /**
25 * Method instance()
26 *
27 * Create public static instance.
28 *
29 * @static
30 * @return MainWP_Post_Plugin_Theme_Handler
31 */
32 public static function instance() {
33 if ( null == self::$instance ) {
34 self::$instance = new self();
35 }
36 return self::$instance;
37 }
38
39 /**
40 * Init plugins/themes actions
41 */
42 public function init() {
43 // Page: ManageSites.
44 $this->add_action( 'mainwp_ext_prepareinstallplugintheme', array( &$this, 'mainwp_ext_prepareinstallplugintheme' ) );
45 $this->add_action( 'mainwp_ext_performinstallplugintheme', array( &$this, 'mainwp_ext_performinstallplugintheme' ) );
46
47 // Page: InstallPlugins/Themes.
48 $this->add_action( 'mainwp_preparebulkinstallplugintheme', array( &$this, 'mainwp_preparebulkinstallplugintheme' ) );
49 $this->add_action( 'mainwp_installbulkinstallplugintheme', array( &$this, 'mainwp_installbulkinstallplugintheme' ) );
50 $this->add_action( 'mainwp_preparebulkuploadplugintheme', array( &$this, 'mainwp_preparebulkuploadplugintheme' ) );
51 $this->add_action( 'mainwp_installbulkuploadplugintheme', array( &$this, 'mainwp_installbulkuploadplugintheme' ) );
52 $this->add_action( 'mainwp_cleanbulkuploadplugintheme', array( &$this, 'mainwp_cleanbulkuploadplugintheme' ) );
53
54 // Widget: RightNow.
55 $this->add_action( 'mainwp_upgradewp', array( &$this, 'mainwp_upgradewp' ) );
56 $this->add_action( 'mainwp_upgradeplugintheme', array( &$this, 'mainwp_upgrade_plugintheme' ) );
57 $this->add_action( 'mainwp_ignoreplugintheme', array( &$this, 'mainwp_ignoreplugintheme' ) );
58 $this->add_action( 'mainwp_unignoreplugintheme', array( &$this, 'mainwp_unignoreplugintheme' ) );
59 $this->add_action( 'mainwp_ignorepluginsthemes', array( &$this, 'mainwp_ignorepluginsthemes' ) );
60 $this->add_action( 'mainwp_unignorepluginsthemes', array( &$this, 'mainwp_unignorepluginsthemes' ) );
61 $this->add_action( 'mainwp_unignoreabandonedplugintheme', array( &$this, 'mainwp_unignoreabandonedplugintheme' ) );
62 $this->add_action( 'mainwp_unignoreabandonedpluginsthemes', array( &$this, 'mainwp_unignoreabandonedpluginsthemes' ) );
63 $this->add_action( 'mainwp_dismissoutdateplugintheme', array( &$this, 'mainwp_dismissoutdateplugintheme' ) );
64 $this->add_action( 'mainwp_dismissoutdatepluginsthemes', array( &$this, 'mainwp_dismissoutdatepluginsthemes' ) );
65 $this->add_action( 'mainwp_trust_plugin', array( &$this, 'mainwp_trust_plugin' ) );
66 $this->add_action( 'mainwp_trust_theme', array( &$this, 'mainwp_trust_theme' ) );
67
68 // Page: Themes.
69 $this->add_action( 'mainwp_themes_search', array( &$this, 'mainwp_themes_search' ) );
70 $this->add_action( 'mainwp_themes_search_all', array( &$this, 'mainwp_themes_search_all' ) );
71 if ( mainwp_current_user_have_right( 'dashboard', 'activate_themes' ) ) {
72 $this->add_action( 'mainwp_theme_activate', array( &$this, 'mainwp_theme_activate' ) );
73 }
74 if ( mainwp_current_user_have_right( 'dashboard', 'delete_themes' ) ) {
75 $this->add_action( 'mainwp_theme_delete', array( &$this, 'mainwp_theme_delete' ) );
76 }
77 $this->add_action( 'mainwp_trusted_theme_notes_save', array( &$this, 'mainwp_trusted_theme_notes_save' ) );
78 if ( mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) {
79 $this->add_action( 'mainwp_theme_ignore_updates', array( &$this, 'mainwp_theme_ignore_updates' ) );
80 }
81
82 // Page: Plugins.
83 $this->add_action( 'mainwp_plugins_search', array( &$this, 'mainwp_plugins_search' ) );
84 $this->add_action( 'mainwp_plugins_search_all_active', array( &$this, 'mainwp_plugins_search_all_active' ) );
85
86 if ( mainwp_current_user_have_right( 'dashboard', 'activate_deactivate_plugins' ) ) {
87 $this->add_action( 'mainwp_plugin_activate', array( &$this, 'mainwp_plugin_activate' ) );
88 $this->add_action( 'mainwp_plugin_deactivate', array( &$this, 'mainwp_plugin_deactivate' ) );
89 }
90 if ( mainwp_current_user_have_right( 'dashboard', 'delete_plugins' ) ) {
91 $this->add_action( 'mainwp_plugin_delete', array( &$this, 'mainwp_plugin_delete' ) );
92 }
93
94 if ( mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) {
95 $this->add_action( 'mainwp_plugin_ignore_updates', array( &$this, 'mainwp_plugin_ignore_updates' ) );
96 }
97 $this->add_action( 'mainwp_trusted_plugin_notes_save', array( &$this, 'mainwp_trusted_plugin_notes_save' ) );
98
99 // Widget: Plugins.
100 $this->add_action( 'mainwp_widget_plugin_activate', array( &$this, 'mainwp_widget_plugin_activate' ) );
101 $this->add_action( 'mainwp_widget_plugin_deactivate', array( &$this, 'mainwp_widget_plugin_deactivate' ) );
102 $this->add_action( 'mainwp_widget_plugin_delete', array( &$this, 'mainwp_widget_plugin_delete' ) );
103
104 // Widget: Themes.
105 $this->add_action( 'mainwp_widget_theme_activate', array( &$this, 'mainwp_widget_theme_activate' ) );
106 $this->add_action( 'mainwp_widget_theme_delete', array( &$this, 'mainwp_widget_theme_delete' ) );
107 }
108
109 /**
110 * Method mainwp_themes_search()
111 *
112 * Search handler for Themes.
113 */
114 public function mainwp_themes_search() {
115 $this->secure_request( 'mainwp_themes_search' );
116
117 $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
118 $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
119 $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : array();
120 $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : array();
121
122 MainWP_Cache::init_session();
123 $result = MainWP_Themes::render_table( $keyword, $status, $groups, $sites );
124 wp_send_json( $result );
125 }
126
127 /**
128 * Method mainwp_theme_activate()
129 *
130 * Activate Theme,
131 * Page: Themes.
132 */
133 public function mainwp_theme_activate() {
134 $this->secure_request( 'mainwp_theme_activate' );
135 MainWP_Themes_Handler::activate_theme();
136 die();
137 }
138
139 /**
140 * Method mainwp_theme_delete()
141 *
142 * Delete Theme,
143 * Page: Themes.
144 */
145 public function mainwp_theme_delete() {
146 $this->secure_request( 'mainwp_theme_delete' );
147 MainWP_Themes_Handler::delete_themes();
148 die();
149 }
150
151 /**
152 * Method mainwp_theme_ignore_updates()
153 *
154 * Ignore theme updates,
155 * Page: Themes.
156 */
157 public function mainwp_theme_ignore_updates() {
158 $this->secure_request( 'mainwp_theme_ignore_updates' );
159 MainWP_Themes_Handler::ignore_updates();
160 die();
161 }
162
163 /**
164 * Method mainwp_themes_search_all()
165 *
166 * Search ALL handler for,
167 * Page: Themes.
168 */
169 public function mainwp_themes_search_all() {
170 $this->secure_request( 'mainwp_themes_search_all' );
171 MainWP_Cache::init_session();
172 MainWP_Themes::render_all_themes_table();
173 die();
174 }
175
176 /**
177 * Method mainwp_trusted_theme_notes_save()
178 *
179 * Save trusted theme notes,
180 * Page: Themes.
181 */
182 public function mainwp_trusted_theme_notes_save() {
183 $this->secure_request( 'mainwp_trusted_theme_notes_save' );
184 MainWP_Themes_Handler::save_trusted_theme_note();
185 die( wp_json_encode( array( 'result' => 'SUCCESS' ) ) );
186 }
187
188 /**
189 * Method mainwp_plugins_search()
190 *
191 * Search handler for Plugins.
192 */
193 public function mainwp_plugins_search() {
194 $this->secure_request( 'mainwp_plugins_search' );
195
196 $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
197 $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
198 $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
199 $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
200
201 MainWP_Cache::init_session();
202 $result = MainWP_Plugins::render_table( $keyword, $status, $groups, $sites );
203 wp_send_json( $result );
204 }
205
206 /**
207 * Method mainwp_plugins_search_all_active()
208 *
209 * Search all Active handler for,
210 * Page: Plugins.
211 */
212 public function mainwp_plugins_search_all_active() {
213 $this->secure_request( 'mainwp_plugins_search_all_active' );
214 MainWP_Cache::init_session();
215 MainWP_Plugins::render_all_active_table();
216 die();
217 }
218
219 /**
220 * Method mainwp_plugin_activate()
221 *
222 * Activate plugins,
223 * Page: Plugins.
224 */
225 public function mainwp_plugin_activate() {
226 $this->secure_request( 'mainwp_plugin_activate' );
227 MainWP_Plugins_Handler::activate_plugins();
228 die();
229 }
230
231 /**
232 * Method mainwp_plugin_deactivate()
233 *
234 * Deactivate plugins,
235 * Page: Plugins.
236 */
237 public function mainwp_plugin_deactivate() {
238 $this->secure_request( 'mainwp_plugin_deactivate' );
239 MainWP_Plugins_Handler::deactivate_plugins();
240 die();
241 }
242
243 /**
244 * Method mainwp_plugin_delete()
245 *
246 * Delete plugins,
247 * Page: Plugins.
248 */
249 public function mainwp_plugin_delete() {
250 $this->secure_request( 'mainwp_plugin_delete' );
251 MainWP_Plugins_Handler::delete_plugins();
252 die();
253 }
254
255 /**
256 * Method mainwp_plugin_ignore_updates()
257 *
258 * Ignore plugins updates,
259 * Page: Plugins.
260 */
261 public function mainwp_plugin_ignore_updates() {
262 $this->secure_request( 'mainwp_plugin_ignore_updates' );
263 MainWP_Plugins_Handler::ignore_updates();
264 die();
265 }
266
267 /**
268 * Method mainwp_trusted_plugin_notes_save()
269 *
270 * Save trusted plugin notes,
271 * Page: Plugins.
272 */
273 public function mainwp_trusted_plugin_notes_save() {
274 $this->secure_request( 'mainwp_trusted_plugin_notes_save' );
275 MainWP_Plugins_Handler::save_trusted_plugin_note();
276 die( wp_json_encode( array( 'result' => 'SUCCESS' ) ) );
277 }
278
279 /**
280 * Method mainwp_widget_plugin_activate()
281 *
282 * Activate plugin,
283 * Widget: Plugins.
284 */
285 public function mainwp_widget_plugin_activate() {
286 $this->secure_request( 'mainwp_widget_plugin_activate' );
287 MainWP_Widget_Plugins::activate_plugin();
288 }
289
290 /**
291 * Method mainwp_widget_plugin_deactivate()
292 *
293 * Deactivate plugin,
294 * Widget: Plugins.
295 */
296 public function mainwp_widget_plugin_deactivate() {
297 $this->secure_request( 'mainwp_widget_plugin_deactivate' );
298 MainWP_Widget_Plugins::deactivate_plugin();
299 }
300
301 /**
302 * Method mainwp_widget_plugin_delete()
303 *
304 * Delete plugin,
305 * Widget: Plugins.
306 */
307 public function mainwp_widget_plugin_delete() {
308 $this->secure_request( 'mainwp_widget_plugin_delete' );
309 MainWP_Widget_Plugins::delete_plugin();
310 }
311
312 /**
313 * Method mainwp_widget_plugin_activate()
314 *
315 * Activate theme,
316 * Widget: Themes.
317 */
318 public function mainwp_widget_theme_activate() {
319 $this->secure_request( 'mainwp_widget_theme_activate' );
320 MainWP_Widget_Themes::activate_theme();
321 }
322
323 /**
324 * Method mainwp_widget_plugin_delete()
325 *
326 * Delete theme,
327 * Widget: Themes.
328 */
329 public function mainwp_widget_theme_delete() {
330 $this->secure_request( 'mainwp_widget_theme_delete' );
331 MainWP_Widget_Themes::delete_theme();
332 }
333
334 /**
335 * Method mainwp_preparebulkinstallplugintheme()
336 *
337 * Prepair bulk installation of plugins & themes,
338 * Page: InstallPlugins/Themes.
339 */
340 public function mainwp_preparebulkinstallplugintheme() {
341 $this->secure_request( 'mainwp_preparebulkinstallplugintheme' );
342 MainWP_Install_Bulk::prepare_install();
343 }
344
345 /**
346 * Method mainwp_installbulkinstallplugintheme()
347 *
348 * Installation of plugins & themes,
349 * Page: InstallPlugins/Themes.
350 */
351 public function mainwp_installbulkinstallplugintheme() {
352 $this->secure_request( 'mainwp_installbulkinstallplugintheme' );
353 MainWP_Install_Bulk::perform_install();
354 }
355
356 /**
357 * Method mainwp_preparebulkuploadplugintheme()
358 *
359 * Prepair bulk upload of plugins & themes,
360 * Page: InstallPlugins/Themes.
361 */
362 public function mainwp_preparebulkuploadplugintheme() {
363 $this->secure_request( 'mainwp_preparebulkuploadplugintheme' );
364 MainWP_Install_Bulk::prepare_upload();
365 }
366
367 /**
368 * Method mainwp_installbulkuploadplugintheme()
369 *
370 * Bulk upload of plugins & themes,
371 * Page: InstallPlugins/Themes.
372 */
373 public function mainwp_installbulkuploadplugintheme() {
374 $this->secure_request( 'mainwp_installbulkuploadplugintheme' );
375 MainWP_Install_Bulk::perform_upload();
376 }
377
378 /**
379 * Method mainwp_cleanbulkuploadplugintheme()
380 *
381 * Clean upload of plugins & themes,
382 * Page: InstallPlugins/Themes.
383 */
384 public function mainwp_cleanbulkuploadplugintheme() {
385 $this->secure_request( 'mainwp_cleanbulkuploadplugintheme' );
386 MainWP_Install_Bulk::clean_upload();
387 }
388
389 /**
390 * Method mainwp_ext_prepareinstallplugintheme()
391 *
392 * Prepair Installation of plugins & themes,
393 * Page: ManageSites.
394 */
395 public function mainwp_ext_prepareinstallplugintheme() {
396 do_action( 'mainwp_prepareinstallplugintheme' );
397 }
398
399 /**
400 * Method mainwp_ext_performinstallplugintheme()
401 *
402 * Installation of plugins & themes,
403 * Page: ManageSites.
404 */
405 public function mainwp_ext_performinstallplugintheme() {
406 do_action( 'mainwp_performinstallplugintheme' );
407 }
408
409 /**
410 * Method mainwp_upgradewp()
411 *
412 * Update a specific WP core.
413 */
414 public function mainwp_upgradewp() {
415 if ( ! mainwp_current_user_have_right( 'dashboard', 'update_wordpress' ) ) {
416 die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'update WordPress', 'mainwp' ), $echo = false ) ) ) );
417 }
418
419 $this->secure_request( 'mainwp_upgradewp' );
420
421 try {
422 $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : false;
423 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::upgrade_site( $id ) ) ) ); // ok.
424 } catch ( MainWP_Exception $e ) {
425 die(
426 wp_json_encode(
427 array(
428 'error' => array(
429 'message' => $e->getMessage(),
430 'extra' => $e->get_message_extra(),
431 ),
432 )
433 )
434 );
435 }
436 }
437
438 /**
439 * Method mainwp_upgrade_plugintheme()
440 *
441 * Update plugin or theme.
442 */
443 public function mainwp_upgrade_plugintheme() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
444
445 if ( ! isset( $_POST['type'] ) ) {
446 die( wp_json_encode( array( 'error' => '<i class="red times icon"></i> ' . __( 'Invalid request', 'mainwp' ) ) ) );
447 }
448
449 if ( 'plugin' === $_POST['type'] && ! mainwp_current_user_have_right( 'dashboard', 'update_plugins' ) ) {
450 die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'update plugins', 'mainwp' ), $echo = false ) ) ) );
451 }
452
453 if ( 'theme' === $_POST['type'] && ! mainwp_current_user_have_right( 'dashboard', 'update_themes' ) ) {
454 die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'update themes', 'mainwp' ), $echo = false ) ) ) );
455 }
456
457 if ( 'translation' === $_POST['type'] && ! mainwp_current_user_have_right( 'dashboard', 'update_translations' ) ) {
458 die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'update translations', 'mainwp' ), $echo = false ) ) ) );
459 }
460
461 $this->secure_request( 'mainwp_upgradeplugintheme' );
462
463 // support chunk update for manage sites page only.
464 $chunk_support = ! empty( $_POST['chunk_support'] ) ? true : false;
465 $max_update = 0;
466 $websiteId = null;
467 $slugs = '';
468
469 if ( isset( $_POST['websiteId'] ) ) {
470 $websiteId = intval( $_POST['websiteId'] );
471
472 if ( $chunk_support ) {
473 /**
474 * Filter: mainwp_update_plugintheme_max
475 *
476 * Filters the max number of plugins/themes to be updated in one run in order to improve performance.
477 *
478 * @param int $websiteId Child site ID.
479 *
480 * @since Unknown
481 */
482 $max_update = apply_filters( 'mainwp_update_plugintheme_max', false, $websiteId );
483 if ( empty( $max_update ) ) {
484 $chunk_support = false; // there is no hook so disable chunk update support.
485 }
486 }
487 if ( $chunk_support ) {
488 if ( isset( $_POST['chunk_slugs'] ) ) {
489 $slugs = wp_unslash( $_POST['chunk_slugs'] );
490 } else {
491 $slugs = MainWP_Updates_Handler::get_plugin_theme_slugs( $websiteId, sanitize_text_field( wp_unslash( $_POST['type'] ) ) );
492 }
493 } elseif ( isset( $_POST['slug'] ) ) {
494 $slugs = wp_unslash( $_POST['slug'] );
495 } else {
496 $slugs = MainWP_Updates_Handler::get_plugin_theme_slugs( $websiteId, sanitize_text_field( wp_unslash( $_POST['type'] ) ) );
497 }
498 }
499
500 if ( MainWP_DB_Backup::instance()->backup_full_task_running( $websiteId ) ) {
501 die( wp_json_encode( array( 'error' => __( 'Backup process in progress on the child site. Please, try again later.', 'mainwp' ) ) ) );
502 }
503
504 $chunk_slugs = array();
505
506 if ( $chunk_support ) {
507 // calculate update slugs here.
508 if ( $max_update ) {
509 $slugs = explode( ',', $slugs );
510 $chunk_slugs = array_slice( $slugs, $max_update );
511 $update_slugs = array_diff( $slugs, $chunk_slugs );
512 $slugs = implode( ',', $update_slugs );
513 }
514 }
515
516 if ( empty( $slugs ) && ! $chunk_support ) {
517 die( wp_json_encode( array( 'message' => __( 'Item slug could not be found. Update process could not be executed.', 'mainwp' ) ) ) );
518 }
519 $website = MainWP_DB::instance()->get_website_by_id( $websiteId );
520 try {
521 $info = array( 'result' => MainWP_Updates_Handler::upgrade_plugin_theme_translation( $websiteId, sanitize_text_field( wp_unslash( $_POST['type'] ) ), $slugs ) );
522
523 if ( $chunk_support && ( 0 < count( $chunk_slugs ) ) ) {
524 $info['chunk_slugs'] = implode( ',', $chunk_slugs );
525 }
526
527 if ( ! empty( $website ) ) {
528 $info['site_url'] = esc_url( $website->url );
529 }
530 wp_send_json( $info );
531 } catch ( MainWP_Exception $e ) {
532 die(
533 wp_json_encode(
534 array(
535 'error' => array(
536 'message' => $e->getMessage(),
537 'extra' => $e->get_message_extra(),
538 ),
539 )
540 )
541 );
542 }
543 }
544
545 /**
546 * Method mainwp_ignoreplugintheme()
547 *
548 * Ignore plugin or theme.
549 */
550 public function mainwp_ignoreplugintheme() {
551 $this->secure_request( 'mainwp_ignoreplugintheme' );
552
553 if ( ! isset( $_POST['id'] ) ) {
554 die( wp_json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
555 }
556 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
557 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
558 $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0;
559 wp_send_json( array( 'result' => MainWP_Updates_Handler::ignore_plugin_theme( $type, $slug, $id ) ) );
560 }
561
562 /**
563 * Method mainwp_unignoreabandonedplugintheme()
564 *
565 * Unignore abandoned plugin or theme.
566 */
567 public function mainwp_unignoreabandonedplugintheme() {
568 $this->secure_request( 'mainwp_unignoreabandonedplugintheme' );
569
570 if ( ! isset( $_POST['id'] ) ) {
571 die( wp_json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
572 }
573
574 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
575 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
576 $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : 0; // string|int.
577 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_abandoned_plugin_theme( $type, $slug, $id ) ) ) ); // ok.
578 }
579
580 /**
581 * Method mainwp_unignoreabandonedpluginthemes()
582 *
583 * Unignore abandoned plugins or themes.
584 */
585 public function mainwp_unignoreabandonedpluginsthemes() {
586 $this->secure_request( 'mainwp_unignoreabandonedpluginsthemes' );
587
588 if ( ! isset( $_POST['slug'] ) ) {
589 die( wp_json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
590 }
591
592 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
593 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
594 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_abandoned_plugins_themes( $type, $slug ) ) ) );
595 }
596
597 /**
598 * Method mainwp_dismissoutdateplugintheme()
599 *
600 * Dismiss outdated plugin or theme.
601 */
602 public function mainwp_dismissoutdateplugintheme() {
603 $this->secure_request( 'mainwp_dismissoutdateplugintheme' );
604
605 if ( ! isset( $_POST['id'] ) ) {
606 die( wp_json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
607 }
608 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
609 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
610 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
611 $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0;
612 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::dismiss_plugin_theme( $type, $slug, $name, $id ) ) ) );
613 }
614
615 /**
616 * Method mainwp_dismissoutdatepluginthemes()
617 *
618 * Dismiss outdated plugins or themes.
619 */
620 public function mainwp_dismissoutdatepluginsthemes() {
621 $this->secure_request( 'mainwp_dismissoutdatepluginsthemes' );
622
623 if ( ! mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) {
624 die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'ignore/unignore updates', 'mainwp' ) ) ) ) );
625 }
626
627 if ( ! isset( $_POST['slug'] ) ) {
628 die( wp_json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
629 }
630
631 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
632 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
633 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
634
635 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::dismiss_plugins_themes( $type, $slug, $name ) ) ) );
636 }
637
638 /**
639 * Method mainwp_unignoreplugintheme()
640 *
641 * Unignore plugin or theme.
642 */
643 public function mainwp_unignoreplugintheme() {
644 $this->secure_request( 'mainwp_unignoreplugintheme' );
645
646 if ( ! isset( $_POST['id'] ) ) {
647 die( wp_json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
648 }
649 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
650 $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : '';
651 $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
652 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_plugin_theme( $type, $slug, $id ) ) ) );
653 }
654
655 /**
656 * Method mainwp_ignorepluginthemes()
657 *
658 * Ignore plugins or themes.
659 */
660 public function mainwp_ignorepluginsthemes() {
661 $this->secure_request( 'mainwp_ignorepluginsthemes' );
662
663 if ( ! mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) {
664 die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'ignore/unignore updates', 'mainwp' ) ) ) ) );
665 }
666
667 if ( ! isset( $_POST['slug'] ) ) {
668 die( wp_json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
669 }
670
671 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
672 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
673 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
674 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::ignore_plugins_themes( $type, $slug, $name ) ) ) );
675 }
676
677 /**
678 * Method mainwp_unignorepluginthemes()
679 *
680 * Unignore plugins or themes.
681 */
682 public function mainwp_unignorepluginsthemes() {
683 $this->secure_request( 'mainwp_unignorepluginsthemes' );
684
685 if ( ! isset( $_POST['slug'] ) ) {
686 die( wp_json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
687 }
688 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
689 $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : '';
690 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_plugins_themes( $type, $slug ) ) ) );
691 }
692
693 /**
694 * Method mainwp_trust_plugin()
695 *
696 * Trust plugin.
697 */
698 public function mainwp_trust_plugin() {
699 $this->secure_request( 'mainwp_trust_plugin' );
700
701 MainWP_Plugins_Handler::trust_post();
702 die( wp_json_encode( array( 'result' => true ) ) );
703 }
704
705 /**
706 * Method mainwp_trust_theme()
707 *
708 * Trust theme.
709 */
710 public function mainwp_trust_theme() {
711 $this->secure_request( 'mainwp_trust_theme' );
712
713 MainWP_Themes_Handler::trust_post();
714 die( wp_json_encode( array( 'result' => true ) ) );
715 }
716
717 }
718