PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.1
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-post-plugin-theme-handler.php

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

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