| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dev4Press\Plugin\SweepPress\Admin; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
class PostBack extends \Dev4Press\v49\Core\Admin\PostBack { |
| 10 |
protected function process() { |
| 11 |
parent::process(); |
| 12 |
|
| 13 |
do_action( 'sweeppress_admin_postback_handler', $this->p() ); |
| 14 |
} |
| 15 |
|
| 16 |
protected function tools() { |
| 17 |
parent::tools(); |
| 18 |
|
| 19 |
if ( $this->a()->subpanel == 'purge' ) { |
| 20 |
$this->purge(); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
protected function remove() { |
| 25 |
$data = isset( $_POST['sweeppress-tools'] ) ? sweeppress_sanitize_keys_based_array( $_POST['sweeppress-tools'] ) : array(); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput |
| 26 |
|
| 27 |
$remove = isset( $data['remove'] ) ? (array) $data['remove'] : array(); |
| 28 |
$message = 'nothing-removed'; |
| 29 |
|
| 30 |
if ( ! empty( $remove ) ) { |
| 31 |
$groups = array( 'settings', 'sweepers', 'statistics', 'scheduler', 'cache', 'storage' ); |
| 32 |
|
| 33 |
foreach ( $groups as $group ) { |
| 34 |
if ( isset( $remove[ $group ] ) && $remove[ $group ] == 'on' ) { |
| 35 |
$this->a()->settings()->remove_plugin_settings_by_group( $group ); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
if ( isset( $remove['disable'] ) && $remove['disable'] == 'on' ) { |
| 40 |
if ( isset( $remove['settings'] ) && $remove['settings'] == 'on' ) { |
| 41 |
$this->a()->settings()->remove_plugin_settings_by_group( 'core' ); |
| 42 |
} |
| 43 |
|
| 44 |
sweeppress()->deactivate(); |
| 45 |
|
| 46 |
wp_redirect( admin_url( 'plugins.php' ) ); |
| 47 |
exit; |
| 48 |
} |
| 49 |
|
| 50 |
$message = 'removed'; |
| 51 |
} |
| 52 |
|
| 53 |
wp_redirect( $this->a()->current_url() . '&message=' . $message ); |
| 54 |
exit; |
| 55 |
} |
| 56 |
|
| 57 |
private function purge() { |
| 58 |
$data = isset( $_POST['sweeppress-tools'] ) ? sweeppress_sanitize_keys_based_array( $_POST['sweeppress-tools'] ) : array(); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput |
| 59 |
|
| 60 |
$remove = isset( $data['purge'] ) ? (array) $data['purge'] : array(); |
| 61 |
$message = empty( $remove ) ? 'nothing-removed' : 'removed';; |
| 62 |
|
| 63 |
if ( isset( $remove['cache'] ) ) { |
| 64 |
if ( isset( $remove['cache']['sweepers'] ) && $remove['cache']['sweepers'] == 'on' ) { |
| 65 |
sweeppress_settings()->purge_sweeper_cache(); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
if ( isset( $remove['storage'] ) ) { |
| 70 |
$settings = array( |
| 71 |
'scan_plugins', |
| 72 |
'scan_themes', |
| 73 |
); |
| 74 |
|
| 75 |
foreach ( $settings as $option ) { |
| 76 |
if ( isset( $remove['storage'][ $option ] ) && $remove['storage'][ $option ] == 'on' ) { |
| 77 |
$this->a()->settings()->set( $option, array(), 'storage' ); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
$this->a()->settings()->save( 'storage' ); |
| 82 |
} |
| 83 |
|
| 84 |
wp_redirect( $this->a()->current_url() . '&message=' . $message ); |
| 85 |
exit; |
| 86 |
} |
| 87 |
} |
| 88 |
|