71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Gravity_Forms\Gravity_SMTP\Connectors\Endpoints;
|
|
|
|
use Gravity_Forms\Gravity_Tools\Endpoints\Endpoint;
|
|
use Gravity_Forms\Gravity_SMTP\Users\Roles;
|
|
|
|
class Cleanup_Data_Endpoint extends Endpoint {
|
|
|
|
const PARAM_TARGET = 'target';
|
|
|
|
const ACTION_NAME = 'cleanup_data';
|
|
|
|
protected $minimum_cap = Roles::EDIT_INTEGRATIONS;
|
|
|
|
/**
|
|
* @var Plugin_Opts_Data_Store;
|
|
*/
|
|
protected $data_store;
|
|
|
|
public function __construct( $data_store ) {
|
|
$this->data_store = $data_store;
|
|
}
|
|
|
|
protected function get_nonce_name() {
|
|
return self::ACTION_NAME;
|
|
}
|
|
|
|
private function reset_setup_wizard_data() {
|
|
$this->data_store->save( Save_Plugin_Settings_Endpoint::PARAM_SETUP_WIZARD_SHOULD_DISPLAY, 'true' );
|
|
$this->data_store->save( Save_Plugin_Settings_Endpoint::PARAM_LICENSE_KEY, '' );
|
|
update_option( 'gravitysmtp_generic', '' );
|
|
update_option( 'gravitysmtp_mailgun', '' );
|
|
update_option( 'gravitysmtp_postmark', '' );
|
|
update_option( 'gravitysmtp_sendgrid', '' );
|
|
|
|
wp_send_json_success( __( 'Setup wizard data reset.', 'gravitysmtp' ) );
|
|
}
|
|
|
|
public function handle() {
|
|
if ( ! $this->validate() ) {
|
|
wp_send_json_error( __( 'Missing required parameters.', 'gravitysmtp' ), 400 );
|
|
}
|
|
|
|
$target = filter_input( INPUT_POST, self::PARAM_TARGET );
|
|
$target = htmlspecialchars( $target );
|
|
|
|
// handle data clean up or resets here
|
|
|
|
switch( $target ) {
|
|
case 'setup_wizard':
|
|
$this->reset_setup_wizard_data();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
protected function validate() {
|
|
if ( ! parent::validate() ) {
|
|
return false;
|
|
}
|
|
|
|
if ( empty( $_REQUEST[ self::PARAM_TARGET ] ) ) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|