PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / trunk
MainWP Dashboard: Self-hosted WordPress Management for Agencies vtrunk
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 trunk, at class/class-mainwp-post-plugin-theme-handler.php

1,108 lines 46.7 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 // Exit if accessed directly.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Class MainWP_Post_Plugin_Theme_Handler
17 *
18 * @package MainWP\Dashboard
19 *
20 * @uses \MainWP\Dashboard\MainWP_Post_Base_Handler
21 */
22 class MainWP_Post_Plugin_Theme_Handler extends MainWP_Post_Base_Handler { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
23 // phpcs:disable Generic.Metrics.CyclomaticComplexity -- complexity.
24 /**
25 * Protected static variable to hold the single instance of the class.
26 *
27 * @var mixed Default null
28 */
29 private static $instance = null;
30
31 /**
32 * Method instance()
33 *
34 * Create public static instance.
35 *
36 * @static
37 * @return MainWP_Post_Plugin_Theme_Handler
38 */
39 public static function instance() {
40 if ( null === static::$instance ) {
41 static::$instance = new self();
42 }
43 return static::$instance;
44 }
45
46 /**
47 * Init plugins/themes actions
48 */
49 public function init() {
50 // Page: ManageSites.
51 $this->add_action( 'mainwp_ext_prepareinstallplugintheme', array( &$this, 'mainwp_ext_prepareinstallplugintheme' ) );
52 $this->add_action( 'mainwp_ext_performinstallplugintheme', array( &$this, 'mainwp_ext_performinstallplugintheme' ) );
53
54 // Page: InstallPlugins/Themes.
55 $this->add_action( 'mainwp_preparebulkinstallplugintheme', array( &$this, 'mainwp_preparebulkinstallplugintheme' ) );
56 $this->add_action( 'mainwp_installbulkinstallplugintheme', array( &$this, 'mainwp_installbulkinstallplugintheme' ) );
57 $this->add_action( 'mainwp_preparebulkuploadplugintheme', array( &$this, 'mainwp_preparebulkuploadplugintheme' ) );
58 $this->add_action( 'mainwp_installbulkuploadplugintheme', array( &$this, 'mainwp_installbulkuploadplugintheme' ) );
59 $this->add_action( 'mainwp_cleanbulkuploadplugintheme', array( &$this, 'mainwp_cleanbulkuploadplugintheme' ) );
60 $this->add_action( 'mainwp_preparebulkinstallcheckplugin', array( &$this, 'hook_prepare_installcheck_plugin' ) );
61
62 // Widget: RightNow.
63 $this->add_action( 'mainwp_upgradewp', array( &$this, 'mainwp_upgradewp' ) );
64 $this->add_action( 'mainwp_upgradeplugintheme', array( &$this, 'mainwp_upgrade_plugintheme' ) );
65 $this->add_action( 'mainwp_ignoreplugintheme', array( &$this, 'mainwp_ignoreplugintheme' ) );
66 $this->add_action( 'mainwp_unignoreplugintheme', array( &$this, 'mainwp_unignoreplugintheme' ) );
67 $this->add_action( 'mainwp_ignorepluginsthemes', array( &$this, 'mainwp_ignorepluginsthemes' ) );
68 $this->add_action( 'mainwp_unignorepluginsthemes', array( &$this, 'mainwp_unignore_global_pluginsthemes' ) );
69 $this->add_action( 'mainwp_unignoreabandonedplugintheme', array( &$this, 'mainwp_unignoreabandonedplugintheme' ) );
70 $this->add_action( 'mainwp_unignoreabandonedpluginsthemes', array( &$this, 'mainwp_unignoreabandonedpluginsthemes' ) );
71 $this->add_action( 'mainwp_dismissoutdateplugintheme', array( &$this, 'mainwp_dismissoutdateplugintheme' ) );
72 $this->add_action( 'mainwp_dismissoutdatepluginsthemes', array( &$this, 'mainwp_dismissoutdatepluginsthemes' ) );
73 $this->add_action( 'mainwp_trust_plugin', array( &$this, 'mainwp_trust_plugin' ) );
74 $this->add_action( 'mainwp_trust_theme', array( &$this, 'mainwp_trust_theme' ) );
75 $this->add_action( 'mainwp_updates_ignore_upgrades', array( &$this, 'ajax_ignore_core_updates' ) );
76 $this->add_action( 'mainwp_updates_unignore_upgrades', array( &$this, 'ajax_unignore_core_updates' ) );
77 $this->add_action( 'mainwp_updates_unignore_global_upgrades', array( &$this, 'ajax_unignore_global_upgrades' ) );
78 $this->add_action( 'mainwp_overview_prepare_upgradeall', array( &$this, 'ajax_prepare_upgradeall' ) );
79
80 // Page: Themes.
81 $this->add_action( 'mainwp_themes_search', array( &$this, 'mainwp_themes_search' ) );
82 $this->add_action( 'mainwp_themes_search_all', array( &$this, 'mainwp_themes_search_all' ) );
83 if ( \mainwp_current_user_can( 'dashboard', 'activate_themes' ) ) {
84 $this->add_action( 'mainwp_theme_activate', array( &$this, 'mainwp_theme_activate' ) );
85 }
86 if ( \mainwp_current_user_can( 'dashboard', 'delete_themes' ) ) {
87 $this->add_action( 'mainwp_theme_delete', array( &$this, 'mainwp_theme_delete' ) );
88 }
89 $this->add_action( 'mainwp_trusted_theme_notes_save', array( &$this, 'mainwp_trusted_theme_notes_save' ) );
90 if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) {
91 $this->add_action( 'mainwp_theme_ignore_updates', array( &$this, 'mainwp_theme_ignore_updates' ) );
92 }
93
94 // Page: Plugins.
95 $this->add_action( 'mainwp_plugins_search', array( &$this, 'mainwp_plugins_search' ) );
96 $this->add_action( 'mainwp_plugins_search_all_active', array( &$this, 'mainwp_plugins_search_all_active' ) );
97
98 if ( \mainwp_current_user_can( 'dashboard', 'activate_deactivate_plugins' ) ) {
99 $this->add_action( 'mainwp_plugin_activate', array( &$this, 'mainwp_plugin_activate' ) );
100 $this->add_action( 'mainwp_plugin_deactivate', array( &$this, 'mainwp_plugin_deactivate' ) );
101 }
102 if ( \mainwp_current_user_can( 'dashboard', 'delete_plugins' ) ) {
103 $this->add_action( 'mainwp_plugin_delete', array( &$this, 'mainwp_plugin_delete' ) );
104 }
105
106 if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) {
107 $this->add_action( 'mainwp_plugin_ignore_updates', array( &$this, 'mainwp_plugin_ignore_updates' ) );
108 }
109 $this->add_action( 'mainwp_trusted_plugin_notes_save', array( &$this, 'mainwp_trusted_plugin_notes_save' ) );
110
111 // Widget: Plugins.
112 $this->add_action( 'mainwp_widget_plugin_activate', array( &$this, 'mainwp_widget_plugin_activate' ) );
113 $this->add_action( 'mainwp_widget_plugin_deactivate', array( &$this, 'mainwp_widget_plugin_deactivate' ) );
114 $this->add_action( 'mainwp_widget_plugin_delete', array( &$this, 'mainwp_widget_plugin_delete' ) );
115
116 // Widget: Themes.
117 $this->add_action( 'mainwp_widget_theme_activate', array( &$this, 'mainwp_widget_theme_activate' ) );
118 $this->add_action( 'mainwp_widget_theme_delete', array( &$this, 'mainwp_widget_theme_delete' ) );
119 }
120
121 /**
122 * Method mainwp_themes_search()
123 *
124 * Search handler for Themes.
125 *
126 * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
127 *
128 * @uses \MainWP\Dashboard\MainWP_Themes::render_table()
129 */
130 public function mainwp_themes_search() {
131 $this->secure_request( 'mainwp_themes_search' );
132 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
133 $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
134 $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
135 $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : array();
136 $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : array();
137 $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : array();
138 $not_criteria = isset( $_POST['not_criteria'] ) && 'true' === $_POST['not_criteria'] ? true : false;
139 $not_fetchdata = isset( $_POST['not_fetchdata'] ) && ! empty( $_POST['not_fetchdata'] ) ? true : false;
140
141 // phpcs:enable
142 MainWP_Cache::init_session();
143 $result = MainWP_Themes::render_table( $keyword, $status, $groups, $sites, $not_criteria, $clients, $not_fetchdata );
144 wp_send_json( $result );
145 }
146
147 /**
148 * Method mainwp_theme_activate()
149 *
150 * Activate Theme,
151 * Page: Themes.
152 *
153 * @uses \MainWP\Dashboard\MainWP_Themes_Handler::activate_theme()
154 */
155 public function mainwp_theme_activate() {
156 $this->secure_request( 'mainwp_theme_activate' );
157 MainWP_Themes_Handler::activate_theme();
158 die();
159 }
160
161 /**
162 * Method mainwp_theme_delete()
163 *
164 * Delete Theme,
165 * Page: Themes.
166 *
167 * @uses \MainWP\Dashboard\MainWP_Themes_Handler::delete_themes()
168 */
169 public function mainwp_theme_delete() {
170 $this->secure_request( 'mainwp_theme_delete' );
171 MainWP_Themes_Handler::delete_themes();
172 die();
173 }
174
175 /**
176 * Method mainwp_theme_ignore_updates()
177 *
178 * Ignore theme updates,
179 * Page: Themes.
180 *
181 * @uses \MainWP\Dashboard\MainWP_Themes_Handler::ignore_updates()
182 */
183 public function mainwp_theme_ignore_updates() {
184 $this->secure_request( 'mainwp_theme_ignore_updates' );
185 MainWP_Themes_Handler::ignore_updates();
186 die();
187 }
188
189 /**
190 * Method mainwp_themes_search_all()
191 *
192 * Search ALL handler for,
193 * Page: Themes.
194 *
195 * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
196 * @uses \MainWP\Dashboard\MainWP_Themes::render_all_themes_table()
197 */
198 public function mainwp_themes_search_all() {
199 $this->secure_request( 'mainwp_themes_search_all' );
200 MainWP_Cache::init_session();
201 MainWP_Themes::render_all_themes_table();
202 die();
203 }
204
205 /**
206 * Method mainwp_trusted_theme_notes_save()
207 *
208 * Save trusted theme notes,
209 * Page: Themes.
210 *
211 * @uses \MainWP\Dashboard\MainWP_Themes_Handler::save_trusted_theme_note()
212 */
213 public function mainwp_trusted_theme_notes_save() {
214 $this->secure_request( 'mainwp_trusted_theme_notes_save' );
215 $esc_note = MainWP_Themes_Handler::save_trusted_theme_note();
216 die(
217 wp_json_encode(
218 array(
219 'result' => 'SUCCESS',
220 'esc_note_content' => $esc_note,
221 )
222 )
223 );
224 }
225
226 /**
227 * Method mainwp_plugins_search()
228 *
229 * Search handler for Plugins.
230 *
231 * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
232 * @uses \MainWP\Dashboard\MainWP_Plugins::render_table()
233 */
234 public function mainwp_plugins_search() {
235 $this->secure_request( 'mainwp_plugins_search' );
236 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
237 $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
238 $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
239 $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
240 $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
241 $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
242 $not_criteria = isset( $_POST['not_criteria'] ) && 'true' === $_POST['not_criteria'] ? true : false;
243 $not_fetchdata = isset( $_POST['not_fetchdata'] ) && ! empty( $_POST['not_fetchdata'] ) ? true : false;
244
245 // phpcs:enable
246 MainWP_Cache::init_session();
247 $result = MainWP_Plugins::render_table( $keyword, $status, $groups, $sites, $not_criteria, $clients, $not_fetchdata );
248 wp_send_json( $result );
249 }
250
251 /**
252 * Method mainwp_plugins_search_all_active()
253 *
254 * Search all Active handler for,
255 * Page: Plugins.
256 *
257 * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
258 * @uses \MainWP\Dashboard\MainWP_Plugins::render_all_active_table()
259 */
260 public function mainwp_plugins_search_all_active() {
261 $this->secure_request( 'mainwp_plugins_search_all_active' );
262 MainWP_Cache::init_session();
263 MainWP_Plugins::render_all_active_table();
264 die();
265 }
266
267 /**
268 * Method mainwp_plugin_activate()
269 *
270 * Activate plugins,
271 * Page: Plugins.
272 *
273 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::activate_plugins()
274 */
275 public function mainwp_plugin_activate() {
276 $this->secure_request( 'mainwp_plugin_activate' );
277 MainWP_Plugins_Handler::activate_plugins();
278 die();
279 }
280
281 /**
282 * Method mainwp_plugin_deactivate()
283 *
284 * Deactivate plugins,
285 * Page: Plugins.
286 *
287 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::deactivate_plugins()
288 */
289 public function mainwp_plugin_deactivate() {
290 $this->secure_request( 'mainwp_plugin_deactivate' );
291 MainWP_Plugins_Handler::deactivate_plugins();
292 die();
293 }
294
295 /**
296 * Method mainwp_plugin_delete()
297 *
298 * Delete plugins,
299 * Page: Plugins.
300 *
301 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::delete_plugins()
302 */
303 public function mainwp_plugin_delete() {
304 $this->secure_request( 'mainwp_plugin_delete' );
305 MainWP_Plugins_Handler::delete_plugins();
306 die();
307 }
308
309 /**
310 * Method mainwp_plugin_ignore_updates()
311 *
312 * Ignore plugin updates,
313 * Page: Plugins.
314 *
315 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::ignore_updates()
316 */
317 public function mainwp_plugin_ignore_updates() {
318 $this->secure_request( 'mainwp_plugin_ignore_updates' );
319 MainWP_Plugins_Handler::ignore_updates();
320 die();
321 }
322
323 /**
324 * Method mainwp_trusted_plugin_notes_save()
325 *
326 * Save trusted plugin notes,
327 * Page: Plugins.
328 *
329 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::save_trusted_plugin_note()
330 */
331 public function mainwp_trusted_plugin_notes_save() {
332 $this->secure_request( 'mainwp_trusted_plugin_notes_save' );
333 $esc_note = MainWP_Plugins_Handler::save_trusted_plugin_note();
334 die(
335 wp_json_encode(
336 array(
337 'result' => 'SUCCESS',
338 'esc_note_content' => $esc_note,
339 )
340 )
341 );
342 }
343
344 /**
345 * Method mainwp_widget_plugin_activate()
346 *
347 * Activate plugin,
348 * Widget: Plugins.
349 *
350 * @uses \MainWP\Dashboard\MainWP_Widget_Plugins::activate_plugin()
351 */
352 public function mainwp_widget_plugin_activate() {
353 $this->secure_request( 'mainwp_widget_plugin_activate' );
354 MainWP_Widget_Plugins::activate_plugin();
355 }
356
357 /**
358 * Method mainwp_widget_plugin_deactivate()
359 *
360 * Deactivate plugin,
361 * Widget: Plugins.
362 *
363 * @uses \MainWP\Dashboard\MainWP_Widget_Plugins::deactivate_plugin()
364 */
365 public function mainwp_widget_plugin_deactivate() {
366 $this->secure_request( 'mainwp_widget_plugin_deactivate' );
367 MainWP_Widget_Plugins::deactivate_plugin();
368 }
369
370 /**
371 * Method mainwp_widget_plugin_delete()
372 *
373 * Delete plugin,
374 * Widget: Plugins.
375 *
376 * @uses \MainWP\Dashboard\MainWP_Widget_Plugins::delete_plugin()
377 */
378 public function mainwp_widget_plugin_delete() {
379 $this->secure_request( 'mainwp_widget_plugin_delete' );
380 MainWP_Widget_Plugins::delete_plugin();
381 }
382
383 /**
384 * Method mainwp_widget_theme_activate()
385 *
386 * Activate theme,
387 * Widget: Themes.
388 *
389 * @uses \MainWP\Dashboard\MainWP_Widget_Themes::activate_theme()
390 */
391 public function mainwp_widget_theme_activate() {
392 $this->secure_request( 'mainwp_widget_theme_activate' );
393 MainWP_Widget_Themes::activate_theme();
394 }
395
396 /**
397 * Method mainwp_widget_theme_delete()
398 *
399 * Delete theme,
400 * Widget: Themes.
401 *
402 * @uses \MainWP\Dashboard\MainWP_Widget_Themes::delete_theme()
403 */
404 public function mainwp_widget_theme_delete() {
405 $this->secure_request( 'mainwp_widget_theme_delete' );
406 MainWP_Widget_Themes::delete_theme();
407 }
408
409 /**
410 * Method mainwp_preparebulkinstallplugintheme()
411 *
412 * Prepair bulk installation of plugins & themes,
413 * Page: InstallPlugins/Themes.
414 *
415 * @uses \MainWP\Dashboard\MainWP_Install_Bulk::prepare_install()
416 */
417 public function mainwp_preparebulkinstallplugintheme() {
418 $this->secure_request( 'mainwp_preparebulkinstallplugintheme' );
419 MainWP_Install_Bulk::prepare_install();
420 }
421
422 /**
423 * Method mainwp_installbulkinstallplugintheme()
424 *
425 * Installation of plugins & themes,
426 * Page: InstallPlugins/Themes.
427 *
428 * @uses \MainWP\Dashboard\MainWP_Install_Bulk::perform_install()
429 */
430 public function mainwp_installbulkinstallplugintheme() {
431 $this->secure_request( 'mainwp_installbulkinstallplugintheme' );
432 MainWP_Install_Bulk::perform_install();
433 }
434
435 /**
436 * Method mainwp_preparebulkuploadplugintheme()
437 *
438 * Prepair bulk upload of plugins & themes,
439 * Page: InstallPlugins/Themes.
440 *
441 * @uses \MainWP\Dashboard\MainWP_Install_Bulk::prepare_upload()
442 */
443 public function mainwp_preparebulkuploadplugintheme() {
444 $this->secure_request( 'mainwp_preparebulkuploadplugintheme' );
445 MainWP_Install_Bulk::prepare_upload();
446 }
447
448 /**
449 * Method mainwp_installbulkuploadplugintheme()
450 *
451 * Bulk upload of plugins & themes,
452 * Page: InstallPlugins/Themes.
453 *
454 * @uses \MainWP\Dashboard\MainWP_Install_Bulk::perform_upload()
455 */
456 public function mainwp_installbulkuploadplugintheme() {
457 $this->secure_request( 'mainwp_installbulkuploadplugintheme' );
458 MainWP_Install_Bulk::perform_upload();
459 }
460
461 /**
462 * Method mainwp_cleanbulkuploadplugintheme()
463 *
464 * Clean upload of plugins & themes,
465 * Page: InstallPlugins/Themes.
466 *
467 * @uses \MainWP\Dashboard\MainWP_Install_Bulk::clean_upload()
468 */
469 public function mainwp_cleanbulkuploadplugintheme() {
470 $this->secure_request( 'mainwp_cleanbulkuploadplugintheme' );
471 MainWP_Install_Bulk::clean_upload();
472 }
473
474 /**
475 * Method mainwp_ext_prepareinstallplugintheme()
476 *
477 * Prepair Installation of plugins & themes,
478 * Page: ManageSites.
479 */
480 public function mainwp_ext_prepareinstallplugintheme() {
481 do_action( 'mainwp_prepareinstallplugintheme' );
482 }
483
484 /**
485 * Method mainwp_ext_performinstallplugintheme()
486 *
487 * Installation of plugins & themes,
488 * Page: ManageSites.
489 */
490 public function mainwp_ext_performinstallplugintheme() {
491 $this->secure_request( 'mainwp_ext_performinstallplugintheme' );
492 do_action( 'mainwp_performinstallplugintheme' );
493 }
494
495 /**
496 * Method hook_prepare_installcheck_plugin()
497 *
498 * Prepair bulk installation of plugins,
499 */
500 public function hook_prepare_installcheck_plugin() {
501 $this->secure_request( 'mainwp_preparebulkinstallcheckplugin' );
502 include_once ABSPATH . '/wp-admin/includes/plugin-install.php'; // NOSONAR - WP compatible.
503 $api = MainWP_System_Utility::get_plugin_theme_info(
504 'plugin',
505 array(
506 'slug' => isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '', // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
507 'fields' => array( 'sections' => false ),
508 )
509 ); // Save on a bit of bandwidth.
510 $url = $api->download_link;
511 $output = array();
512 $output['url'] = $url;
513 wp_send_json( $output );
514 }
515
516 /**
517 * Method mainwp_upgradewp()
518 *
519 * Update a specific WP core.
520 *
521 * @uses \MainWP\Dashboard\MainWP_Exception
522 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::upgrade_site()
523 */
524 public function mainwp_upgradewp() {
525 if ( ! \mainwp_current_user_can( 'dashboard', 'update_wordpress' ) ) {
526 die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'update WordPress', 'mainwp' ), false ) ) ) );
527 }
528
529 $this->secure_request( 'mainwp_upgradewp' );
530
531 try {
532 $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
533 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::upgrade_site( $id ) ) ) ); // ok.
534 } catch ( MainWP_Exception $e ) {
535 die(
536 wp_json_encode(
537 array(
538 'error' => array(
539 'message' => $e->getMessage(),
540 'extra' => $e->get_message_extra(),
541 'errorCode' => $e->get_message_error_code(),
542 ),
543 )
544 )
545 );
546 }
547 }
548
549
550 /**
551 * Method ajax_prepare_upgradeall()
552 *
553 * Prepare update all.
554 */
555 public function ajax_prepare_upgradeall() {
556 $this->secure_request( 'mainwp_overview_prepare_upgradeall' );
557
558 $update_type = isset( $_POST['which'] ) ? sanitize_text_field( wp_unslash( $_POST['which'] ) ) : ''; // phpcs:ignore --NOSONAR - none verified.
559 if ( ! in_array( $update_type, array( 'all', 'plugin', 'theme', 'translation', 'wp' ), true ) ) {
560 ?>
561 <div class="ui yellow message"><i class="close icon"></i> <?php esc_html_e( 'Invalid update type. Please try again.', 'mainwp' ); ?></div>
562 <?php
563 die();
564 }
565 $current_siteid = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : 0; // phpcs:ignore --NOSONAR - none verified.
566
567 if ( 'translation' === $update_type ) {
568 $update_type = 'trans'; // compatible.
569 } elseif ( 'wp' === $update_type ) {
570 $update_type = 'core'; // compatible.
571 }
572
573 $data = MainWP_Updates_Overview::prepare_update_data( $update_type, $current_siteid );
574
575 $data = wp_parse_args(
576 $data,
577 array(
578 'total_wp_upgrades' => 0,
579 'all_wp_updates' => array(),
580 'total_plugin_upgrades' => 0,
581 'all_plugins_updates' => array(),
582 'total_theme_upgrades' => 0,
583 'all_themes_updates' => array(),
584 'total_translation_upgrades' => 0,
585 'all_translations_updates' => array(),
586 )
587 );
588
589 extract( $data ); // phpcs:ignore -- NOSONAR - well structure.
590
591 $user_can_update_translation = \mainwp_current_user_can( 'dashboard', 'update_translations' );
592 $user_can_update_wordpress = \mainwp_current_user_can( 'dashboard', 'update_wordpress' );
593 $user_can_update_themes = \mainwp_current_user_can( 'dashboard', 'update_themes' );
594 $user_can_update_plugins = \mainwp_current_user_can( 'dashboard', 'update_plugins' );
595
596 $mainwp_show_language_updates = get_option( 'mainwp_show_language_updates', 1 );
597
598 MainWP_Updates_Overview::render_global_update(
599 $update_type,
600 $user_can_update_wordpress,
601 $total_wp_upgrades,
602 $all_wp_updates,
603 $user_can_update_plugins,
604 $total_plugin_upgrades,
605 $all_plugins_updates,
606 $user_can_update_themes,
607 $total_theme_upgrades,
608 $all_themes_updates,
609 $mainwp_show_language_updates,
610 $user_can_update_translation,
611 $total_translation_upgrades,
612 $all_translations_updates
613 );
614
615 die();
616 }
617
618 /**
619 * Method mainwp_upgrade_plugintheme()
620 *
621 * Update plugin or theme.
622 *
623 * @uses \MainWP\Dashboard\MainWP_DB_Backup::backup_full_task_running()
624 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
625 * @uses \MainWP\Dashboard\MainWP_Exception
626 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::get_plugin_theme_slugs()
627 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::upgrade_plugin_theme_translation()
628 */
629 public function mainwp_upgrade_plugintheme() { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
630
631 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
632 if ( ! isset( $_POST['type'] ) ) {
633 die( wp_json_encode( array( 'error' => '<i class="red times icon"></i> ' . esc_html__( 'Plugin or theme not specified. Please reload the page and try again.', 'mainwp' ) ) ) );
634 }
635
636 if ( 'plugin' === $_POST['type'] && ! \mainwp_current_user_can( 'dashboard', 'update_plugins' ) ) {
637 die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'update plugins', 'mainwp' ), false ) ) ) );
638 }
639
640 if ( 'theme' === $_POST['type'] && ! \mainwp_current_user_can( 'dashboard', 'update_themes' ) ) {
641 die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'update themes', 'mainwp' ), false ) ) ) );
642 }
643
644 if ( 'translation' === $_POST['type'] && ! \mainwp_current_user_can( 'dashboard', 'update_translations' ) ) {
645 die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'update translations', 'mainwp' ), false ) ) ) );
646 }
647
648 $this->secure_request( 'mainwp_upgradeplugintheme' );
649
650 // support chunk update for manage sites page only.
651 $chunk_support = ! empty( $_POST['chunk_support'] ) ? true : false;
652 $max_update = 0;
653 $websiteId = null;
654 $slugs = '';
655
656 if ( isset( $_POST['websiteId'] ) ) {
657 $websiteId = intval( $_POST['websiteId'] );
658
659 if ( $chunk_support ) {
660 /**
661 * Filter: mainwp_update_plugintheme_max
662 *
663 * Filters the max number of plugins/themes to be updated in one run in order to improve performance.
664 *
665 * @param int $websiteId Child site ID.
666 *
667 * @since Unknown
668 */
669 $max_update = apply_filters( 'mainwp_update_plugintheme_max', false, $websiteId );
670 if ( empty( $max_update ) ) {
671 $chunk_support = false; // there is no hook so disable chunk update support.
672 }
673 }
674 if ( $chunk_support ) {
675 if ( isset( $_POST['chunk_slugs'] ) ) {
676 $slugs = wp_unslash( $_POST['chunk_slugs'] );
677 } else {
678 $slugs = MainWP_Updates_Handler::get_plugin_theme_slugs( $websiteId, sanitize_text_field( wp_unslash( $_POST['type'] ) ) );
679 }
680 } elseif ( isset( $_POST['slug'] ) ) {
681 $slugs = wp_unslash( $_POST['slug'] );
682 } else {
683 $slugs = MainWP_Updates_Handler::get_plugin_theme_slugs( $websiteId, sanitize_text_field( wp_unslash( $_POST['type'] ) ) );
684 }
685 }
686 // phpcs:enable
687
688 if ( MainWP_DB_Backup::instance()->backup_full_task_running( $websiteId ) ) {
689 die( wp_json_encode( array( 'error' => esc_html__( 'Backup process in progress on the child site. Please, try again later.', 'mainwp' ) ) ) );
690 }
691
692 $chunk_slugs = array();
693
694 if ( $chunk_support && $max_update ) {
695 $slugs = explode( ',', $slugs );
696 $chunk_slugs = array_slice( $slugs, $max_update );
697 $update_slugs = array_diff( $slugs, $chunk_slugs );
698 $slugs = implode( ',', $update_slugs );
699 }
700
701 if ( empty( $slugs ) && ! $chunk_support ) {
702 die( wp_json_encode( array( 'message' => esc_html__( 'Item slug could not be found. Update process could not be executed.', 'mainwp' ) ) ) );
703 }
704 $website = MainWP_DB::instance()->get_website_by_id( $websiteId );
705 try {
706 $info = array(
707 'result' => array(),
708 'result_error' => array(),
709 'result_started' => array(),
710 );
711
712 $result = MainWP_Updates_Handler::upgrade_plugin_theme_translation( $websiteId, sanitize_text_field( wp_unslash( $_POST['type'] ) ), $slugs ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
713
714 if ( is_array( $result ) ) {
715 if ( isset( $result['result'] ) ) {
716 $info['result'] = $result['result'];
717 }
718 if ( isset( $result['result_error'] ) ) {
719 $info['result_error'] = $result['result_error'];
720 }
721 if ( isset( $result['result_started'] ) ) {
722 $info['result_started'] = $result['result_started'];
723 }
724 }
725
726 // MWP-1660: append a generic licensing hint to failures of known premium
727 // products; vendors only deliver update packages to licensed installs.
728 $item_type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
729 if ( ( 'plugin' === $item_type || 'theme' === $item_type ) && ! empty( $info['result_error'] ) && is_array( $info['result_error'] ) ) {
730 $premium_ids = MainWP_Premium_Update_Registry::get_filter_defaults( $item_type, 'detect' );
731 $premium_prefixes = MainWP_Premium_Update_Registry::get_prefixes( $item_type, 'detect' );
732 foreach ( $info['result_error'] as $err_slug => $err_msg ) {
733 if ( is_string( $err_msg ) && MainWP_Premium_Update_Registry::slug_matches( urldecode( $err_slug ), $premium_ids, $premium_prefixes ) ) {
734 $info['result_error'][ $err_slug ] = $err_msg . ' ' . esc_html__( 'Premium updates usually require an active license on the child site; check that first.', 'mainwp' );
735 }
736 }
737 }
738
739 if ( $chunk_support && ( ! empty( $chunk_slugs ) ) ) {
740 $info['chunk_slugs'] = implode( ',', $chunk_slugs );
741 }
742
743 if ( ! empty( $website ) ) {
744 $info['site_url'] = esc_url( $website->url );
745 }
746
747 // Get max the scope of the largest change.
748 $max_scope = apply_filters( 'mainwp_html_regression_largest_change_scope', $websiteId, false );
749 if ( ! empty( $max_scope ) && $max_scope !== $websiteId ) {
750 $info['result']['html_regression_max_scope'] = $max_scope;
751 }
752
753 wp_send_json( $info );
754 } catch ( MainWP_Exception $e ) {
755 die(
756 wp_json_encode(
757 array(
758 'error' => array(
759 'message' => $e->getMessage(),
760 'extra' => $e->get_message_extra(),
761 'errorCode' => $e->get_message_error_code(),
762 ),
763 )
764 )
765 );
766 }
767 }
768
769 /**
770 * Method mainwp_ignoreplugintheme()
771 *
772 * Ignores a plugin or a theme.
773 */
774 public function mainwp_ignoreplugintheme() {
775 $this->secure_request( 'mainwp_ignoreplugintheme' );
776
777 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
778 if ( ! isset( $_POST['id'] ) ) {
779 die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
780 }
781 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
782 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
783 $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0;
784 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
785 $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
786 // phpcs:enable
787 wp_send_json( array( 'result' => MainWP_Updates_Handler::ignore_plugin_theme( $type, $slug, $name, $id, $ver ) ) );
788 }
789
790
791 /**
792 * Method mainwp_unignore_global_pluginsthemes()
793 *
794 * Unignore plugins or themes.
795 */
796 public function mainwp_unignore_global_pluginsthemes() {
797 $this->secure_request( 'mainwp_unignorepluginsthemes' );
798
799 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
800 if ( ! isset( $_POST['slug'] ) ) {
801 die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
802 }
803 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
804 $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : '';
805 $ver = isset( $_POST['ignore_ver'] ) ? wp_unslash( $_POST['ignore_ver'] ) : '';
806 // phpcs:enable
807 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_global_plugins_themes( $type, $slug, $ver ) ) ) );
808 }
809
810 /**
811 * Method mainwp_unignoreabandonedplugintheme()
812 *
813 * Unignore abandoned plugin or theme.
814 *
815 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugin_theme()
816 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_abandoned_plugin_theme()
817 */
818 public function mainwp_unignoreabandonedplugintheme() {
819 $this->secure_request( 'mainwp_unignoreabandonedplugintheme' );
820
821 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
822 if ( ! isset( $_POST['id'] ) ) {
823 die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
824 }
825
826 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
827 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
828 $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : 0; // string|int.
829 // phpcs:enable
830 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_abandoned_plugin_theme( $type, $slug, $id ) ) ) ); // ok.
831 }
832
833 /**
834 * Method mainwp_unignoreabandonedpluginthemes()
835 *
836 * Unignore abandoned plugins or themes.
837 *
838 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_abandoned_plugins_themes()
839 */
840 public function mainwp_unignoreabandonedpluginsthemes() {
841 $this->secure_request( 'mainwp_unignoreabandonedpluginsthemes' );
842
843 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
844 if ( ! isset( $_POST['slug'] ) ) {
845 die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
846 }
847
848 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
849 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
850 // phpcs:enable
851 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_abandoned_plugins_themes( $type, $slug ) ) ) );
852 }
853
854 /**
855 * Method mainwp_dismissoutdateplugintheme()
856 *
857 * Dismiss outdated plugin or theme.
858 *
859 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::dismiss_plugin_theme()
860 */
861 public function mainwp_dismissoutdateplugintheme() {
862 $this->secure_request( 'mainwp_dismissoutdateplugintheme' );
863
864 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
865 if ( ! isset( $_POST['id'] ) ) {
866 die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
867 }
868 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
869 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
870 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
871 $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0;
872 // phpcs:enable
873 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::dismiss_plugin_theme( $type, $slug, $name, $id ) ) ) );
874 }
875
876 /**
877 * Method mainwp_dismissoutdatepluginthemes()
878 *
879 * Dismiss outdated plugins or themes.
880 *
881 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::dismiss_plugins_themes()
882 */
883 public function mainwp_dismissoutdatepluginsthemes() {
884 $this->secure_request( 'mainwp_dismissoutdatepluginsthemes' );
885
886 if ( ! \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) {
887 die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'ignore/unignore updates', 'mainwp' ) ) ) ) );
888 }
889
890 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
891 if ( ! isset( $_POST['slug'] ) ) {
892 die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
893 }
894
895 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
896 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
897 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
898 // phpcs:enable
899
900 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::dismiss_plugins_themes( $type, $slug, $name ) ) ) );
901 }
902
903 /**
904 * Method mainwp_unignoreplugintheme()
905 *
906 * Unignore plugin or theme.
907 *
908 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_plugin_theme()
909 */
910 public function mainwp_unignoreplugintheme() {
911 $this->secure_request( 'mainwp_unignoreplugintheme' );
912
913 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
914 if ( ! isset( $_POST['id'] ) ) {
915 die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
916 }
917 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
918 $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : '';
919 $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
920 $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
921
922 // phpcs:enable
923 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_plugin_theme( $type, $slug, $id, $ver ) ) ) );
924 }
925
926 /**
927 * Method mainwp_ignorepluginsthemes()
928 *
929 * Ignore plugins or themes.
930 *
931 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugins_themes()
932 */
933 public function mainwp_ignorepluginsthemes() {
934 $this->secure_request( 'mainwp_ignorepluginsthemes' );
935
936 if ( ! \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) {
937 die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'ignore/unignore updates', 'mainwp' ) ) ) ) );
938 }
939
940 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
941 if ( ! isset( $_POST['slug'] ) ) {
942 die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
943 }
944
945 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
946 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
947 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
948 $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
949
950 // phpcs:enable
951 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::ignore_plugins_themes( $type, $slug, $name, $ver ) ) ) );
952 }
953
954 /**
955 * Method ajax_ignore_core_updates()
956 *
957 * Ignore plugins or themes.
958 *
959 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugins_themes()
960 */
961 public function ajax_ignore_core_updates() { //phpcs:ignore -- NOSONAR complex function.
962
963 $this->secure_request( 'mainwp_updates_ignore_upgrades' );
964
965 if ( ! \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) {
966 die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'ignore/unignore updates', 'mainwp' ) ) ) ) );
967 }
968
969 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
970 if ( empty( $_POST['slug'] ) ) {
971 die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
972 }
973
974 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
975 $ignore = isset( $_POST['ignore'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore'] ) ) : '';
976 $site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : 0;
977 $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
978
979 if ( 'wp' === $type ) {
980 if ( ( 'this_version' === $ignore || 'all_versions' === $ignore ) && $site_id ) {
981 $website = MainWP_DB::instance()->get_website_by_id( $site_id, false, array( 'ignored_wp_upgrades' ) );
982
983 if ( empty( $website ) ) {
984 wp_send_json( array( 'error' => esc_html__( 'Site ID invalid or site not found. Please try again.', 'mainwp' ) ) );
985 }
986
987 $ignored_upgrades = ! empty( $website->ignored_wp_upgrades ) ? json_decode( $website->ignored_wp_upgrades, true ) : array();
988
989 if ( ! is_array( $ignored_upgrades ) ) {
990 $ignored_upgrades = array();
991 }
992
993 $ignored_vers = is_array( $ignored_upgrades ) && isset( $ignored_upgrades['ignored_versions'] ) ? $ignored_upgrades['ignored_versions'] : array();
994 if ( ! is_array( $ignored_vers ) ) {
995 $ignored_vers = array();
996 }
997
998 if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all.
999 $ignored_vers = array( 'all_versions' );
1000 } else {
1001 $ver = urldecode( $ver );
1002 if ( ! in_array( $ver, $ignored_vers ) ) {
1003 $ignored_vers[] = $ver;
1004 }
1005 }
1006
1007 $ignored_upgrades['ignored_versions'] = $ignored_vers;
1008
1009 MainWP_DB::instance()->update_website_option(
1010 $site_id,
1011 'ignored_wp_upgrades',
1012 wp_json_encode( $ignored_upgrades )
1013 );
1014
1015 wp_send_json( array( 'success' => 1 ) );
1016
1017 } elseif ( 'this_version_global' === $ignore ) {
1018
1019 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1020 $decodedIgnoredCores = ! empty( $userExtension->ignored_wp_upgrades ) ? json_decode( $userExtension->ignored_wp_upgrades, true ) : array();
1021
1022 if ( ! is_array( $decodedIgnoredCores ) ) {
1023 $decodedIgnoredCores = array();
1024 }
1025
1026 $ignored_vers = isset( $decodedIgnoredCores['ignored_versions'] ) ? $decodedIgnoredCores['ignored_versions'] : array();
1027
1028 if ( ! is_array( $ignored_vers ) ) {
1029 $ignored_vers = array();
1030 }
1031
1032 $ver = urldecode( $ver );
1033 if ( ! in_array( $ver, $ignored_vers ) ) {
1034 $ignored_vers[] = $ver;
1035 }
1036
1037 $decodedIgnoredCores['ignored_versions'] = $ignored_vers;
1038
1039 MainWP_DB_Common::instance()->update_user_extension(
1040 array(
1041 'userid' => null,
1042 'ignored_wp_upgrades' => wp_json_encode( $decodedIgnoredCores ),
1043 )
1044 );
1045 wp_send_json( array( 'success' => 1 ) );
1046 }
1047 }
1048 wp_send_json( array( 'error' => esc_html__( 'Invalid types. Please try again.', 'mainwp' ) ) );
1049 }
1050
1051 /**
1052 * Method ajax_unignore_core_updates()
1053 *
1054 * Unignore plugin or theme.
1055 */
1056 public function ajax_unignore_core_updates() {
1057 $this->secure_request( 'mainwp_updates_unignore_upgrades' );
1058 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1059 $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : ''; // numberic id or _ALL_.
1060 $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
1061 // phpcs:enable
1062 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_core_updates( $id, $ver ) ) ) );
1063 }
1064
1065
1066 /**
1067 * Method ajax_unignore_global_upgrades()
1068 *
1069 * Unignore plugin or theme.
1070 */
1071 public function ajax_unignore_global_upgrades() {
1072 $this->secure_request( 'mainwp_updates_unignore_global_upgrades' );
1073 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1074 $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : '';
1075 $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
1076 // phpcs:enable
1077 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_global_cores( $slug, $ver ) ) ) );
1078 }
1079
1080
1081 /**
1082 * Method mainwp_trust_plugin()
1083 *
1084 * Trust plugin.
1085 *
1086 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_post()
1087 * @uses \MainWP\Dashboard\MainWP_Themes_Handler::trust_post()
1088 */
1089 public function mainwp_trust_plugin() {
1090 $this->secure_request( 'mainwp_trust_plugin' );
1091
1092 MainWP_Plugins_Handler::trust_post();
1093 die( wp_json_encode( array( 'result' => true ) ) );
1094 }
1095
1096 /**
1097 * Method mainwp_trust_theme()
1098 *
1099 * Trust theme.
1100 */
1101 public function mainwp_trust_theme() {
1102 $this->secure_request( 'mainwp_trust_theme' );
1103
1104 MainWP_Themes_Handler::trust_post();
1105 die( wp_json_encode( array( 'result' => true ) ) );
1106 }
1107 }
1108