PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.2
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
← All changes | class/class-mainwp-post-plugin-theme-handler.php +696 -1006 6.24.2 View file →
@@ -6,13 +6,8 @@
6 6 */
7 7
8 8 namespace MainWP\Dashboard;
9 9
10 -// Exit if accessed directly.
11 -if ( ! defined( 'ABSPATH' ) ) {
12 - exit;
13 -}
14 -
15 10 /**
16 11 * Class MainWP_Post_Plugin_Theme_Handler
17 12 *
18 13 * @package MainWP\Dashboard
@@ -18,1090 +13,785 @@
18 13 * @package MainWP\Dashboard
19 14 *
20 15 * @uses \MainWP\Dashboard\MainWP_Post_Base_Handler
21 16 */
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;
17 +class MainWP_Post_Plugin_Theme_Handler extends MainWP_Post_Base_Handler {
30 18
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 - }
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;
45 25
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' ) );
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 + }
53 40
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' ) );
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' ) );
61 48
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' ) );
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' ) );
79 55
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 - }
56 + // Widget: RightNow.
57 + $this->add_action( 'mainwp_upgradewp', array( &$this, 'mainwp_upgradewp' ) );
58 + $this->add_action( 'mainwp_upgradeplugintheme', array( &$this, 'mainwp_upgrade_plugintheme' ) );
59 + $this->add_action( 'mainwp_ignoreplugintheme', array( &$this, 'mainwp_ignoreplugintheme' ) );
60 + $this->add_action( 'mainwp_unignoreplugintheme', array( &$this, 'mainwp_unignoreplugintheme' ) );
61 + $this->add_action( 'mainwp_ignorepluginsthemes', array( &$this, 'mainwp_ignorepluginsthemes' ) );
62 + $this->add_action( 'mainwp_unignorepluginsthemes', array( &$this, 'mainwp_unignorepluginsthemes' ) );
63 + $this->add_action( 'mainwp_unignoreabandonedplugintheme', array( &$this, 'mainwp_unignoreabandonedplugintheme' ) );
64 + $this->add_action( 'mainwp_unignoreabandonedpluginsthemes', array( &$this, 'mainwp_unignoreabandonedpluginsthemes' ) );
65 + $this->add_action( 'mainwp_dismissoutdateplugintheme', array( &$this, 'mainwp_dismissoutdateplugintheme' ) );
66 + $this->add_action( 'mainwp_dismissoutdatepluginsthemes', array( &$this, 'mainwp_dismissoutdatepluginsthemes' ) );
67 + $this->add_action( 'mainwp_trust_plugin', array( &$this, 'mainwp_trust_plugin' ) );
68 + $this->add_action( 'mainwp_trust_theme', array( &$this, 'mainwp_trust_theme' ) );
93 69
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' ) );
70 + // Page: Themes.
71 + $this->add_action( 'mainwp_themes_search', array( &$this, 'mainwp_themes_search' ) );
72 + $this->add_action( 'mainwp_themes_search_all', array( &$this, 'mainwp_themes_search_all' ) );
73 + if ( mainwp_current_user_have_right( 'dashboard', 'activate_themes' ) ) {
74 + $this->add_action( 'mainwp_theme_activate', array( &$this, 'mainwp_theme_activate' ) );
75 + }
76 + if ( mainwp_current_user_have_right( 'dashboard', 'delete_themes' ) ) {
77 + $this->add_action( 'mainwp_theme_delete', array( &$this, 'mainwp_theme_delete' ) );
78 + }
79 + $this->add_action( 'mainwp_trusted_theme_notes_save', array( &$this, 'mainwp_trusted_theme_notes_save' ) );
80 + if ( mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) {
81 + $this->add_action( 'mainwp_theme_ignore_updates', array( &$this, 'mainwp_theme_ignore_updates' ) );
82 + }
97 83
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 - }
84 + // Page: Plugins.
85 + $this->add_action( 'mainwp_plugins_search', array( &$this, 'mainwp_plugins_search' ) );
86 + $this->add_action( 'mainwp_plugins_search_all_active', array( &$this, 'mainwp_plugins_search_all_active' ) );
105 87
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' ) );
88 + if ( mainwp_current_user_have_right( 'dashboard', 'activate_deactivate_plugins' ) ) {
89 + $this->add_action( 'mainwp_plugin_activate', array( &$this, 'mainwp_plugin_activate' ) );
90 + $this->add_action( 'mainwp_plugin_deactivate', array( &$this, 'mainwp_plugin_deactivate' ) );
91 + }
92 + if ( mainwp_current_user_have_right( 'dashboard', 'delete_plugins' ) ) {
93 + $this->add_action( 'mainwp_plugin_delete', array( &$this, 'mainwp_plugin_delete' ) );
94 + }
110 95
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' ) );
96 + if ( mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) {
97 + $this->add_action( 'mainwp_plugin_ignore_updates', array( &$this, 'mainwp_plugin_ignore_updates' ) );
98 + }
99 + $this->add_action( 'mainwp_trusted_plugin_notes_save', array( &$this, 'mainwp_trusted_plugin_notes_save' ) );
115 100
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 - }
101 + // Widget: Plugins.
102 + $this->add_action( 'mainwp_widget_plugin_activate', array( &$this, 'mainwp_widget_plugin_activate' ) );
103 + $this->add_action( 'mainwp_widget_plugin_deactivate', array( &$this, 'mainwp_widget_plugin_deactivate' ) );
104 + $this->add_action( 'mainwp_widget_plugin_delete', array( &$this, 'mainwp_widget_plugin_delete' ) );
120 105
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;
106 + // Widget: Themes.
107 + $this->add_action( 'mainwp_widget_theme_activate', array( &$this, 'mainwp_widget_theme_activate' ) );
108 + $this->add_action( 'mainwp_widget_theme_delete', array( &$this, 'mainwp_widget_theme_delete' ) );
109 + }
140 110
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 - }
111 + /**
112 + * Method mainwp_themes_search()
113 + *
114 + * Search handler for Themes.
115 + *
116 + * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
117 + *
118 + * @uses \MainWP\Dashboard\MainWP_Themes::render_table()
119 + */
120 + public function mainwp_themes_search() {
121 + $this->secure_request( 'mainwp_themes_search' );
146 122
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 - }
123 + $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
124 + $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
125 + $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : array();
126 + $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : array();
127 + $not_criteria = isset( $_POST['not_criteria'] ) && 'true' === $_POST['not_criteria'] ? true : false;
128 + MainWP_Cache::init_session();
129 + $result = MainWP_Themes::render_table( $keyword, $status, $groups, $sites, $not_criteria );
130 + wp_send_json( $result );
131 + }
160 132
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 - }
133 + /**
134 + * Method mainwp_theme_activate()
135 + *
136 + * Activate Theme,
137 + * Page: Themes.
138 + *
139 + * @uses \MainWP\Dashboard\MainWP_Themes_Handler::activate_theme()
140 + */
141 + public function mainwp_theme_activate() {
142 + $this->secure_request( 'mainwp_theme_activate' );
143 + MainWP_Themes_Handler::activate_theme();
144 + die();
145 + }
174 146
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 - }
147 + /**
148 + * Method mainwp_theme_delete()
149 + *
150 + * Delete Theme,
151 + * Page: Themes.
152 + *
153 + * @uses \MainWP\Dashboard\MainWP_Themes_Handler::delete_themes()
154 + */
155 + public function mainwp_theme_delete() {
156 + $this->secure_request( 'mainwp_theme_delete' );
157 + MainWP_Themes_Handler::delete_themes();
158 + die();
159 + }
188 160
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 - }
161 + /**
162 + * Method mainwp_theme_ignore_updates()
163 + *
164 + * Ignore theme updates,
165 + * Page: Themes.
166 + *
167 + * @uses \MainWP\Dashboard\MainWP_Themes_Handler::ignore_updates()
168 + */
169 + public function mainwp_theme_ignore_updates() {
170 + $this->secure_request( 'mainwp_theme_ignore_updates' );
171 + MainWP_Themes_Handler::ignore_updates();
172 + die();
173 + }
204 174
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 - }
175 + /**
176 + * Method mainwp_themes_search_all()
177 + *
178 + * Search ALL handler for,
179 + * Page: Themes.
180 + *
181 + * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
182 + * @uses \MainWP\Dashboard\MainWP_Themes::render_all_themes_table()
183 + */
184 + public function mainwp_themes_search_all() {
185 + $this->secure_request( 'mainwp_themes_search_all' );
186 + MainWP_Cache::init_session();
187 + MainWP_Themes::render_all_themes_table();
188 + die();
189 + }
225 190
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;
191 + /**
192 + * Method mainwp_trusted_theme_notes_save()
193 + *
194 + * Save trusted theme notes,
195 + * Page: Themes.
196 + *
197 + * @uses \MainWP\Dashboard\MainWP_Themes_Handler::save_trusted_theme_note()
198 + */
199 + public function mainwp_trusted_theme_notes_save() {
200 + $this->secure_request( 'mainwp_trusted_theme_notes_save' );
201 + MainWP_Themes_Handler::save_trusted_theme_note();
202 + die( wp_json_encode( array( 'result' => 'SUCCESS' ) ) );
203 + }
244 204
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 - }
205 + /**
206 + * Method mainwp_plugins_search()
207 + *
208 + * Search handler for Plugins.
209 + *
210 + * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
211 + * @uses \MainWP\Dashboard\MainWP_Plugins::render_table()
212 + */
213 + public function mainwp_plugins_search() {
214 + $this->secure_request( 'mainwp_plugins_search' );
250 215
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 - }
216 + $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
217 + $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
218 + $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
219 + $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
220 + $not_criteria = isset( $_POST['not_criteria'] ) && 'true' === $_POST['not_criteria'] ? true : false;
221 + MainWP_Cache::init_session();
222 + $result = MainWP_Plugins::render_table( $keyword, $status, $groups, $sites, $not_criteria );
223 + wp_send_json( $result );
224 + }
266 225
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 - }
226 + /**
227 + * Method mainwp_plugins_search_all_active()
228 + *
229 + * Search all Active handler for,
230 + * Page: Plugins.
231 + *
232 + * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
233 + * @uses \MainWP\Dashboard\MainWP_Plugins::render_all_active_table()
234 + */
235 + public function mainwp_plugins_search_all_active() {
236 + $this->secure_request( 'mainwp_plugins_search_all_active' );
237 + MainWP_Cache::init_session();
238 + MainWP_Plugins::render_all_active_table();
239 + die();
240 + }
280 241
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 - }
242 + /**
243 + * Method mainwp_plugin_activate()
244 + *
245 + * Activate plugins,
246 + * Page: Plugins.
247 + *
248 + * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::activate_plugins()
249 + */
250 + public function mainwp_plugin_activate() {
251 + $this->secure_request( 'mainwp_plugin_activate' );
252 + MainWP_Plugins_Handler::activate_plugins();
253 + die();
254 + }
294 255
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 - }
256 + /**
257 + * Method mainwp_plugin_deactivate()
258 + *
259 + * Deactivate plugins,
260 + * Page: Plugins.
261 + *
262 + * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::deactivate_plugins()
263 + */
264 + public function mainwp_plugin_deactivate() {
265 + $this->secure_request( 'mainwp_plugin_deactivate' );
266 + MainWP_Plugins_Handler::deactivate_plugins();
267 + die();
268 + }
308 269
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 - }
270 + /**
271 + * Method mainwp_plugin_delete()
272 + *
273 + * Delete plugins,
274 + * Page: Plugins.
275 + *
276 + * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::delete_plugins()
277 + */
278 + public function mainwp_plugin_delete() {
279 + $this->secure_request( 'mainwp_plugin_delete' );
280 + MainWP_Plugins_Handler::delete_plugins();
281 + die();
282 + }
322 283
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 - }
284 + /**
285 + * Method mainwp_plugin_ignore_updates()
286 + *
287 + * Ignore plugins updates,
288 + * Page: Plugins.
289 + *
290 + * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::ignore_updates()
291 + */
292 + public function mainwp_plugin_ignore_updates() {
293 + $this->secure_request( 'mainwp_plugin_ignore_updates' );
294 + MainWP_Plugins_Handler::ignore_updates();
295 + die();
296 + }
343 297
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 - }
298 + /**
299 + * Method mainwp_trusted_plugin_notes_save()
300 + *
301 + * Save trusted plugin notes,
302 + * Page: Plugins.
303 + *
304 + * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::save_trusted_plugin_note()
305 + */
306 + public function mainwp_trusted_plugin_notes_save() {
307 + $this->secure_request( 'mainwp_trusted_plugin_notes_save' );
308 + MainWP_Plugins_Handler::save_trusted_plugin_note();
309 + die( wp_json_encode( array( 'result' => 'SUCCESS' ) ) );
310 + }
356 311
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 - }
312 + /**
313 + * Method mainwp_widget_plugin_activate()
314 + *
315 + * Activate plugin,
316 + * Widget: Plugins.
317 + *
318 + * @uses \MainWP\Dashboard\MainWP_Widget_Plugins::activate_plugin()
319 + */
320 + public function mainwp_widget_plugin_activate() {
321 + $this->secure_request( 'mainwp_widget_plugin_activate' );
322 + MainWP_Widget_Plugins::activate_plugin();
323 + }
369 324
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 - }
325 + /**
326 + * Method mainwp_widget_plugin_deactivate()
327 + *
328 + * Deactivate plugin,
329 + * Widget: Plugins.
330 + *
331 + * @uses \MainWP\Dashboard\MainWP_Widget_Plugins::deactivate_plugin()
332 + */
333 + public function mainwp_widget_plugin_deactivate() {
334 + $this->secure_request( 'mainwp_widget_plugin_deactivate' );
335 + MainWP_Widget_Plugins::deactivate_plugin();
336 + }
382 337
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 - }
338 + /**
339 + * Method mainwp_widget_plugin_delete()
340 + *
341 + * Delete plugin,
342 + * Widget: Plugins.
343 + *
344 + * @uses \MainWP\Dashboard\MainWP_Widget_Plugins::delete_plugin()
345 + */
346 + public function mainwp_widget_plugin_delete() {
347 + $this->secure_request( 'mainwp_widget_plugin_delete' );
348 + MainWP_Widget_Plugins::delete_plugin();
349 + }
395 350
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 - }
351 + /**
352 + * Method mainwp_widget_plugin_activate()
353 + *
354 + * Activate theme,
355 + * Widget: Themes.
356 + *
357 + * @uses \MainWP\Dashboard\MainWP_Widget_Themes::activate_theme()
358 + */
359 + public function mainwp_widget_theme_activate() {
360 + $this->secure_request( 'mainwp_widget_theme_activate' );
361 + MainWP_Widget_Themes::activate_theme();
362 + }
408 363
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 - }
364 + /**
365 + * Method mainwp_widget_plugin_delete()
366 + *
367 + * Delete theme,
368 + * Widget: Themes.
369 + *
370 + * @uses \MainWP\Dashboard\MainWP_Widget_Themes::delete_theme()
371 + */
372 + public function mainwp_widget_theme_delete() {
373 + $this->secure_request( 'mainwp_widget_theme_delete' );
374 + MainWP_Widget_Themes::delete_theme();
375 + }
421 376
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 - }
377 + /**
378 + * Method mainwp_preparebulkinstallplugintheme()
379 + *
380 + * Prepair bulk installation of plugins & themes,
381 + * Page: InstallPlugins/Themes.
382 + *
383 + * @uses \MainWP\Dashboard\MainWP_Install_Bulk::prepare_install()
384 + */
385 + public function mainwp_preparebulkinstallplugintheme() {
386 + $this->secure_request( 'mainwp_preparebulkinstallplugintheme' );
387 + MainWP_Install_Bulk::prepare_install();
388 + }
434 389
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 - }
390 + /**
391 + * Method mainwp_installbulkinstallplugintheme()
392 + *
393 + * Installation of plugins & themes,
394 + * Page: InstallPlugins/Themes.
395 + *
396 + * @uses \MainWP\Dashboard\MainWP_Install_Bulk::perform_install()
397 + */
398 + public function mainwp_installbulkinstallplugintheme() {
399 + $this->secure_request( 'mainwp_installbulkinstallplugintheme' );
400 + MainWP_Install_Bulk::perform_install();
401 + }
447 402
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 - }
403 + /**
404 + * Method mainwp_preparebulkuploadplugintheme()
405 + *
406 + * Prepair bulk upload of plugins & themes,
407 + * Page: InstallPlugins/Themes.
408 + *
409 + * @uses \MainWP\Dashboard\MainWP_Install_Bulk::prepare_upload()
410 + */
411 + public function mainwp_preparebulkuploadplugintheme() {
412 + $this->secure_request( 'mainwp_preparebulkuploadplugintheme' );
413 + MainWP_Install_Bulk::prepare_upload();
414 + }
460 415
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 - }
416 + /**
417 + * Method mainwp_installbulkuploadplugintheme()
418 + *
419 + * Bulk upload of plugins & themes,
420 + * Page: InstallPlugins/Themes.
421 + *
422 + * @uses \MainWP\Dashboard\MainWP_Install_Bulk::perform_upload()
423 + */
424 + public function mainwp_installbulkuploadplugintheme() {
425 + $this->secure_request( 'mainwp_installbulkuploadplugintheme' );
426 + MainWP_Install_Bulk::perform_upload();
427 + }
473 428
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 - }
429 + /**
430 + * Method mainwp_cleanbulkuploadplugintheme()
431 + *
432 + * Clean upload of plugins & themes,
433 + * Page: InstallPlugins/Themes.
434 + *
435 + * @uses \MainWP\Dashboard\MainWP_Install_Bulk::clean_upload()
436 + */
437 + public function mainwp_cleanbulkuploadplugintheme() {
438 + $this->secure_request( 'mainwp_cleanbulkuploadplugintheme' );
439 + MainWP_Install_Bulk::clean_upload();
440 + }
483 441
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 - }
442 + /**
443 + * Method mainwp_ext_prepareinstallplugintheme()
444 + *
445 + * Prepair Installation of plugins & themes,
446 + * Page: ManageSites.
447 + */
448 + public function mainwp_ext_prepareinstallplugintheme() {
449 + do_action( 'mainwp_prepareinstallplugintheme' );
450 + }
494 451
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 - }
452 + /**
453 + * Method mainwp_ext_performinstallplugintheme()
454 + *
455 + * Installation of plugins & themes,
456 + * Page: ManageSites.
457 + */
458 + public function mainwp_ext_performinstallplugintheme() {
459 + $this->secure_request( 'mainwp_ext_performinstallplugintheme' );
460 + do_action( 'mainwp_performinstallplugintheme' );
461 + }
515 462
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 - }
463 + /**
464 + * Method mainwp_upgradewp()
465 + *
466 + * Update a specific WP core.
467 + *
468 + * @uses \MainWP\Dashboard\MainWP_Exception
469 + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::upgrade_site()
470 + */
471 + public function mainwp_upgradewp() {
472 + if ( ! mainwp_current_user_have_right( 'dashboard', 'update_wordpress' ) ) {
473 + die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'update WordPress', 'mainwp' ), $echo = false ) ) ) );
474 + }
528 475
529 - $this->secure_request( 'mainwp_upgradewp' );
476 + $this->secure_request( 'mainwp_upgradewp' );
530 477
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 - }
478 + try {
479 + $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : false;
480 + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::upgrade_site( $id ) ) ) ); // ok.
481 + } catch ( MainWP_Exception $e ) {
482 + die(
483 + wp_json_encode(
484 + array(
485 + 'error' => array(
486 + 'message' => $e->getMessage(),
487 + 'extra' => $e->get_message_extra(),
488 + ),
489 + )
490 + )
491 + );
492 + }
493 + }
548 494
495 + /**
496 + * Method mainwp_upgrade_plugintheme()
497 + *
498 + * Update plugin or theme.
499 + *
500 + * @uses \MainWP\Dashboard\MainWP_DB_Backup::backup_full_task_running()
501 + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
502 + * @uses \MainWP\Dashboard\MainWP_Exception
503 + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::get_plugin_theme_slugs()
504 + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::upgrade_plugin_theme_translation()
505 + */
506 + public function mainwp_upgrade_plugintheme() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
549 507
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' );
508 + if ( ! isset( $_POST['type'] ) ) {
509 + die( wp_json_encode( array( 'error' => '<i class="red times icon"></i> ' . __( 'Plugin or theme not specified. Please reload the page and try again.', 'mainwp' ) ) ) );
510 + }
557 511
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.
512 + if ( 'plugin' === $_POST['type'] && ! mainwp_current_user_have_right( 'dashboard', 'update_plugins' ) ) {
513 + die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'update plugins', 'mainwp' ), $echo = false ) ) ) );
514 + }
566 515
567 - if ( 'translation' === $update_type ) {
568 - $update_type = 'trans'; // compatible.
569 - } elseif ( 'wp' === $update_type ) {
570 - $update_type = 'core'; // compatible.
571 - }
516 + if ( 'theme' === $_POST['type'] && ! mainwp_current_user_have_right( 'dashboard', 'update_themes' ) ) {
517 + die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'update themes', 'mainwp' ), $echo = false ) ) ) );
518 + }
572 519
573 - $data = MainWP_Updates_Overview::prepare_update_data( $update_type, $current_siteid );
520 + if ( 'translation' === $_POST['type'] && ! mainwp_current_user_have_right( 'dashboard', 'update_translations' ) ) {
521 + die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'update translations', 'mainwp' ), $echo = false ) ) ) );
522 + }
574 523
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 - );
524 + $this->secure_request( 'mainwp_upgradeplugintheme' );
588 525
589 - extract( $data ); // phpcs:ignore -- NOSONAR - well structure.
526 + // support chunk update for manage sites page only.
527 + $chunk_support = ! empty( $_POST['chunk_support'] ) ? true : false;
528 + $max_update = 0;
529 + $websiteId = null;
530 + $slugs = '';
590 531
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' );
532 + if ( isset( $_POST['websiteId'] ) ) {
533 + $websiteId = intval( $_POST['websiteId'] );
595 534
596 - $mainwp_show_language_updates = get_option( 'mainwp_show_language_updates', 1 );
535 + if ( $chunk_support ) {
536 + /**
537 + * Filter: mainwp_update_plugintheme_max
538 + *
539 + * Filters the max number of plugins/themes to be updated in one run in order to improve performance.
540 + *
541 + * @param int $websiteId Child site ID.
542 + *
543 + * @since Unknown
544 + */
545 + $max_update = apply_filters( 'mainwp_update_plugintheme_max', false, $websiteId );
546 + if ( empty( $max_update ) ) {
547 + $chunk_support = false; // there is no hook so disable chunk update support.
548 + }
549 + }
550 + if ( $chunk_support ) {
551 + if ( isset( $_POST['chunk_slugs'] ) ) {
552 + $slugs = wp_unslash( $_POST['chunk_slugs'] );
553 + } else {
554 + $slugs = MainWP_Updates_Handler::get_plugin_theme_slugs( $websiteId, sanitize_text_field( wp_unslash( $_POST['type'] ) ) );
555 + }
556 + } elseif ( isset( $_POST['slug'] ) ) {
557 + $slugs = wp_unslash( $_POST['slug'] );
558 + } else {
559 + $slugs = MainWP_Updates_Handler::get_plugin_theme_slugs( $websiteId, sanitize_text_field( wp_unslash( $_POST['type'] ) ) );
560 + }
561 + }
597 562
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 - );
563 + if ( MainWP_DB_Backup::instance()->backup_full_task_running( $websiteId ) ) {
564 + die( wp_json_encode( array( 'error' => __( 'Backup process in progress on the child site. Please, try again later.', 'mainwp' ) ) ) );
565 + }
614 566
615 - die();
616 - }
567 + $chunk_slugs = array();
617 568
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.
569 + if ( $chunk_support ) {
570 + // calculate update slugs here.
571 + if ( $max_update ) {
572 + $slugs = explode( ',', $slugs );
573 + $chunk_slugs = array_slice( $slugs, $max_update );
574 + $update_slugs = array_diff( $slugs, $chunk_slugs );
575 + $slugs = implode( ',', $update_slugs );
576 + }
577 + }
630 578
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 - }
579 + if ( empty( $slugs ) && ! $chunk_support ) {
580 + die( wp_json_encode( array( 'message' => __( 'Item slug could not be found. Update process could not be executed.', 'mainwp' ) ) ) );
581 + }
582 + $website = MainWP_DB::instance()->get_website_by_id( $websiteId );
583 + try {
584 + $info = array( 'result' => MainWP_Updates_Handler::upgrade_plugin_theme_translation( $websiteId, sanitize_text_field( wp_unslash( $_POST['type'] ) ), $slugs ) );
635 585
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 - }
586 + if ( $chunk_support && ( 0 < count( $chunk_slugs ) ) ) {
587 + $info['chunk_slugs'] = implode( ',', $chunk_slugs );
588 + }
639 589
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 - }
590 + if ( ! empty( $website ) ) {
591 + $info['site_url'] = esc_url( $website->url );
592 + }
593 + wp_send_json( $info );
594 + } catch ( MainWP_Exception $e ) {
595 + die(
596 + wp_json_encode(
597 + array(
598 + 'error' => array(
599 + 'message' => $e->getMessage(),
600 + 'extra' => $e->get_message_extra(),
601 + ),
602 + )
603 + )
604 + );
605 + }
606 + }
643 607
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 - }
608 + /**
609 + * Method mainwp_ignoreplugintheme()
610 + *
611 + * Ignores a plugin or a theme.
612 + */
613 + public function mainwp_ignoreplugintheme() {
614 + $this->secure_request( 'mainwp_ignoreplugintheme' );
647 615
648 - $this->secure_request( 'mainwp_upgradeplugintheme' );
616 + if ( ! isset( $_POST['id'] ) ) {
617 + die( wp_json_encode( array( 'error' => __( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
618 + }
619 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
620 + $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
621 + $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0;
622 + $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
623 + wp_send_json( array( 'result' => MainWP_Updates_Handler::ignore_plugin_theme( $type, $slug, $name, $id ) ) );
624 + }
649 625
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 = '';
626 + /**
627 + * Method mainwp_unignoreabandonedplugintheme()
628 + *
629 + * Unignore abandoned plugin or theme.
630 + *
631 + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugin_theme()
632 + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_abandoned_plugin_theme()
633 + */
634 + public function mainwp_unignoreabandonedplugintheme() {
635 + $this->secure_request( 'mainwp_unignoreabandonedplugintheme' );
655 636
656 - if ( isset( $_POST['websiteId'] ) ) {
657 - $websiteId = intval( $_POST['websiteId'] );
637 + if ( ! isset( $_POST['id'] ) ) {
638 + die( wp_json_encode( array( 'error' => __( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
639 + }
658 640
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
641 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
642 + $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
643 + $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : 0; // string|int.
644 + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_abandoned_plugin_theme( $type, $slug, $id ) ) ) ); // ok.
645 + }
687 646
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 - }
647 + /**
648 + * Method mainwp_unignoreabandonedpluginthemes()
649 + *
650 + * Unignore abandoned plugins or themes.
651 + *
652 + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_abandoned_plugins_themes()
653 + */
654 + public function mainwp_unignoreabandonedpluginsthemes() {
655 + $this->secure_request( 'mainwp_unignoreabandonedpluginsthemes' );
691 656
692 - $chunk_slugs = array();
657 + if ( ! isset( $_POST['slug'] ) ) {
658 + die( wp_json_encode( array( 'error' => __( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
659 + }
693 660
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 - }
661 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
662 + $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
663 + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_abandoned_plugins_themes( $type, $slug ) ) ) );
664 + }
700 665
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 - );
666 + /**
667 + * Method mainwp_dismissoutdateplugintheme()
668 + *
669 + * Dismiss outdated plugin or theme.
670 + *
671 + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::dismiss_plugin_theme()
672 + */
673 + public function mainwp_dismissoutdateplugintheme() {
674 + $this->secure_request( 'mainwp_dismissoutdateplugintheme' );
711 675
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
676 + if ( ! isset( $_POST['id'] ) ) {
677 + die( wp_json_encode( array( 'error' => __( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
678 + }
679 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
680 + $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
681 + $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
682 + $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0;
683 + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::dismiss_plugin_theme( $type, $slug, $name, $id ) ) ) );
684 + }
713 685
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 - if ( isset( $result['result_started'] ) ) {
722 - $info['result_started'] = $result['result_started'];
723 - }
724 - }
686 + /**
687 + * Method mainwp_dismissoutdatepluginthemes()
688 + *
689 + * Dismiss outdated plugins or themes.
690 + *
691 + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::dismiss_plugins_themes()
692 + */
693 + public function mainwp_dismissoutdatepluginsthemes() {
694 + $this->secure_request( 'mainwp_dismissoutdatepluginsthemes' );
725 695
726 - // MWP-1660: append a generic licensing hint to failures of known premium
727 - // products; vendors only deliver update packages to licensed installs.
728 - $item_type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
729 - if ( ( 'plugin' === $item_type || 'theme' === $item_type ) && ! empty( $info['result_error'] ) && is_array( $info['result_error'] ) ) {
730 - $premium_ids = MainWP_Premium_Update_Registry::get_filter_defaults( $item_type, 'detect' );
731 - $premium_prefixes = MainWP_Premium_Update_Registry::get_prefixes( $item_type, 'detect' );
732 - foreach ( $info['result_error'] as $err_slug => $err_msg ) {
733 - if ( is_string( $err_msg ) && MainWP_Premium_Update_Registry::slug_matches( urldecode( $err_slug ), $premium_ids, $premium_prefixes ) ) {
734 - $info['result_error'][ $err_slug ] = $err_msg . ' ' . esc_html__( 'Premium updates usually require an active license on the child site; check that first.', 'mainwp' );
735 - }
736 - }
737 - }
696 + if ( ! mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) {
697 + die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'ignore/unignore updates', 'mainwp' ) ) ) ) );
698 + }
738 699
739 - if ( $chunk_support && ( ! empty( $chunk_slugs ) ) ) {
740 - $info['chunk_slugs'] = implode( ',', $chunk_slugs );
741 - }
700 + if ( ! isset( $_POST['slug'] ) ) {
701 + die( wp_json_encode( array( 'error' => __( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
702 + }
742 703
743 - if ( ! empty( $website ) ) {
744 - $info['site_url'] = esc_url( $website->url );
745 - }
704 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
705 + $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
706 + $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
746 707
747 - // Get max the scope of the largest change.
748 - $max_scope = apply_filters( 'mainwp_html_regression_largest_change_scope', $websiteId, false );
749 - if ( ! empty( $max_scope ) && $max_scope !== $websiteId ) {
750 - $info['result']['html_regression_max_scope'] = $max_scope;
751 - }
708 + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::dismiss_plugins_themes( $type, $slug, $name ) ) ) );
709 + }
752 710
753 - wp_send_json( $info );
754 - } catch ( MainWP_Exception $e ) {
755 - die(
756 - wp_json_encode(
757 - array(
758 - 'error' => array(
759 - 'message' => $e->getMessage(),
760 - 'extra' => $e->get_message_extra(),
761 - 'errorCode' => $e->get_message_error_code(),
762 - ),
763 - )
764 - )
765 - );
766 - }
767 - }
711 + /**
712 + * Method mainwp_unignoreplugintheme()
713 + *
714 + * Unignore plugin or theme.
715 + *
716 + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_plugin_theme()
717 + */
718 + public function mainwp_unignoreplugintheme() {
719 + $this->secure_request( 'mainwp_unignoreplugintheme' );
768 720
769 - /**
770 - * Method mainwp_ignoreplugintheme()
771 - *
772 - * Ignores a plugin or a theme.
773 - */
774 - public function mainwp_ignoreplugintheme() {
775 - $this->secure_request( 'mainwp_ignoreplugintheme' );
721 + if ( ! isset( $_POST['id'] ) ) {
722 + die( wp_json_encode( array( 'error' => __( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
723 + }
724 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
725 + $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : '';
726 + $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
727 + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_plugin_theme( $type, $slug, $id ) ) ) );
728 + }
776 729
777 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
778 - if ( ! isset( $_POST['id'] ) ) {
779 - die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
780 - }
781 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
782 - $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
783 - $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0;
784 - $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
785 - $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
786 - // phpcs:enable
787 - wp_send_json( array( 'result' => MainWP_Updates_Handler::ignore_plugin_theme( $type, $slug, $name, $id, $ver ) ) );
788 - }
730 + /**
731 + * Method mainwp_ignorepluginthemes()
732 + *
733 + * Ignore plugins or themes.
734 + *
735 + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugins_themes()
736 + */
737 + public function mainwp_ignorepluginsthemes() {
738 + $this->secure_request( 'mainwp_ignorepluginsthemes' );
789 739
740 + if ( ! mainwp_current_user_have_right( 'dashboard', 'ignore_unignore_updates' ) ) {
741 + die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'ignore/unignore updates', 'mainwp' ) ) ) ) );
742 + }
790 743
791 - /**
792 - * Method mainwp_unignore_global_pluginsthemes()
793 - *
794 - * Unignore plugins or themes.
795 - */
796 - public function mainwp_unignore_global_pluginsthemes() {
797 - $this->secure_request( 'mainwp_unignorepluginsthemes' );
744 + if ( ! isset( $_POST['slug'] ) ) {
745 + die( wp_json_encode( array( 'error' => __( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
746 + }
798 747
799 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
800 - if ( ! isset( $_POST['slug'] ) ) {
801 - die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
802 - }
803 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
804 - $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : '';
805 - $ver = isset( $_POST['ignore_ver'] ) ? wp_unslash( $_POST['ignore_ver'] ) : '';
806 - // phpcs:enable
807 - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_global_plugins_themes( $type, $slug, $ver ) ) ) );
808 - }
748 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
749 + $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
750 + $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
751 + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::ignore_plugins_themes( $type, $slug, $name ) ) ) );
752 + }
809 753
810 - /**
811 - * Method mainwp_unignoreabandonedplugintheme()
812 - *
813 - * Unignore abandoned plugin or theme.
814 - *
815 - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugin_theme()
816 - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_abandoned_plugin_theme()
817 - */
818 - public function mainwp_unignoreabandonedplugintheme() {
819 - $this->secure_request( 'mainwp_unignoreabandonedplugintheme' );
754 + /**
755 + * Method mainwp_unignorepluginthemes()
756 + *
757 + * Unignore plugins or themes.
758 + */
759 + public function mainwp_unignorepluginsthemes() {
760 + $this->secure_request( 'mainwp_unignorepluginsthemes' );
820 761
821 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
822 - if ( ! isset( $_POST['id'] ) ) {
823 - die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
824 - }
762 + if ( ! isset( $_POST['slug'] ) ) {
763 + die( wp_json_encode( array( 'error' => __( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
764 + }
765 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
766 + $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : '';
767 + die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_plugins_themes( $type, $slug ) ) ) );
768 + }
825 769
826 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
827 - $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
828 - $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : 0; // string|int.
829 - // phpcs:enable
830 - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_abandoned_plugin_theme( $type, $slug, $id ) ) ) ); // ok.
831 - }
770 + /**
771 + * Method mainwp_trust_plugin()
772 + *
773 + * Trust plugin.
774 + *
775 + * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_post()
776 + * @uses \MainWP\Dashboard\MainWP_Themes_Handler::trust_post()
777 + */
778 + public function mainwp_trust_plugin() {
779 + $this->secure_request( 'mainwp_trust_plugin' );
832 780
833 - /**
834 - * Method mainwp_unignoreabandonedpluginthemes()
835 - *
836 - * Unignore abandoned plugins or themes.
837 - *
838 - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_abandoned_plugins_themes()
839 - */
840 - public function mainwp_unignoreabandonedpluginsthemes() {
841 - $this->secure_request( 'mainwp_unignoreabandonedpluginsthemes' );
781 + MainWP_Plugins_Handler::trust_post();
782 + die( wp_json_encode( array( 'result' => true ) ) );
783 + }
842 784
843 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
844 - if ( ! isset( $_POST['slug'] ) ) {
845 - die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
846 - }
785 + /**
786 + * Method mainwp_trust_theme()
787 + *
788 + * Trust theme.
789 + */
790 + public function mainwp_trust_theme() {
791 + $this->secure_request( 'mainwp_trust_theme' );
847 792
848 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
849 - $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
850 - // phpcs:enable
851 - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_abandoned_plugins_themes( $type, $slug ) ) ) );
852 - }
793 + MainWP_Themes_Handler::trust_post();
794 + die( wp_json_encode( array( 'result' => true ) ) );
795 + }
853 796
854 - /**
855 - * Method mainwp_dismissoutdateplugintheme()
856 - *
857 - * Dismiss outdated plugin or theme.
858 - *
859 - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::dismiss_plugin_theme()
860 - */
861 - public function mainwp_dismissoutdateplugintheme() {
862 - $this->secure_request( 'mainwp_dismissoutdateplugintheme' );
863 -
864 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
865 - if ( ! isset( $_POST['id'] ) ) {
866 - die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
867 - }
868 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
869 - $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
870 - $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
871 - $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0;
872 - // phpcs:enable
873 - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::dismiss_plugin_theme( $type, $slug, $name, $id ) ) ) );
874 - }
875 -
876 - /**
877 - * Method mainwp_dismissoutdatepluginthemes()
878 - *
879 - * Dismiss outdated plugins or themes.
880 - *
881 - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::dismiss_plugins_themes()
882 - */
883 - public function mainwp_dismissoutdatepluginsthemes() {
884 - $this->secure_request( 'mainwp_dismissoutdatepluginsthemes' );
885 -
886 - if ( ! \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) {
887 - die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'ignore/unignore updates', 'mainwp' ) ) ) ) );
888 - }
889 -
890 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
891 - if ( ! isset( $_POST['slug'] ) ) {
892 - die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
893 - }
894 -
895 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
896 - $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
897 - $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
898 - // phpcs:enable
899 -
900 - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::dismiss_plugins_themes( $type, $slug, $name ) ) ) );
901 - }
902 -
903 - /**
904 - * Method mainwp_unignoreplugintheme()
905 - *
906 - * Unignore plugin or theme.
907 - *
908 - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::unignore_plugin_theme()
909 - */
910 - public function mainwp_unignoreplugintheme() {
911 - $this->secure_request( 'mainwp_unignoreplugintheme' );
912 -
913 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
914 - if ( ! isset( $_POST['id'] ) ) {
915 - die( wp_json_encode( array( 'error' => esc_html__( 'Item ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
916 - }
917 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
918 - $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : '';
919 - $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
920 - $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
921 -
922 - // phpcs:enable
923 - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_plugin_theme( $type, $slug, $id, $ver ) ) ) );
924 - }
925 -
926 - /**
927 - * Method mainwp_ignorepluginsthemes()
928 - *
929 - * Ignore plugins or themes.
930 - *
931 - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugins_themes()
932 - */
933 - public function mainwp_ignorepluginsthemes() {
934 - $this->secure_request( 'mainwp_ignorepluginsthemes' );
935 -
936 - if ( ! \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) {
937 - die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'ignore/unignore updates', 'mainwp' ) ) ) ) );
938 - }
939 -
940 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
941 - if ( ! isset( $_POST['slug'] ) ) {
942 - die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
943 - }
944 -
945 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
946 - $slug = isset( $_POST['slug'] ) ? esc_html( wp_unslash( $_POST['slug'] ) ) : '';
947 - $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
948 - $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
949 -
950 - // phpcs:enable
951 - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::ignore_plugins_themes( $type, $slug, $name, $ver ) ) ) );
952 - }
953 -
954 - /**
955 - * Method ajax_ignore_core_updates()
956 - *
957 - * Ignore plugins or themes.
958 - *
959 - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::ignore_plugins_themes()
960 - */
961 - public function ajax_ignore_core_updates() { //phpcs:ignore -- NOSONAR complex function.
962 -
963 - $this->secure_request( 'mainwp_updates_ignore_upgrades' );
964 -
965 - if ( ! \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) {
966 - die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'ignore/unignore updates', 'mainwp' ) ) ) ) );
967 - }
968 -
969 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
970 - if ( empty( $_POST['slug'] ) ) {
971 - die( wp_json_encode( array( 'error' => esc_html__( 'Item slug not found. Please reload the page and try again.', 'mainwp' ) ) ) );
972 - }
973 -
974 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
975 - $ignore = isset( $_POST['ignore'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore'] ) ) : '';
976 - $site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : 0;
977 - $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
978 -
979 - if ( 'wp' === $type ) {
980 - if ( ( 'this_version' === $ignore || 'all_versions' === $ignore ) && $site_id ) {
981 - $website = MainWP_DB::instance()->get_website_by_id( $site_id, false, array( 'ignored_wp_upgrades' ) );
982 -
983 - if ( empty( $website ) ) {
984 - wp_send_json( array( 'error' => esc_html__( 'Site ID invalid or site not found. Please try again.', 'mainwp' ) ) );
985 - }
986 -
987 - $ignored_upgrades = ! empty( $website->ignored_wp_upgrades ) ? json_decode( $website->ignored_wp_upgrades, true ) : array();
988 -
989 - if ( ! is_array( $ignored_upgrades ) ) {
990 - $ignored_upgrades = array();
991 - }
992 -
993 - $ignored_vers = is_array( $ignored_upgrades ) && isset( $ignored_upgrades['ignored_versions'] ) ? $ignored_upgrades['ignored_versions'] : array();
994 - if ( ! is_array( $ignored_vers ) ) {
995 - $ignored_vers = array();
996 - }
997 -
998 - if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all.
999 - $ignored_vers = array( 'all_versions' );
1000 - } else {
1001 - $ver = urldecode( $ver );
1002 - if ( ! in_array( $ver, $ignored_vers ) ) {
1003 - $ignored_vers[] = $ver;
1004 - }
1005 - }
1006 -
1007 - $ignored_upgrades['ignored_versions'] = $ignored_vers;
1008 -
1009 - MainWP_DB::instance()->update_website_option(
1010 - $site_id,
1011 - 'ignored_wp_upgrades',
1012 - wp_json_encode( $ignored_upgrades )
1013 - );
1014 -
1015 - wp_send_json( array( 'success' => 1 ) );
1016 -
1017 - } elseif ( 'this_version_global' === $ignore ) {
1018 -
1019 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1020 - $decodedIgnoredCores = ! empty( $userExtension->ignored_wp_upgrades ) ? json_decode( $userExtension->ignored_wp_upgrades, true ) : array();
1021 -
1022 - if ( ! is_array( $decodedIgnoredCores ) ) {
1023 - $decodedIgnoredCores = array();
1024 - }
1025 -
1026 - $ignored_vers = isset( $decodedIgnoredCores['ignored_versions'] ) ? $decodedIgnoredCores['ignored_versions'] : array();
1027 -
1028 - if ( ! is_array( $ignored_vers ) ) {
1029 - $ignored_vers = array();
1030 - }
1031 -
1032 - $ver = urldecode( $ver );
1033 - if ( ! in_array( $ver, $ignored_vers ) ) {
1034 - $ignored_vers[] = $ver;
1035 - }
1036 -
1037 - $decodedIgnoredCores['ignored_versions'] = $ignored_vers;
1038 -
1039 - MainWP_DB_Common::instance()->update_user_extension(
1040 - array(
1041 - 'userid' => null,
1042 - 'ignored_wp_upgrades' => wp_json_encode( $decodedIgnoredCores ),
1043 - )
1044 - );
1045 - wp_send_json( array( 'success' => 1 ) );
1046 - }
1047 - }
1048 - wp_send_json( array( 'error' => esc_html__( 'Invalid types. Please try again.', 'mainwp' ) ) );
1049 - }
1050 -
1051 - /**
1052 - * Method ajax_unignore_core_updates()
1053 - *
1054 - * Unignore plugin or theme.
1055 - */
1056 - public function ajax_unignore_core_updates() {
1057 - $this->secure_request( 'mainwp_updates_unignore_upgrades' );
1058 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1059 - $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : ''; // numberic id or _ALL_.
1060 - $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
1061 - // phpcs:enable
1062 - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_core_updates( $id, $ver ) ) ) );
1063 - }
1064 -
1065 -
1066 - /**
1067 - * Method ajax_unignore_global_upgrades()
1068 - *
1069 - * Unignore plugin or theme.
1070 - */
1071 - public function ajax_unignore_global_upgrades() {
1072 - $this->secure_request( 'mainwp_updates_unignore_global_upgrades' );
1073 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1074 - $slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : '';
1075 - $ver = isset( $_POST['ignore_ver'] ) ? sanitize_text_field( wp_unslash( $_POST['ignore_ver'] ) ) : '';
1076 - // phpcs:enable
1077 - die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::unignore_global_cores( $slug, $ver ) ) ) );
1078 - }
1079 -
1080 -
1081 - /**
1082 - * Method mainwp_trust_plugin()
1083 - *
1084 - * Trust plugin.
1085 - *
1086 - * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_post()
1087 - * @uses \MainWP\Dashboard\MainWP_Themes_Handler::trust_post()
1088 - */
1089 - public function mainwp_trust_plugin() {
1090 - $this->secure_request( 'mainwp_trust_plugin' );
1091 -
1092 - MainWP_Plugins_Handler::trust_post();
1093 - die( wp_json_encode( array( 'result' => true ) ) );
1094 - }
1095 -
1096 - /**
1097 - * Method mainwp_trust_theme()
1098 - *
1099 - * Trust theme.
1100 - */
1101 - public function mainwp_trust_theme() {
1102 - $this->secure_request( 'mainwp_trust_theme' );
1103 -
1104 - MainWP_Themes_Handler::trust_post();
1105 - die( wp_json_encode( array( 'result' => true ) ) );
1106 - }
1107 797 }