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

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

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