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

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