PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.2 6.2.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 All 155 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 6.2.2, at class/class-mainwp-post-plugin-theme-handler.php

1,109 lines 46.8 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 // for backward compatibility.
722 if ( isset( $result['result_started'] ) ) {
723 $info['result_started'] = $result['result_started'];
724 }
725 }
726
727 // MWP-1660: append a generic licensing hint to failures of known premium
728 // products; vendors only deliver update packages to licensed installs.
729 $item_type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
730 if ( ( 'plugin' === $item_type || 'theme' === $item_type ) && ! empty( $info['result_error'] ) && is_array( $info['result_error'] ) ) {
731 $premium_ids = MainWP_Premium_Update_Registry::get_filter_defaults( $item_type, 'detect' );
732 $premium_prefixes = MainWP_Premium_Update_Registry::get_prefixes( $item_type, 'detect' );
733 foreach ( $info['result_error'] as $err_slug => $err_msg ) {
734 if ( is_string( $err_msg ) && MainWP_Premium_Update_Registry::slug_matches( urldecode( $err_slug ), $premium_ids, $premium_prefixes ) ) {
735 $info['result_error'][ $err_slug ] = $err_msg . ' ' . esc_html__( 'Premium updates usually require an active license on the child site; check that first.', 'mainwp' );
736 }
737 }
738 }
739
740 if ( $chunk_support && ( ! empty( $chunk_slugs ) ) ) {
741 $info['chunk_slugs'] = implode( ',', $chunk_slugs );
742 }
743
744 if ( ! empty( $website ) ) {
745 $info['site_url'] = esc_url( $website->url );
746 }
747
748 // Get max the scope of the largest change.
749 $max_scope = apply_filters( 'mainwp_html_regression_largest_change_scope', $websiteId, false );
750 if ( ! empty( $max_scope ) && $max_scope !== $websiteId ) {
751 $info['result']['html_regression_max_scope'] = $max_scope;
752 }
753
754 wp_send_json( $info );
755 } catch ( MainWP_Exception $e ) {
756 die(
757 wp_json_encode(
758 array(
759 'error' => array(
760 'message' => $e->getMessage(),
761 'extra' => $e->get_message_extra(),
762 'errorCode' => $e->get_message_error_code(),
763 ),
764 )
765 )
766 );
767 }
768 }
769
770 /**
771 * Method mainwp_ignoreplugintheme()
772 *
773 * Ignores a plugin or a theme.
774 */
775 public function mainwp_ignoreplugintheme() {
776 $this->secure_request( 'mainwp_ignoreplugintheme' );
777
778 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
779 if ( ! isset( $_POST['id'] ) ) {
780 die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
781 }
782 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
783 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
784 $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0;
785 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
786 $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
787 // phpcs:enable
788 wp_send_json( array( 'result' => MainWP_Updates_Handler::ignore_plugin_theme( $type, $slug, $name, $id, $ver ) ) );
789 }
790
791
792 /**
793 * Method mainwp_unignore_global_pluginsthemes()
794 *
795 * Unignore plugins or themes.
796 */
797 public function mainwp_unignore_global_pluginsthemes() {
798 $this->secure_request( 'mainwp_unignorepluginsthemes' );
799
800 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
801 if ( ! isset( $_POST['slug'] ) ) {
802 die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
803 }
804 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
805 $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : '';
806 $ver = isset( $_POST['ignore_ver'] ) ? wp_unslash( $_POST['ignore_ver'] ) : '';
807 // phpcs:enable
808 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_global_plugins_themes( $type, $slug, $ver ) ) ) );
809 }
810
811 /**
812 * Method mainwp_unignoreabandonedplugintheme()
813 *
814 * Unignore abandoned plugin or theme.
815 *
816 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugin_theme()
817 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_abandoned_plugin_theme()
818 */
819 public function mainwp_unignoreabandonedplugintheme() {
820 $this->secure_request( 'mainwp_unignoreabandonedplugintheme' );
821
822 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
823 if ( ! isset( $_POST['id'] ) ) {
824 die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
825 }
826
827 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
828 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
829 $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : 0; // string|int.
830 // phpcs:enable
831 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_abandoned_plugin_theme( $type, $slug, $id ) ) ) ); // ok.
832 }
833
834 /**
835 * Method mainwp_unignoreabandonedpluginthemes()
836 *
837 * Unignore abandoned plugins or themes.
838 *
839 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_abandoned_plugins_themes()
840 */
841 public function mainwp_unignoreabandonedpluginsthemes() {
842 $this->secure_request( 'mainwp_unignoreabandonedpluginsthemes' );
843
844 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
845 if ( ! isset( $_POST['slug'] ) ) {
846 die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
847 }
848
849 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
850 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
851 // phpcs:enable
852 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_abandoned_plugins_themes( $type, $slug ) ) ) );
853 }
854
855 /**
856 * Method mainwp_dismissoutdateplugintheme()
857 *
858 * Dismiss outdated plugin or theme.
859 *
860 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::dismiss_plugin_theme()
861 */
862 public function mainwp_dismissoutdateplugintheme() {
863 $this->secure_request( 'mainwp_dismissoutdateplugintheme' );
864
865 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
866 if ( ! isset( $_POST['id'] ) ) {
867 die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
868 }
869 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
870 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
871 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
872 $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0;
873 // phpcs:enable
874 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::dismiss_plugin_theme( $type, $slug, $name, $id ) ) ) );
875 }
876
877 /**
878 * Method mainwp_dismissoutdatepluginthemes()
879 *
880 * Dismiss outdated plugins or themes.
881 *
882 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::dismiss_plugins_themes()
883 */
884 public function mainwp_dismissoutdatepluginsthemes() {
885 $this->secure_request( 'mainwp_dismissoutdatepluginsthemes' );
886
887 if ( ! \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) {
888 die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'ignore/unignore updates', 'mainwp' ) ) ) ) );
889 }
890
891 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
892 if ( ! isset( $_POST['slug'] ) ) {
893 die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
894 }
895
896 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
897 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
898 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
899 // phpcs:enable
900
901 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::dismiss_plugins_themes( $type, $slug, $name ) ) ) );
902 }
903
904 /**
905 * Method mainwp_unignoreplugintheme()
906 *
907 * Unignore plugin or theme.
908 *
909 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_plugin_theme()
910 */
911 public function mainwp_unignoreplugintheme() {
912 $this->secure_request( 'mainwp_unignoreplugintheme' );
913
914 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
915 if ( ! isset( $_POST['id'] ) ) {
916 die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
917 }
918 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
919 $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : '';
920 $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
921 $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
922
923 // phpcs:enable
924 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_plugin_theme( $type, $slug, $id, $ver ) ) ) );
925 }
926
927 /**
928 * Method mainwp_ignorepluginsthemes()
929 *
930 * Ignore plugins or themes.
931 *
932 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugins_themes()
933 */
934 public function mainwp_ignorepluginsthemes() {
935 $this->secure_request( 'mainwp_ignorepluginsthemes' );
936
937 if ( ! \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) {
938 die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'ignore/unignore updates', 'mainwp' ) ) ) ) );
939 }
940
941 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
942 if ( ! isset( $_POST['slug'] ) ) {
943 die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
944 }
945
946 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
947 $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
948 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
949 $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
950
951 // phpcs:enable
952 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::ignore_plugins_themes( $type, $slug, $name, $ver ) ) ) );
953 }
954
955 /**
956 * Method ajax_ignore_core_updates()
957 *
958 * Ignore plugins or themes.
959 *
960 * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugins_themes()
961 */
962 public function ajax_ignore_core_updates() { //phpcs:ignore -- NOSONAR complex function.
963
964 $this->secure_request( 'mainwp_updates_ignore_upgrades' );
965
966 if ( ! \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) {
967 die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'ignore/unignore updates', 'mainwp' ) ) ) ) );
968 }
969
970 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
971 if ( empty( $_POST['slug'] ) ) {
972 die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
973 }
974
975 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
976 $ignore = isset( $_POST['ignore'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore'] ) ) : '';
977 $site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : 0;
978 $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
979
980 if ( 'wp' === $type ) {
981 if ( ( 'this_version' === $ignore || 'all_versions' === $ignore ) && $site_id ) {
982 $website = MainWP_DB::instance()->get_website_by_id( $site_id, false, array( 'ignored_wp_upgrades' ) );
983
984 if ( empty( $website ) ) {
985 wp_send_json( array( 'error' => esc_html__( 'Site ID invalid or site not found. Please try again.', 'mainwp' ) ) );
986 }
987
988 $ignored_upgrades = ! empty( $website->ignored_wp_upgrades ) ? json_decode( $website->ignored_wp_upgrades, true ) : array();
989
990 if ( ! is_array( $ignored_upgrades ) ) {
991 $ignored_upgrades = array();
992 }
993
994 $ignored_vers = is_array( $ignored_upgrades ) && isset( $ignored_upgrades['ignored_versions'] ) ? $ignored_upgrades['ignored_versions'] : array();
995 if ( ! is_array( $ignored_vers ) ) {
996 $ignored_vers = array();
997 }
998
999 if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all.
1000 $ignored_vers = array( 'all_versions' );
1001 } else {
1002 $ver = urldecode( $ver );
1003 if ( ! in_array( $ver, $ignored_vers ) ) {
1004 $ignored_vers[] = $ver;
1005 }
1006 }
1007
1008 $ignored_upgrades['ignored_versions'] = $ignored_vers;
1009
1010 MainWP_DB::instance()->update_website_option(
1011 $site_id,
1012 'ignored_wp_upgrades',
1013 wp_json_encode( $ignored_upgrades )
1014 );
1015
1016 wp_send_json( array( 'success' => 1 ) );
1017
1018 } elseif ( 'this_version_global' === $ignore ) {
1019
1020 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1021 $decodedIgnoredCores = ! empty( $userExtension->ignored_wp_upgrades ) ? json_decode( $userExtension->ignored_wp_upgrades, true ) : array();
1022
1023 if ( ! is_array( $decodedIgnoredCores ) ) {
1024 $decodedIgnoredCores = array();
1025 }
1026
1027 $ignored_vers = isset( $decodedIgnoredCores['ignored_versions'] ) ? $decodedIgnoredCores['ignored_versions'] : array();
1028
1029 if ( ! is_array( $ignored_vers ) ) {
1030 $ignored_vers = array();
1031 }
1032
1033 $ver = urldecode( $ver );
1034 if ( ! in_array( $ver, $ignored_vers ) ) {
1035 $ignored_vers[] = $ver;
1036 }
1037
1038 $decodedIgnoredCores['ignored_versions'] = $ignored_vers;
1039
1040 MainWP_DB_Common::instance()->update_user_extension(
1041 array(
1042 'userid' => null,
1043 'ignored_wp_upgrades' => wp_json_encode( $decodedIgnoredCores ),
1044 )
1045 );
1046 wp_send_json( array( 'success' => 1 ) );
1047 }
1048 }
1049 wp_send_json( array( 'error' => esc_html__( 'Invalid types. Please try again.', 'mainwp' ) ) );
1050 }
1051
1052 /**
1053 * Method ajax_unignore_core_updates()
1054 *
1055 * Unignore plugin or theme.
1056 */
1057 public function ajax_unignore_core_updates() {
1058 $this->secure_request( 'mainwp_updates_unignore_upgrades' );
1059 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1060 $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : ''; // numberic id or _ALL_.
1061 $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
1062 // phpcs:enable
1063 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_core_updates( $id, $ver ) ) ) );
1064 }
1065
1066
1067 /**
1068 * Method ajax_unignore_global_upgrades()
1069 *
1070 * Unignore plugin or theme.
1071 */
1072 public function ajax_unignore_global_upgrades() {
1073 $this->secure_request( 'mainwp_updates_unignore_global_upgrades' );
1074 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1075 $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : '';
1076 $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
1077 // phpcs:enable
1078 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_global_cores( $slug, $ver ) ) ) );
1079 }
1080
1081
1082 /**
1083 * Method mainwp_trust_plugin()
1084 *
1085 * Trust plugin.
1086 *
1087 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_post()
1088 * @uses \MainWP\Dashboard\MainWP_Themes_Handler::trust_post()
1089 */
1090 public function mainwp_trust_plugin() {
1091 $this->secure_request( 'mainwp_trust_plugin' );
1092
1093 MainWP_Plugins_Handler::trust_post();
1094 die( wp_json_encode( array( 'result' => true ) ) );
1095 }
1096
1097 /**
1098 * Method mainwp_trust_theme()
1099 *
1100 * Trust theme.
1101 */
1102 public function mainwp_trust_theme() {
1103 $this->secure_request( 'mainwp_trust_theme' );
1104
1105 MainWP_Themes_Handler::trust_post();
1106 die( wp_json_encode( array( 'result' => true ) ) );
1107 }
1108 }
1109