| @@ -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 |
| @@ -14,9 +19,9 @@ | ||
| 14 | 19 | * |
| 15 | 20 | * @uses \MainWP\Dashboard\MainWP_Post_Base_Handler |
| 16 | 21 | */ |
| 17 | 22 | class MainWP_Post_Plugin_Theme_Handler extends MainWP_Post_Base_Handler { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. |
| 18 | - | |
| 23 | + // phpcs:disable Generic.Metrics.CyclomaticComplexity -- complexity. | |
| 19 | 24 | /** |
| 20 | 25 | * Protected static variable to hold the single instance of the class. |
| 21 | 26 | * |
| 22 | 27 | * @var mixed Default null |
| @@ -59,9 +64,9 @@ | ||
| 59 | 64 | $this->add_action( 'mainwp_upgradeplugintheme', array( &$this, 'mainwp_upgrade_plugintheme' ) ); |
| 60 | 65 | $this->add_action( 'mainwp_ignoreplugintheme', array( &$this, 'mainwp_ignoreplugintheme' ) ); |
| 61 | 66 | $this->add_action( 'mainwp_unignoreplugintheme', array( &$this, 'mainwp_unignoreplugintheme' ) ); |
| 62 | 67 | $this->add_action( 'mainwp_ignorepluginsthemes', array( &$this, 'mainwp_ignorepluginsthemes' ) ); |
| 63 | - $this->add_action( 'mainwp_unignorepluginsthemes', array( &$this, 'mainwp_unignorepluginsthemes' ) ); | |
| 68 | + $this->add_action( 'mainwp_unignorepluginsthemes', array( &$this, 'mainwp_unignore_global_pluginsthemes' ) ); | |
| 64 | 69 | $this->add_action( 'mainwp_unignoreabandonedplugintheme', array( &$this, 'mainwp_unignoreabandonedplugintheme' ) ); |
| 65 | 70 | $this->add_action( 'mainwp_unignoreabandonedpluginsthemes', array( &$this, 'mainwp_unignoreabandonedpluginsthemes' ) ); |
| 66 | 71 | $this->add_action( 'mainwp_dismissoutdateplugintheme', array( &$this, 'mainwp_dismissoutdateplugintheme' ) ); |
| 67 | 72 | $this->add_action( 'mainwp_dismissoutdatepluginsthemes', array( &$this, 'mainwp_dismissoutdatepluginsthemes' ) ); |
| @@ -66,20 +71,24 @@ | ||
| 66 | 71 | $this->add_action( 'mainwp_dismissoutdateplugintheme', array( &$this, 'mainwp_dismissoutdateplugintheme' ) ); |
| 67 | 72 | $this->add_action( 'mainwp_dismissoutdatepluginsthemes', array( &$this, 'mainwp_dismissoutdatepluginsthemes' ) ); |
| 68 | 73 | $this->add_action( 'mainwp_trust_plugin', array( &$this, 'mainwp_trust_plugin' ) ); |
| 69 | 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' ) ); | |
| 70 | 79 | |
| 71 | 80 | // Page: Themes. |
| 72 | 81 | $this->add_action( 'mainwp_themes_search', array( &$this, 'mainwp_themes_search' ) ); |
| 73 | 82 | $this->add_action( 'mainwp_themes_search_all', array( &$this, 'mainwp_themes_search_all' ) ); |
| 74 | - if ( mainwp_current_user_have_right( 'dashboard', 'activate_themes' ) ) { | |
| 83 | + if ( \mainwp_current_user_can( 'dashboard', 'activate_themes' ) ) { | |
| 75 | 84 | $this->add_action( 'mainwp_theme_activate', array( &$this, 'mainwp_theme_activate' ) ); |
| 76 | 85 | } |
| 77 | - if ( mainwp_current_user_have_right( 'dashboard', 'delete_themes' ) ) { | |
| 86 | + if ( \mainwp_current_user_can( 'dashboard', 'delete_themes' ) ) { | |
| 78 | 87 | $this->add_action( 'mainwp_theme_delete', array( &$this, 'mainwp_theme_delete' ) ); |
| 79 | 88 | } |
| 80 | 89 | $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' ) ) { | |
| 90 | + if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) { | |
| 82 | 91 | $this->add_action( 'mainwp_theme_ignore_updates', array( &$this, 'mainwp_theme_ignore_updates' ) ); |
| 83 | 92 | } |
| 84 | 93 | |
| 85 | 94 | // Page: Plugins. |
| @@ -85,17 +94,17 @@ | ||
| 85 | 94 | // Page: Plugins. |
| 86 | 95 | $this->add_action( 'mainwp_plugins_search', array( &$this, 'mainwp_plugins_search' ) ); |
| 87 | 96 | $this->add_action( 'mainwp_plugins_search_all_active', array( &$this, 'mainwp_plugins_search_all_active' ) ); |
| 88 | 97 | |
| 89 | - if ( mainwp_current_user_have_right( 'dashboard', 'activate_deactivate_plugins' ) ) { | |
| 98 | + if ( \mainwp_current_user_can( 'dashboard', 'activate_deactivate_plugins' ) ) { | |
| 90 | 99 | $this->add_action( 'mainwp_plugin_activate', array( &$this, 'mainwp_plugin_activate' ) ); |
| 91 | 100 | $this->add_action( 'mainwp_plugin_deactivate', array( &$this, 'mainwp_plugin_deactivate' ) ); |
| 92 | 101 | } |
| 93 | - if ( mainwp_current_user_have_right( 'dashboard', 'delete_plugins' ) ) { | |
| 102 | + if ( \mainwp_current_user_can( 'dashboard', 'delete_plugins' ) ) { | |
| 94 | 103 | $this->add_action( 'mainwp_plugin_delete', array( &$this, 'mainwp_plugin_delete' ) ); |
| 95 | 104 | } |
| 96 | 105 | |
| 97 | - if ( mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) { | |
| 106 | + if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) { | |
| 98 | 107 | $this->add_action( 'mainwp_plugin_ignore_updates', array( &$this, 'mainwp_plugin_ignore_updates' ) ); |
| 99 | 108 | } |
| 100 | 109 | $this->add_action( 'mainwp_trusted_plugin_notes_save', array( &$this, 'mainwp_trusted_plugin_notes_save' ) ); |
| 101 | 110 | |
| @@ -120,18 +129,19 @@ | ||
| 120 | 129 | */ |
| 121 | 130 | public function mainwp_themes_search() { |
| 122 | 131 | $this->secure_request( 'mainwp_themes_search' ); |
| 123 | 132 | // 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(); | |
| 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; | |
| 129 | 140 | |
| 130 | - $not_criteria = isset( $_POST['not_criteria'] ) && 'true' === $_POST['not_criteria'] ? true : false; | |
| 131 | 141 | // phpcs:enable |
| 132 | 142 | MainWP_Cache::init_session(); |
| 133 | - $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 ); | |
| 134 | 144 | wp_send_json( $result ); |
| 135 | 145 | } |
| 136 | 146 | |
| 137 | 147 | /** |
| @@ -201,10 +211,17 @@ | ||
| 201 | 211 | * @uses \MainWP\Dashboard\MainWP_Themes_Handler::save_trusted_theme_note() |
| 202 | 212 | */ |
| 203 | 213 | public function mainwp_trusted_theme_notes_save() { |
| 204 | 214 | $this->secure_request( 'mainwp_trusted_theme_notes_save' ); |
| 205 | - MainWP_Themes_Handler::save_trusted_theme_note(); | |
| 206 | - 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 | + ); | |
| 207 | 224 | } |
| 208 | 225 | |
| 209 | 226 | /** |
| 210 | 227 | * Method mainwp_plugins_search() |
| @@ -216,17 +233,19 @@ | ||
| 216 | 233 | */ |
| 217 | 234 | public function mainwp_plugins_search() { |
| 218 | 235 | $this->secure_request( 'mainwp_plugins_search' ); |
| 219 | 236 | // 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; | |
| 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 | + | |
| 226 | 245 | // phpcs:enable |
| 227 | 246 | MainWP_Cache::init_session(); |
| 228 | - $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 ); | |
| 229 | 248 | wp_send_json( $result ); |
| 230 | 249 | } |
| 231 | 250 | |
| 232 | 251 | /** |
| @@ -289,9 +308,9 @@ | ||
| 289 | 308 | |
| 290 | 309 | /** |
| 291 | 310 | * Method mainwp_plugin_ignore_updates() |
| 292 | 311 | * |
| 293 | - * Ignore plugins updates, | |
| 312 | + * Ignore plugin updates, | |
| 294 | 313 | * Page: Plugins. |
| 295 | 314 | * |
| 296 | 315 | * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::ignore_updates() |
| 297 | 316 | */ |
| @@ -310,10 +329,17 @@ | ||
| 310 | 329 | * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::save_trusted_plugin_note() |
| 311 | 330 | */ |
| 312 | 331 | public function mainwp_trusted_plugin_notes_save() { |
| 313 | 332 | $this->secure_request( 'mainwp_trusted_plugin_notes_save' ); |
| 314 | - MainWP_Plugins_Handler::save_trusted_plugin_note(); | |
| 315 | - 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 | + ); | |
| 316 | 342 | } |
| 317 | 343 | |
| 318 | 344 | /** |
| 319 | 345 | * Method mainwp_widget_plugin_activate() |
| @@ -495,10 +521,10 @@ | ||
| 495 | 521 | * @uses \MainWP\Dashboard\MainWP_Exception |
| 496 | 522 | * @uses \MainWP\Dashboard\MainWP_Updates_Handler::upgrade_site() |
| 497 | 523 | */ |
| 498 | 524 | 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 ) ) ) ); | |
| 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 ) ) ) ); | |
| 501 | 527 | } |
| 502 | 528 | |
| 503 | 529 | $this->secure_request( 'mainwp_upgradewp' ); |
| 504 | 530 | |
| @@ -509,10 +535,11 @@ | ||
| 509 | 535 | die( |
| 510 | 536 | wp_json_encode( |
| 511 | 537 | array( |
| 512 | 538 | 'error' => array( |
| 513 | - 'message' => $e->getMessage(), | |
| 514 | - 'extra' => $e->get_message_extra(), | |
| 539 | + 'message' => $e->getMessage(), | |
| 540 | + 'extra' => $e->get_message_extra(), | |
| 541 | + 'errorCode' => $e->get_message_error_code(), | |
| 515 | 542 | ), |
| 516 | 543 | ) |
| 517 | 544 | ) |
| 518 | 545 | ); |
| @@ -518,9 +545,78 @@ | ||
| 518 | 545 | ); |
| 519 | 546 | } |
| 520 | 547 | } |
| 521 | 548 | |
| 549 | + | |
| 522 | 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 | + /** | |
| 523 | 619 | * Method mainwp_upgrade_plugintheme() |
| 524 | 620 | * |
| 525 | 621 | * Update plugin or theme. |
| 526 | 622 | * |
| @@ -536,18 +632,18 @@ | ||
| 536 | 632 | if ( ! isset( $_POST['type'] ) ) { |
| 537 | 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' ) ) ) ); |
| 538 | 634 | } |
| 539 | 635 | |
| 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 ) ) ) ); | |
| 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 ) ) ) ); | |
| 542 | 638 | } |
| 543 | 639 | |
| 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 ) ) ) ); | |
| 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 ) ) ) ); | |
| 546 | 642 | } |
| 547 | 643 | |
| 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 ) ) ) ); | |
| 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 ) ) ) ); | |
| 550 | 646 | } |
| 551 | 647 | |
| 552 | 648 | $this->secure_request( 'mainwp_upgradeplugintheme' ); |
| 553 | 649 | |
| @@ -607,10 +703,11 @@ | ||
| 607 | 703 | } |
| 608 | 704 | $website = MainWP_DB::instance()->get_website_by_id( $websiteId ); |
| 609 | 705 | try { |
| 610 | 706 | $info = array( |
| 611 | - 'result' => array(), | |
| 612 | - 'result_error' => array(), | |
| 707 | + 'result' => array(), | |
| 708 | + 'result_error' => array(), | |
| 709 | + 'result_started' => array(), | |
| 613 | 710 | ); |
| 614 | 711 | |
| 615 | 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 |
| 616 | 713 | |
| @@ -620,10 +717,27 @@ | ||
| 620 | 717 | } |
| 621 | 718 | if ( isset( $result['result_error'] ) ) { |
| 622 | 719 | $info['result_error'] = $result['result_error']; |
| 623 | 720 | } |
| 721 | + // for backward compatibility. | |
| 722 | + if ( isset( $result['result_started'] ) ) { | |
| 723 | + $info['result_started'] = $result['result_started']; | |
| 724 | + } | |
| 624 | 725 | } |
| 625 | 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 | + | |
| 626 | 740 | if ( $chunk_support && ( ! empty( $chunk_slugs ) ) ) { |
| 627 | 741 | $info['chunk_slugs'] = implode( ',', $chunk_slugs ); |
| 628 | 742 | } |
| 629 | 743 | |
| @@ -629,8 +743,15 @@ | ||
| 629 | 743 | |
| 630 | 744 | if ( ! empty( $website ) ) { |
| 631 | 745 | $info['site_url'] = esc_url( $website->url ); |
| 632 | 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 | + | |
| 633 | 754 | wp_send_json( $info ); |
| 634 | 755 | } catch ( MainWP_Exception $e ) { |
| 635 | 756 | die( |
| 636 | 757 | wp_json_encode( |
| @@ -661,13 +782,34 @@ | ||
| 661 | 782 | $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; |
| 662 | 783 | $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : ''; |
| 663 | 784 | $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; |
| 664 | 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'] ) ) : ''; | |
| 665 | 787 | // phpcs:enable |
| 666 | - wp_send_json( array( 'result' => MainWP_Updates_Handler::ignore_plugin_theme( $type, $slug, $name, $id ) ) ); | |
| 788 | + wp_send_json( array( 'result' => MainWP_Updates_Handler::ignore_plugin_theme( $type, $slug, $name, $id, $ver ) ) ); | |
| 667 | 789 | } |
| 668 | 790 | |
| 791 | + | |
| 669 | 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 | + /** | |
| 670 | 812 | * Method mainwp_unignoreabandonedplugintheme() |
| 671 | 813 | * |
| 672 | 814 | * Unignore abandoned plugin or theme. |
| 673 | 815 | * |
| @@ -741,10 +883,10 @@ | ||
| 741 | 883 | */ |
| 742 | 884 | public function mainwp_dismissoutdatepluginsthemes() { |
| 743 | 885 | $this->secure_request( 'mainwp_dismissoutdatepluginsthemes' ); |
| 744 | 886 | |
| 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' ) ) ) ) ); | |
| 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' ) ) ) ) ); | |
| 747 | 889 | } |
| 748 | 890 | |
| 749 | 891 | // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 750 | 892 | if ( ! isset( $_POST['slug'] ) ) { |
| @@ -775,14 +917,16 @@ | ||
| 775 | 917 | } |
| 776 | 918 | $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; |
| 777 | 919 | $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : ''; |
| 778 | 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 | + | |
| 779 | 923 | // phpcs:enable |
| 780 | - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_plugin_theme( $type, $slug, $id ) ) ) ); | |
| 924 | + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_plugin_theme( $type, $slug, $id, $ver ) ) ) ); | |
| 781 | 925 | } |
| 782 | 926 | |
| 783 | 927 | /** |
| 784 | - * Method mainwp_ignorepluginthemes() | |
| 928 | + * Method mainwp_ignorepluginsthemes() | |
| 785 | 929 | * |
| 786 | 930 | * Ignore plugins or themes. |
| 787 | 931 | * |
| 788 | 932 | * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugins_themes() |
| @@ -789,10 +933,10 @@ | ||
| 789 | 933 | */ |
| 790 | 934 | public function mainwp_ignorepluginsthemes() { |
| 791 | 935 | $this->secure_request( 'mainwp_ignorepluginsthemes' ); |
| 792 | 936 | |
| 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' ) ) ) ) ); | |
| 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' ) ) ) ) ); | |
| 795 | 939 | } |
| 796 | 940 | |
| 797 | 941 | // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 798 | 942 | if ( ! isset( $_POST['slug'] ) ) { |
| @@ -801,29 +945,140 @@ | ||
| 801 | 945 | |
| 802 | 946 | $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; |
| 803 | 947 | $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : ''; |
| 804 | 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 | + | |
| 805 | 951 | // phpcs:enable |
| 806 | - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::ignore_plugins_themes( $type, $slug, $name ) ) ) ); | |
| 952 | + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::ignore_plugins_themes( $type, $slug, $name, $ver ) ) ) ); | |
| 807 | 953 | } |
| 808 | 954 | |
| 809 | 955 | /** |
| 810 | - * Method mainwp_unignorepluginthemes() | |
| 956 | + * Method ajax_ignore_core_updates() | |
| 811 | 957 | * |
| 812 | - * Unignore plugins or themes. | |
| 958 | + * Ignore plugins or themes. | |
| 959 | + * | |
| 960 | + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugins_themes() | |
| 813 | 961 | */ |
| 814 | - public function mainwp_unignorepluginsthemes() { | |
| 815 | - $this->secure_request( 'mainwp_unignorepluginsthemes' ); | |
| 962 | + public function ajax_ignore_core_updates() { //phpcs:ignore -- NOSONAR complex function. | |
| 816 | 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 | + | |
| 817 | 970 | // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 818 | - if ( ! isset( $_POST['slug'] ) ) { | |
| 971 | + if ( empty( $_POST['slug'] ) ) { | |
| 819 | 972 | die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) ); |
| 820 | 973 | } |
| 821 | - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 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 | |
| 822 | 1075 | $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : ''; |
| 1076 | + $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : ''; | |
| 823 | 1077 | // phpcs:enable |
| 824 | - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_plugins_themes( $type, $slug ) ) ) ); | |
| 1078 | + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_global_cores( $slug, $ver ) ) ) ); | |
| 825 | 1079 | } |
| 1080 | + | |
| 826 | 1081 | |
| 827 | 1082 | /** |
| 828 | 1083 | * Method mainwp_trust_plugin() |
| 829 | 1084 | * |