PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / trunk
MainWP Dashboard: Self-hosted WordPress Management for Agencies vtrunk
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
← All changes | class/class-mainwp-post-plugin-theme-handler.php +139 -22 5.3trunk View file →
@@ -6,8 +6,13 @@
6 6 */
7 7
8 8 namespace MainWP\Dashboard;
9 9
10 +// Exit if accessed directly.
11 +if ( ! defined( 'ABSPATH' ) ) {
12 + exit;
13 +}
14 +
10 15 /**
11 16 * Class MainWP_Post_Plugin_Theme_Handler
12 17 *
13 18 * @package MainWP\Dashboard
@@ -69,8 +74,9 @@
69 74 $this->add_action( 'mainwp_trust_theme', array( &$this, 'mainwp_trust_theme' ) );
70 75 $this->add_action( 'mainwp_updates_ignore_upgrades', array( &$this, 'ajax_ignore_core_updates' ) );
71 76 $this->add_action( 'mainwp_updates_unignore_upgrades', array( &$this, 'ajax_unignore_core_updates' ) );
72 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' ) );
73 79
74 80 // Page: Themes.
75 81 $this->add_action( 'mainwp_themes_search', array( &$this, 'mainwp_themes_search' ) );
76 82 $this->add_action( 'mainwp_themes_search_all', array( &$this, 'mainwp_themes_search_all' ) );
@@ -123,18 +129,19 @@
123 129 */
124 130 public function mainwp_themes_search() {
125 131 $this->secure_request( 'mainwp_themes_search' );
126 132 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
127 - $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
128 - $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
129 - $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : array();
130 - $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : array();
131 - $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : array();
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;
132 140
133 - $not_criteria = isset( $_POST['not_criteria'] ) && 'true' === $_POST['not_criteria'] ? true : false;
134 141 // phpcs:enable
135 142 MainWP_Cache::init_session();
136 - $result = MainWP_Themes::render_table( $keyword, $status, $groups, $sites, $not_criteria, $clients );
143 + $result = MainWP_Themes::render_table( $keyword, $status, $groups, $sites, $not_criteria, $clients, $not_fetchdata );
137 144 wp_send_json( $result );
138 145 }
139 146
140 147 /**
@@ -204,10 +211,17 @@
204 211 * @uses \MainWP\Dashboard\MainWP_Themes_Handler::save_trusted_theme_note()
205 212 */
206 213 public function mainwp_trusted_theme_notes_save() {
207 214 $this->secure_request( 'mainwp_trusted_theme_notes_save' );
208 - MainWP_Themes_Handler::save_trusted_theme_note();
209 - die( wp_json_encode( array( 'result' => 'SUCCESS' ) ) );
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 + );
210 224 }
211 225
212 226 /**
213 227 * Method mainwp_plugins_search()
@@ -219,17 +233,19 @@
219 233 */
220 234 public function mainwp_plugins_search() {
221 235 $this->secure_request( 'mainwp_plugins_search' );
222 236 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
223 - $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
224 - $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
225 - $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
226 - $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
227 - $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
228 - $not_criteria = isset( $_POST['not_criteria'] ) && 'true' === $_POST['not_criteria'] ? true : false;
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 +
229 245 // phpcs:enable
230 246 MainWP_Cache::init_session();
231 - $result = MainWP_Plugins::render_table( $keyword, $status, $groups, $sites, $not_criteria, $clients );
247 + $result = MainWP_Plugins::render_table( $keyword, $status, $groups, $sites, $not_criteria, $clients, $not_fetchdata );
232 248 wp_send_json( $result );
233 249 }
234 250
235 251 /**
@@ -313,10 +329,17 @@
313 329 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::save_trusted_plugin_note()
314 330 */
315 331 public function mainwp_trusted_plugin_notes_save() {
316 332 $this->secure_request( 'mainwp_trusted_plugin_notes_save' );
317 - MainWP_Plugins_Handler::save_trusted_plugin_note();
318 - die( wp_json_encode( array( 'result' => 'SUCCESS' ) ) );
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 + );
319 342 }
320 343
321 344 /**
322 345 * Method mainwp_widget_plugin_activate()
@@ -512,10 +535,11 @@
512 535 die(
513 536 wp_json_encode(
514 537 array(
515 538 'error' => array(
516 - 'message' => $e->getMessage(),
517 - 'extra' => $e->get_message_extra(),
539 + 'message' => $e->getMessage(),
540 + 'extra' => $e->get_message_extra(),
541 + 'errorCode' => $e->get_message_error_code(),
518 542 ),
519 543 )
520 544 )
521 545 );
@@ -521,9 +545,78 @@
521 545 );
522 546 }
523 547 }
524 548
549 +
525 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 + /**
526 619 * Method mainwp_upgrade_plugintheme()
527 620 *
528 621 * Update plugin or theme.
529 622 *
@@ -610,10 +703,11 @@
610 703 }
611 704 $website = MainWP_DB::instance()->get_website_by_id( $websiteId );
612 705 try {
613 706 $info = array(
614 - 'result' => array(),
615 - 'result_error' => array(),
707 + 'result' => array(),
708 + 'result_error' => array(),
709 + 'result_started' => array(),
616 710 );
617 711
618 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
619 713
@@ -623,10 +717,26 @@
623 717 }
624 718 if ( isset( $result['result_error'] ) ) {
625 719 $info['result_error'] = $result['result_error'];
626 720 }
721 + if ( isset( $result['result_started'] ) ) {
722 + $info['result_started'] = $result['result_started'];
723 + }
627 724 }
628 725
726 + // MWP-1660: append a generic licensing hint to failures of known premium
727 + // products; vendors only deliver update packages to licensed installs.
728 + $item_type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
729 + if ( ( 'plugin' === $item_type || 'theme' === $item_type ) && ! empty( $info['result_error'] ) && is_array( $info['result_error'] ) ) {
730 + $premium_ids = MainWP_Premium_Update_Registry::get_filter_defaults( $item_type, 'detect' );
731 + $premium_prefixes = MainWP_Premium_Update_Registry::get_prefixes( $item_type, 'detect' );
732 + foreach ( $info['result_error'] as $err_slug => $err_msg ) {
733 + if ( is_string( $err_msg ) && MainWP_Premium_Update_Registry::slug_matches( urldecode( $err_slug ), $premium_ids, $premium_prefixes ) ) {
734 + $info['result_error'][ $err_slug ] = $err_msg . ' ' . esc_html__( 'Premium updates usually require an active license on the child site; check that first.', 'mainwp' );
735 + }
736 + }
737 + }
738 +
629 739 if ( $chunk_support && ( ! empty( $chunk_slugs ) ) ) {
630 740 $info['chunk_slugs'] = implode( ',', $chunk_slugs );
631 741 }
632 742
@@ -632,8 +742,15 @@
632 742
633 743 if ( ! empty( $website ) ) {
634 744 $info['site_url'] = esc_url( $website->url );
635 745 }
746 +
747 + // Get max the scope of the largest change.
748 + $max_scope = apply_filters( 'mainwp_html_regression_largest_change_scope', $websiteId, false );
749 + if ( ! empty( $max_scope ) && $max_scope !== $websiteId ) {
750 + $info['result']['html_regression_max_scope'] = $max_scope;
751 + }
752 +
636 753 wp_send_json( $info );
637 754 } catch ( MainWP_Exception $e ) {
638 755 die(
639 756 wp_json_encode(