← All changes
|
class/class-mainwp-post-plugin-theme-handler.php
+1006
-754
5.0.2
→
6.2.2
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 |
| @@ -13,844 +18,1091 @@ | ||
| 13 | 18 | * @package MainWP\Dashboard |
| 14 | 19 | * |
| 15 | 20 | * @uses \MainWP\Dashboard\MainWP_Post_Base_Handler |
| 16 | 21 | */ |
| 17 | -class MainWP_Post_Plugin_Theme_Handler extends MainWP_Post_Base_Handler { | |
| 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; | |
| 18 | 30 | |
| 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; | |
| 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 | + } | |
| 25 | 45 | |
| 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 === self::$instance ) { | |
| 36 | - self::$instance = new self(); | |
| 37 | - } | |
| 38 | - return self::$instance; | |
| 39 | - } | |
| 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' ) ); | |
| 40 | 53 | |
| 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' ) ); | |
| 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' ) ); | |
| 48 | 61 | |
| 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' ) ); | |
| 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' ) ); | |
| 56 | 79 | |
| 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' ) ); | |
| 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 | + } | |
| 70 | 93 | |
| 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 | - } | |
| 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' ) ); | |
| 84 | 97 | |
| 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' ) ); | |
| 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 | + } | |
| 88 | 105 | |
| 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 | - } | |
| 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' ) ); | |
| 96 | 110 | |
| 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' ) ); | |
| 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' ) ); | |
| 101 | 115 | |
| 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' ) ); | |
| 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 | + } | |
| 106 | 120 | |
| 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 | - } | |
| 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; | |
| 111 | 140 | |
| 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(); | |
| 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 | + } | |
| 129 | 146 | |
| 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 | - } | |
| 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 | + } | |
| 136 | 160 | |
| 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 | - } | |
| 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 | + } | |
| 150 | 174 | |
| 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 | - } | |
| 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 | + } | |
| 164 | 188 | |
| 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 | - } | |
| 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 | + } | |
| 178 | 204 | |
| 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 | - } | |
| 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 | + } | |
| 194 | 225 | |
| 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 | - } | |
| 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; | |
| 208 | 244 | |
| 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 | - } | |
| 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 | + } | |
| 231 | 250 | |
| 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 | - } | |
| 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 | + } | |
| 247 | 266 | |
| 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 | - } | |
| 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 | + } | |
| 261 | 280 | |
| 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 | - } | |
| 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 | + } | |
| 275 | 294 | |
| 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 | - } | |
| 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 | + } | |
| 289 | 308 | |
| 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 | - } | |
| 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 | + } | |
| 303 | 322 | |
| 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 | - } | |
| 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 | + } | |
| 317 | 343 | |
| 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 | - } | |
| 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 | + } | |
| 330 | 356 | |
| 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 | - } | |
| 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 | + } | |
| 343 | 369 | |
| 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 | - } | |
| 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 | + } | |
| 356 | 382 | |
| 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 | - } | |
| 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 | + } | |
| 369 | 395 | |
| 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 | - } | |
| 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 | + } | |
| 382 | 408 | |
| 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 | - } | |
| 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 | + } | |
| 395 | 421 | |
| 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 | - } | |
| 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 | + } | |
| 408 | 434 | |
| 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 | - } | |
| 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 | + } | |
| 421 | 447 | |
| 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 | - } | |
| 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 | + } | |
| 434 | 460 | |
| 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 | - } | |
| 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 | + } | |
| 447 | 473 | |
| 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 | - } | |
| 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 | + } | |
| 457 | 483 | |
| 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 | - } | |
| 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 | + } | |
| 468 | 494 | |
| 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'; | |
| 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 | - } | |
| 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 | + } | |
| 489 | 515 | |
| 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' ), $echo = false ) ) ) ); | |
| 501 | - } | |
| 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 | + } | |
| 502 | 528 | |
| 503 | - $this->secure_request( 'mainwp_upgradewp' ); | |
| 529 | + $this->secure_request( 'mainwp_upgradewp' ); | |
| 504 | 530 | |
| 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 | - } | |
| 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 | + } | |
| 521 | 548 | |
| 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 -- Current complexity is the only way to achieve desired results, pull request solutions appreciated. | |
| 534 | 549 | |
| 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 | - } | |
| 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' ); | |
| 539 | 557 | |
| 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' ), $echo = false ) ) ) ); | |
| 542 | - } | |
| 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. | |
| 543 | 566 | |
| 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' ), $echo = false ) ) ) ); | |
| 546 | - } | |
| 567 | + if ( 'translation' === $update_type ) { | |
| 568 | + $update_type = 'trans'; // compatible. | |
| 569 | + } elseif ( 'wp' === $update_type ) { | |
| 570 | + $update_type = 'core'; // compatible. | |
| 571 | + } | |
| 547 | 572 | |
| 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' ), $echo = false ) ) ) ); | |
| 550 | - } | |
| 573 | + $data = MainWP_Updates_Overview::prepare_update_data( $update_type, $current_siteid ); | |
| 551 | 574 | |
| 552 | - $this->secure_request( 'mainwp_upgradeplugintheme' ); | |
| 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 | + ); | |
| 553 | 588 | |
| 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 = ''; | |
| 589 | + extract( $data ); // phpcs:ignore -- NOSONAR - well structure. | |
| 559 | 590 | |
| 560 | - if ( isset( $_POST['websiteId'] ) ) { | |
| 561 | - $websiteId = intval( $_POST['websiteId'] ); | |
| 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' ); | |
| 562 | 595 | |
| 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 | |
| 596 | + $mainwp_show_language_updates = get_option( 'mainwp_show_language_updates', 1 ); | |
| 591 | 597 | |
| 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 | - } | |
| 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 | + ); | |
| 595 | 614 | |
| 596 | - $chunk_slugs = array(); | |
| 615 | + die(); | |
| 616 | + } | |
| 597 | 617 | |
| 598 | - if ( $chunk_support ) { | |
| 599 | - // calculate update slugs here. | |
| 600 | - if ( $max_update ) { | |
| 601 | - $slugs = explode( ',', $slugs ); | |
| 602 | - $chunk_slugs = array_slice( $slugs, $max_update ); | |
| 603 | - $update_slugs = array_diff( $slugs, $chunk_slugs ); | |
| 604 | - $slugs = implode( ',', $update_slugs ); | |
| 605 | - } | |
| 606 | - } | |
| 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. | |
| 607 | 630 | |
| 608 | - if ( empty( $slugs ) && ! $chunk_support ) { | |
| 609 | - die( wp_json_encode( array( 'message' => esc_html__( 'Item slug could not be found. Update process could not be executed.', 'mainwp' ) ) ) ); | |
| 610 | - } | |
| 611 | - $website = MainWP_DB::instance()->get_website_by_id( $websiteId ); | |
| 612 | - try { | |
| 613 | - $info = array( | |
| 614 | - 'result' => array(), | |
| 615 | - 'result_error' => array(), | |
| 616 | - ); | |
| 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 | + } | |
| 617 | 635 | |
| 618 | - $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 | |
| 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 | + } | |
| 619 | 639 | |
| 620 | - if ( is_array( $result ) ) { | |
| 621 | - if ( isset( $result['result'] ) ) { | |
| 622 | - $info['result'] = $result['result']; | |
| 623 | - } | |
| 624 | - if ( isset( $result['result_error'] ) ) { | |
| 625 | - $info['result_error'] = $result['result_error']; | |
| 626 | - } | |
| 627 | - } | |
| 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 | + } | |
| 628 | 643 | |
| 629 | - if ( $chunk_support && ( 0 < count( $chunk_slugs ) ) ) { | |
| 630 | - $info['chunk_slugs'] = implode( ',', $chunk_slugs ); | |
| 631 | - } | |
| 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 | + } | |
| 632 | 647 | |
| 633 | - if ( ! empty( $website ) ) { | |
| 634 | - $info['site_url'] = esc_url( $website->url ); | |
| 635 | - } | |
| 636 | - wp_send_json( $info ); | |
| 637 | - } catch ( MainWP_Exception $e ) { | |
| 638 | - die( | |
| 639 | - wp_json_encode( | |
| 640 | - array( | |
| 641 | - 'error' => array( | |
| 642 | - 'message' => $e->getMessage(), | |
| 643 | - 'extra' => $e->get_message_extra(), | |
| 644 | - 'errorCode' => $e->get_message_error_code(), | |
| 645 | - ), | |
| 646 | - ) | |
| 647 | - ) | |
| 648 | - ); | |
| 649 | - } | |
| 650 | - } | |
| 648 | + $this->secure_request( 'mainwp_upgradeplugintheme' ); | |
| 651 | 649 | |
| 652 | - /** | |
| 653 | - * Method mainwp_ignoreplugintheme() | |
| 654 | - * | |
| 655 | - * Ignores a plugin or a theme. | |
| 656 | - */ | |
| 657 | - public function mainwp_ignoreplugintheme() { | |
| 658 | - $this->secure_request( 'mainwp_ignoreplugintheme' ); | |
| 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 = ''; | |
| 659 | 655 | |
| 660 | - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 661 | - if ( ! isset( $_POST['id'] ) ) { | |
| 662 | - die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 663 | - } | |
| 664 | - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 665 | - $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 666 | - $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; | |
| 667 | - $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; | |
| 668 | - // phpcs:enable | |
| 669 | - wp_send_json( array( 'result' => MainWP_Updates_Handler::ignore_plugin_theme( $type, $slug, $name, $id ) ) ); | |
| 670 | - } | |
| 656 | + if ( isset( $_POST['websiteId'] ) ) { | |
| 657 | + $websiteId = intval( $_POST['websiteId'] ); | |
| 671 | 658 | |
| 672 | - /** | |
| 673 | - * Method mainwp_unignoreabandonedplugintheme() | |
| 674 | - * | |
| 675 | - * Unignore abandoned plugin or theme. | |
| 676 | - * | |
| 677 | - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugin_theme() | |
| 678 | - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_abandoned_plugin_theme() | |
| 679 | - */ | |
| 680 | - public function mainwp_unignoreabandonedplugintheme() { | |
| 681 | - $this->secure_request( 'mainwp_unignoreabandonedplugintheme' ); | |
| 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 | |
| 682 | 687 | |
| 683 | - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 684 | - if ( ! isset( $_POST['id'] ) ) { | |
| 685 | - die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 686 | - } | |
| 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 | + } | |
| 687 | 691 | |
| 688 | - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 689 | - $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 690 | - $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : 0; // string|int. | |
| 691 | - // phpcs:enable | |
| 692 | - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_abandoned_plugin_theme( $type, $slug, $id ) ) ) ); // ok. | |
| 693 | - } | |
| 692 | + $chunk_slugs = array(); | |
| 694 | 693 | |
| 695 | - /** | |
| 696 | - * Method mainwp_unignoreabandonedpluginthemes() | |
| 697 | - * | |
| 698 | - * Unignore abandoned plugins or themes. | |
| 699 | - * | |
| 700 | - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_abandoned_plugins_themes() | |
| 701 | - */ | |
| 702 | - public function mainwp_unignoreabandonedpluginsthemes() { | |
| 703 | - $this->secure_request( 'mainwp_unignoreabandonedpluginsthemes' ); | |
| 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 | + } | |
| 704 | 700 | |
| 705 | - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 706 | - if ( ! isset( $_POST['slug'] ) ) { | |
| 707 | - die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 708 | - } | |
| 701 | + if ( empty( $slugs ) && ! $chunk_support ) { | |
| 702 | + die( wp_json_encode( array( 'message' => esc_html__( 'Item slug could not be found. Update process could not be executed.', 'mainwp' ) ) ) ); | |
| 703 | + } | |
| 704 | + $website = MainWP_DB::instance()->get_website_by_id( $websiteId ); | |
| 705 | + try { | |
| 706 | + $info = array( | |
| 707 | + 'result' => array(), | |
| 708 | + 'result_error' => array(), | |
| 709 | + 'result_started' => array(), | |
| 710 | + ); | |
| 709 | 711 | |
| 710 | - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 711 | - $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 712 | - // phpcs:enable | |
| 713 | - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_abandoned_plugins_themes( $type, $slug ) ) ) ); | |
| 714 | - } | |
| 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 | |
| 715 | 713 | |
| 716 | - /** | |
| 717 | - * Method mainwp_dismissoutdateplugintheme() | |
| 718 | - * | |
| 719 | - * Dismiss outdated plugin or theme. | |
| 720 | - * | |
| 721 | - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::dismiss_plugin_theme() | |
| 722 | - */ | |
| 723 | - public function mainwp_dismissoutdateplugintheme() { | |
| 724 | - $this->secure_request( 'mainwp_dismissoutdateplugintheme' ); | |
| 714 | + if ( is_array( $result ) ) { | |
| 715 | + if ( isset( $result['result'] ) ) { | |
| 716 | + $info['result'] = $result['result']; | |
| 717 | + } | |
| 718 | + if ( isset( $result['result_error'] ) ) { | |
| 719 | + $info['result_error'] = $result['result_error']; | |
| 720 | + } | |
| 721 | + // for backward compatibility. | |
| 722 | + if ( isset( $result['result_started'] ) ) { | |
| 723 | + $info['result_started'] = $result['result_started']; | |
| 724 | + } | |
| 725 | + } | |
| 725 | 726 | |
| 726 | - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 727 | - if ( ! isset( $_POST['id'] ) ) { | |
| 728 | - die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 729 | - } | |
| 730 | - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 731 | - $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 732 | - $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; | |
| 733 | - $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; | |
| 734 | - // phpcs:enable | |
| 735 | - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::dismiss_plugin_theme( $type, $slug, $name, $id ) ) ) ); | |
| 736 | - } | |
| 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 | + } | |
| 737 | 739 | |
| 738 | - /** | |
| 739 | - * Method mainwp_dismissoutdatepluginthemes() | |
| 740 | - * | |
| 741 | - * Dismiss outdated plugins or themes. | |
| 742 | - * | |
| 743 | - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::dismiss_plugins_themes() | |
| 744 | - */ | |
| 745 | - public function mainwp_dismissoutdatepluginsthemes() { | |
| 746 | - $this->secure_request( 'mainwp_dismissoutdatepluginsthemes' ); | |
| 740 | + if ( $chunk_support && ( ! empty( $chunk_slugs ) ) ) { | |
| 741 | + $info['chunk_slugs'] = implode( ',', $chunk_slugs ); | |
| 742 | + } | |
| 747 | 743 | |
| 748 | - if ( ! mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) { | |
| 749 | - die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( esc_html__( 'ignore/unignore updates', 'mainwp' ) ) ) ) ); | |
| 750 | - } | |
| 744 | + if ( ! empty( $website ) ) { | |
| 745 | + $info['site_url'] = esc_url( $website->url ); | |
| 746 | + } | |
| 751 | 747 | |
| 752 | - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 753 | - if ( ! isset( $_POST['slug'] ) ) { | |
| 754 | - die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 755 | - } | |
| 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 | + } | |
| 756 | 753 | |
| 757 | - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 758 | - $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 759 | - $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; | |
| 760 | - // phpcs:enable | |
| 754 | + wp_send_json( $info ); | |
| 755 | + } catch ( MainWP_Exception $e ) { | |
| 756 | + die( | |
| 757 | + wp_json_encode( | |
| 758 | + array( | |
| 759 | + 'error' => array( | |
| 760 | + 'message' => $e->getMessage(), | |
| 761 | + 'extra' => $e->get_message_extra(), | |
| 762 | + 'errorCode' => $e->get_message_error_code(), | |
| 763 | + ), | |
| 764 | + ) | |
| 765 | + ) | |
| 766 | + ); | |
| 767 | + } | |
| 768 | + } | |
| 761 | 769 | |
| 762 | - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::dismiss_plugins_themes( $type, $slug, $name ) ) ) ); | |
| 763 | - } | |
| 770 | + /** | |
| 771 | + * Method mainwp_ignoreplugintheme() | |
| 772 | + * | |
| 773 | + * Ignores a plugin or a theme. | |
| 774 | + */ | |
| 775 | + public function mainwp_ignoreplugintheme() { | |
| 776 | + $this->secure_request( 'mainwp_ignoreplugintheme' ); | |
| 764 | 777 | |
| 765 | - /** | |
| 766 | - * Method mainwp_unignoreplugintheme() | |
| 767 | - * | |
| 768 | - * Unignore plugin or theme. | |
| 769 | - * | |
| 770 | - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_plugin_theme() | |
| 771 | - */ | |
| 772 | - public function mainwp_unignoreplugintheme() { | |
| 773 | - $this->secure_request( 'mainwp_unignoreplugintheme' ); | |
| 778 | + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 779 | + if ( ! isset( $_POST['id'] ) ) { | |
| 780 | + die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 781 | + } | |
| 782 | + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 783 | + $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 784 | + $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; | |
| 785 | + $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; | |
| 786 | + $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : ''; | |
| 787 | + // phpcs:enable | |
| 788 | + wp_send_json( array( 'result' => MainWP_Updates_Handler::ignore_plugin_theme( $type, $slug, $name, $id, $ver ) ) ); | |
| 789 | + } | |
| 774 | 790 | |
| 775 | - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 776 | - if ( ! isset( $_POST['id'] ) ) { | |
| 777 | - die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 778 | - } | |
| 779 | - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 780 | - $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : ''; | |
| 781 | - $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : ''; | |
| 782 | - // phpcs:enable | |
| 783 | - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_plugin_theme( $type, $slug, $id ) ) ) ); | |
| 784 | - } | |
| 785 | 791 | |
| 786 | - /** | |
| 787 | - * Method mainwp_ignorepluginthemes() | |
| 788 | - * | |
| 789 | - * Ignore plugins or themes. | |
| 790 | - * | |
| 791 | - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugins_themes() | |
| 792 | - */ | |
| 793 | - public function mainwp_ignorepluginsthemes() { | |
| 794 | - $this->secure_request( 'mainwp_ignorepluginsthemes' ); | |
| 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' ); | |
| 795 | 799 | |
| 796 | - if ( ! mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) { | |
| 797 | - die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( esc_html__( 'ignore/unignore updates', 'mainwp' ) ) ) ) ); | |
| 798 | - } | |
| 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 | + } | |
| 799 | 810 | |
| 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 | - } | |
| 811 | + /** | |
| 812 | + * Method mainwp_unignoreabandonedplugintheme() | |
| 813 | + * | |
| 814 | + * Unignore abandoned plugin or theme. | |
| 815 | + * | |
| 816 | + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugin_theme() | |
| 817 | + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_abandoned_plugin_theme() | |
| 818 | + */ | |
| 819 | + public function mainwp_unignoreabandonedplugintheme() { | |
| 820 | + $this->secure_request( 'mainwp_unignoreabandonedplugintheme' ); | |
| 804 | 821 | |
| 805 | - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 806 | - $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 807 | - $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; | |
| 808 | - // phpcs:enable | |
| 809 | - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::ignore_plugins_themes( $type, $slug, $name ) ) ) ); | |
| 810 | - } | |
| 822 | + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 823 | + if ( ! isset( $_POST['id'] ) ) { | |
| 824 | + die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 825 | + } | |
| 811 | 826 | |
| 812 | - /** | |
| 813 | - * Method mainwp_unignorepluginthemes() | |
| 814 | - * | |
| 815 | - * Unignore plugins or themes. | |
| 816 | - */ | |
| 817 | - public function mainwp_unignorepluginsthemes() { | |
| 818 | - $this->secure_request( 'mainwp_unignorepluginsthemes' ); | |
| 827 | + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 828 | + $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 829 | + $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : 0; // string|int. | |
| 830 | + // phpcs:enable | |
| 831 | + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_abandoned_plugin_theme( $type, $slug, $id ) ) ) ); // ok. | |
| 832 | + } | |
| 819 | 833 | |
| 820 | - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 821 | - if ( ! isset( $_POST['slug'] ) ) { | |
| 822 | - die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 823 | - } | |
| 824 | - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 825 | - $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : ''; | |
| 826 | - // phpcs:enable | |
| 827 | - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_plugins_themes( $type, $slug ) ) ) ); | |
| 828 | - } | |
| 834 | + /** | |
| 835 | + * Method mainwp_unignoreabandonedpluginthemes() | |
| 836 | + * | |
| 837 | + * Unignore abandoned plugins or themes. | |
| 838 | + * | |
| 839 | + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_abandoned_plugins_themes() | |
| 840 | + */ | |
| 841 | + public function mainwp_unignoreabandonedpluginsthemes() { | |
| 842 | + $this->secure_request( 'mainwp_unignoreabandonedpluginsthemes' ); | |
| 829 | 843 | |
| 830 | - /** | |
| 831 | - * Method mainwp_trust_plugin() | |
| 832 | - * | |
| 833 | - * Trust plugin. | |
| 834 | - * | |
| 835 | - * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_post() | |
| 836 | - * @uses \MainWP\Dashboard\MainWP_Themes_Handler::trust_post() | |
| 837 | - */ | |
| 838 | - public function mainwp_trust_plugin() { | |
| 839 | - $this->secure_request( 'mainwp_trust_plugin' ); | |
| 844 | + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 845 | + if ( ! isset( $_POST['slug'] ) ) { | |
| 846 | + die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 847 | + } | |
| 840 | 848 | |
| 841 | - MainWP_Plugins_Handler::trust_post(); | |
| 842 | - die( wp_json_encode( array( 'result' => true ) ) ); | |
| 843 | - } | |
| 849 | + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 850 | + $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 851 | + // phpcs:enable | |
| 852 | + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_abandoned_plugins_themes( $type, $slug ) ) ) ); | |
| 853 | + } | |
| 844 | 854 | |
| 845 | - /** | |
| 846 | - * Method mainwp_trust_theme() | |
| 847 | - * | |
| 848 | - * Trust theme. | |
| 849 | - */ | |
| 850 | - public function mainwp_trust_theme() { | |
| 851 | - $this->secure_request( 'mainwp_trust_theme' ); | |
| 855 | + /** | |
| 856 | + * Method mainwp_dismissoutdateplugintheme() | |
| 857 | + * | |
| 858 | + * Dismiss outdated plugin or theme. | |
| 859 | + * | |
| 860 | + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::dismiss_plugin_theme() | |
| 861 | + */ | |
| 862 | + public function mainwp_dismissoutdateplugintheme() { | |
| 863 | + $this->secure_request( 'mainwp_dismissoutdateplugintheme' ); | |
| 852 | 864 | |
| 853 | - MainWP_Themes_Handler::trust_post(); | |
| 854 | - die( wp_json_encode( array( 'result' => true ) ) ); | |
| 855 | - } | |
| 865 | + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 866 | + if ( ! isset( $_POST['id'] ) ) { | |
| 867 | + die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 868 | + } | |
| 869 | + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 870 | + $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 871 | + $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; | |
| 872 | + $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; | |
| 873 | + // phpcs:enable | |
| 874 | + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::dismiss_plugin_theme( $type, $slug, $name, $id ) ) ) ); | |
| 875 | + } | |
| 876 | + | |
| 877 | + /** | |
| 878 | + * Method mainwp_dismissoutdatepluginthemes() | |
| 879 | + * | |
| 880 | + * Dismiss outdated plugins or themes. | |
| 881 | + * | |
| 882 | + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::dismiss_plugins_themes() | |
| 883 | + */ | |
| 884 | + public function mainwp_dismissoutdatepluginsthemes() { | |
| 885 | + $this->secure_request( 'mainwp_dismissoutdatepluginsthemes' ); | |
| 886 | + | |
| 887 | + if ( ! \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) { | |
| 888 | + die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'ignore/unignore updates', 'mainwp' ) ) ) ) ); | |
| 889 | + } | |
| 890 | + | |
| 891 | + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 892 | + if ( ! isset( $_POST['slug'] ) ) { | |
| 893 | + die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 894 | + } | |
| 895 | + | |
| 896 | + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 897 | + $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 898 | + $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; | |
| 899 | + // phpcs:enable | |
| 900 | + | |
| 901 | + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::dismiss_plugins_themes( $type, $slug, $name ) ) ) ); | |
| 902 | + } | |
| 903 | + | |
| 904 | + /** | |
| 905 | + * Method mainwp_unignoreplugintheme() | |
| 906 | + * | |
| 907 | + * Unignore plugin or theme. | |
| 908 | + * | |
| 909 | + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_plugin_theme() | |
| 910 | + */ | |
| 911 | + public function mainwp_unignoreplugintheme() { | |
| 912 | + $this->secure_request( 'mainwp_unignoreplugintheme' ); | |
| 913 | + | |
| 914 | + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 915 | + if ( ! isset( $_POST['id'] ) ) { | |
| 916 | + die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 917 | + } | |
| 918 | + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 919 | + $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : ''; | |
| 920 | + $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : ''; | |
| 921 | + $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : ''; | |
| 922 | + | |
| 923 | + // phpcs:enable | |
| 924 | + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_plugin_theme( $type, $slug, $id, $ver ) ) ) ); | |
| 925 | + } | |
| 926 | + | |
| 927 | + /** | |
| 928 | + * Method mainwp_ignorepluginsthemes() | |
| 929 | + * | |
| 930 | + * Ignore plugins or themes. | |
| 931 | + * | |
| 932 | + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugins_themes() | |
| 933 | + */ | |
| 934 | + public function mainwp_ignorepluginsthemes() { | |
| 935 | + $this->secure_request( 'mainwp_ignorepluginsthemes' ); | |
| 936 | + | |
| 937 | + if ( ! \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) { | |
| 938 | + die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'ignore/unignore updates', 'mainwp' ) ) ) ) ); | |
| 939 | + } | |
| 940 | + | |
| 941 | + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 942 | + if ( ! isset( $_POST['slug'] ) ) { | |
| 943 | + die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 944 | + } | |
| 945 | + | |
| 946 | + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 947 | + $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 948 | + $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; | |
| 949 | + $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : ''; | |
| 950 | + | |
| 951 | + // phpcs:enable | |
| 952 | + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::ignore_plugins_themes( $type, $slug, $name, $ver ) ) ) ); | |
| 953 | + } | |
| 954 | + | |
| 955 | + /** | |
| 956 | + * Method ajax_ignore_core_updates() | |
| 957 | + * | |
| 958 | + * Ignore plugins or themes. | |
| 959 | + * | |
| 960 | + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugins_themes() | |
| 961 | + */ | |
| 962 | + public function ajax_ignore_core_updates() { //phpcs:ignore -- NOSONAR complex function. | |
| 963 | + | |
| 964 | + $this->secure_request( 'mainwp_updates_ignore_upgrades' ); | |
| 965 | + | |
| 966 | + if ( ! \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) { | |
| 967 | + die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'ignore/unignore updates', 'mainwp' ) ) ) ) ); | |
| 968 | + } | |
| 969 | + | |
| 970 | + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 971 | + if ( empty( $_POST['slug'] ) ) { | |
| 972 | + die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 973 | + } | |
| 974 | + | |
| 975 | + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 976 | + $ignore = isset( $_POST['ignore'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore'] ) ) : ''; | |
| 977 | + $site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : 0; | |
| 978 | + $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : ''; | |
| 979 | + | |
| 980 | + if ( 'wp' === $type ) { | |
| 981 | + if ( ( 'this_version' === $ignore || 'all_versions' === $ignore ) && $site_id ) { | |
| 982 | + $website = MainWP_DB::instance()->get_website_by_id( $site_id, false, array( 'ignored_wp_upgrades' ) ); | |
| 983 | + | |
| 984 | + if ( empty( $website ) ) { | |
| 985 | + wp_send_json( array( 'error' => esc_html__( 'Site ID invalid or site not found. Please try again.', 'mainwp' ) ) ); | |
| 986 | + } | |
| 987 | + | |
| 988 | + $ignored_upgrades = ! empty( $website->ignored_wp_upgrades ) ? json_decode( $website->ignored_wp_upgrades, true ) : array(); | |
| 989 | + | |
| 990 | + if ( ! is_array( $ignored_upgrades ) ) { | |
| 991 | + $ignored_upgrades = array(); | |
| 992 | + } | |
| 993 | + | |
| 994 | + $ignored_vers = is_array( $ignored_upgrades ) && isset( $ignored_upgrades['ignored_versions'] ) ? $ignored_upgrades['ignored_versions'] : array(); | |
| 995 | + if ( ! is_array( $ignored_vers ) ) { | |
| 996 | + $ignored_vers = array(); | |
| 997 | + } | |
| 998 | + | |
| 999 | + if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all. | |
| 1000 | + $ignored_vers = array( 'all_versions' ); | |
| 1001 | + } else { | |
| 1002 | + $ver = urldecode( $ver ); | |
| 1003 | + if ( ! in_array( $ver, $ignored_vers ) ) { | |
| 1004 | + $ignored_vers[] = $ver; | |
| 1005 | + } | |
| 1006 | + } | |
| 1007 | + | |
| 1008 | + $ignored_upgrades['ignored_versions'] = $ignored_vers; | |
| 1009 | + | |
| 1010 | + MainWP_DB::instance()->update_website_option( | |
| 1011 | + $site_id, | |
| 1012 | + 'ignored_wp_upgrades', | |
| 1013 | + wp_json_encode( $ignored_upgrades ) | |
| 1014 | + ); | |
| 1015 | + | |
| 1016 | + wp_send_json( array( 'success' => 1 ) ); | |
| 1017 | + | |
| 1018 | + } elseif ( 'this_version_global' === $ignore ) { | |
| 1019 | + | |
| 1020 | + $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 1021 | + $decodedIgnoredCores = ! empty( $userExtension->ignored_wp_upgrades ) ? json_decode( $userExtension->ignored_wp_upgrades, true ) : array(); | |
| 1022 | + | |
| 1023 | + if ( ! is_array( $decodedIgnoredCores ) ) { | |
| 1024 | + $decodedIgnoredCores = array(); | |
| 1025 | + } | |
| 1026 | + | |
| 1027 | + $ignored_vers = isset( $decodedIgnoredCores['ignored_versions'] ) ? $decodedIgnoredCores['ignored_versions'] : array(); | |
| 1028 | + | |
| 1029 | + if ( ! is_array( $ignored_vers ) ) { | |
| 1030 | + $ignored_vers = array(); | |
| 1031 | + } | |
| 1032 | + | |
| 1033 | + $ver = urldecode( $ver ); | |
| 1034 | + if ( ! in_array( $ver, $ignored_vers ) ) { | |
| 1035 | + $ignored_vers[] = $ver; | |
| 1036 | + } | |
| 1037 | + | |
| 1038 | + $decodedIgnoredCores['ignored_versions'] = $ignored_vers; | |
| 1039 | + | |
| 1040 | + MainWP_DB_Common::instance()->update_user_extension( | |
| 1041 | + array( | |
| 1042 | + 'userid' => null, | |
| 1043 | + 'ignored_wp_upgrades' => wp_json_encode( $decodedIgnoredCores ), | |
| 1044 | + ) | |
| 1045 | + ); | |
| 1046 | + wp_send_json( array( 'success' => 1 ) ); | |
| 1047 | + } | |
| 1048 | + } | |
| 1049 | + wp_send_json( array( 'error' => esc_html__( 'Invalid types. Please try again.', 'mainwp' ) ) ); | |
| 1050 | + } | |
| 1051 | + | |
| 1052 | + /** | |
| 1053 | + * Method ajax_unignore_core_updates() | |
| 1054 | + * | |
| 1055 | + * Unignore plugin or theme. | |
| 1056 | + */ | |
| 1057 | + public function ajax_unignore_core_updates() { | |
| 1058 | + $this->secure_request( 'mainwp_updates_unignore_upgrades' ); | |
| 1059 | + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 1060 | + $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : ''; // numberic id or _ALL_. | |
| 1061 | + $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : ''; | |
| 1062 | + // phpcs:enable | |
| 1063 | + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_core_updates( $id, $ver ) ) ) ); | |
| 1064 | + } | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + /** | |
| 1068 | + * Method ajax_unignore_global_upgrades() | |
| 1069 | + * | |
| 1070 | + * Unignore plugin or theme. | |
| 1071 | + */ | |
| 1072 | + public function ajax_unignore_global_upgrades() { | |
| 1073 | + $this->secure_request( 'mainwp_updates_unignore_global_upgrades' ); | |
| 1074 | + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 1075 | + $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : ''; | |
| 1076 | + $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : ''; | |
| 1077 | + // phpcs:enable | |
| 1078 | + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_global_cores( $slug, $ver ) ) ) ); | |
| 1079 | + } | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + /** | |
| 1083 | + * Method mainwp_trust_plugin() | |
| 1084 | + * | |
| 1085 | + * Trust plugin. | |
| 1086 | + * | |
| 1087 | + * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_post() | |
| 1088 | + * @uses \MainWP\Dashboard\MainWP_Themes_Handler::trust_post() | |
| 1089 | + */ | |
| 1090 | + public function mainwp_trust_plugin() { | |
| 1091 | + $this->secure_request( 'mainwp_trust_plugin' ); | |
| 1092 | + | |
| 1093 | + MainWP_Plugins_Handler::trust_post(); | |
| 1094 | + die( wp_json_encode( array( 'result' => true ) ) ); | |
| 1095 | + } | |
| 1096 | + | |
| 1097 | + /** | |
| 1098 | + * Method mainwp_trust_theme() | |
| 1099 | + * | |
| 1100 | + * Trust theme. | |
| 1101 | + */ | |
| 1102 | + public function mainwp_trust_theme() { | |
| 1103 | + $this->secure_request( 'mainwp_trust_theme' ); | |
| 1104 | + | |
| 1105 | + MainWP_Themes_Handler::trust_post(); | |
| 1106 | + die( wp_json_encode( array( 'result' => true ) ) ); | |
| 1107 | + } | |
| 856 | 1108 | } |