initial
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_SMTP\Environment;
|
||||
|
||||
class Environment_Details {
|
||||
|
||||
public function get_min() {
|
||||
return defined( 'GRAVITYSMTP_SCRIPT_DEBUG' ) && GRAVITYSMTP_SCRIPT_DEBUG ? '' : '.min';
|
||||
}
|
||||
|
||||
public function get_version() {
|
||||
return defined( 'GRAVITYSMTP_SCRIPT_DEBUG' ) && GRAVITYSMTP_SCRIPT_DEBUG ? time() : time();
|
||||
}
|
||||
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_SMTP\Environment;
|
||||
|
||||
use Gravity_Forms\Gravity_SMTP\Environment\Config\Environment_Endpoints_Config;
|
||||
use Gravity_Forms\Gravity_SMTP\Environment\Endpoints\Uninstall_Endpoint;
|
||||
use Gravity_Forms\Gravity_Tools\Service_Container;
|
||||
use Gravity_Forms\Gravity_Tools\Providers\Config_Service_Provider;
|
||||
|
||||
class Environment_Service_Provider extends Config_Service_Provider {
|
||||
|
||||
const UNINSTALL_ENDPOINT = 'uninstall_endpoint';
|
||||
const ENVIRONMENT_ENDPOINTS_CONFIG = 'environment_endpoints_config';
|
||||
|
||||
protected $configs = array(
|
||||
self::ENVIRONMENT_ENDPOINTS_CONFIG => Environment_Endpoints_Config::class,
|
||||
);
|
||||
|
||||
public function register( Service_Container $container ) {
|
||||
parent::register( $container );
|
||||
|
||||
$container->add( self::UNINSTALL_ENDPOINT, function() {
|
||||
return new Uninstall_Endpoint();
|
||||
} );
|
||||
}
|
||||
|
||||
public function init( Service_Container $container ) {
|
||||
add_action( 'wp_ajax_' . Uninstall_Endpoint::ACTION_NAME, function() use ( $container ) {
|
||||
$container->get( self::UNINSTALL_ENDPOINT )->handle();
|
||||
} );
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_SMTP\Environment\Config;
|
||||
|
||||
use Gravity_Forms\Gravity_SMTP\Environment\Endpoints\Uninstall_Endpoint;
|
||||
use Gravity_Forms\Gravity_Tools\Config;
|
||||
|
||||
class Environment_Endpoints_Config extends Config {
|
||||
|
||||
protected $script_to_localize = 'gravitysmtp_scripts_admin';
|
||||
protected $name = 'gravitysmtp_admin_config';
|
||||
|
||||
public function should_enqueue() {
|
||||
return is_admin();
|
||||
}
|
||||
|
||||
public function data() {
|
||||
return array(
|
||||
'common' => array(
|
||||
'endpoints' => array(
|
||||
Uninstall_Endpoint::ACTION_NAME => array(
|
||||
'action' => array(
|
||||
'value' => Uninstall_Endpoint::ACTION_NAME,
|
||||
'default' => 'mock_endpoint',
|
||||
),
|
||||
'nonce' => array(
|
||||
'value' => wp_create_nonce( Uninstall_Endpoint::ACTION_NAME ),
|
||||
'default' => 'nonce',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_SMTP\Environment\Endpoints;
|
||||
|
||||
use Gravity_Forms\Gravity_SMTP\Users\Roles;
|
||||
use Gravity_Forms\Gravity_Tools\Endpoints\Endpoint;
|
||||
|
||||
class Uninstall_Endpoint extends Endpoint {
|
||||
|
||||
const ACTION_NAME = 'gravitysmtp_uninstall_plugin';
|
||||
|
||||
protected $minimum_cap = Roles::EDIT_UNINSTALL;
|
||||
|
||||
public function handle() {
|
||||
if ( ! current_user_can( Roles::EDIT_UNINSTALL ) ) {
|
||||
wp_send_json_error( __( 'You do not have permission to perform this action.', 'gravitysmtp' ), 403 );
|
||||
}
|
||||
|
||||
if ( ! $this->validate() ) {
|
||||
wp_send_json_error( __( 'Missing required parameters.', 'gravitysmtp' ), 400 );
|
||||
}
|
||||
|
||||
$this->delete_options();
|
||||
$this->delete_tables();
|
||||
$this->deactivate_plugin();
|
||||
|
||||
wp_send_json_success( __( 'Gravity SMTP successfully uninstalled.', 'gravitysmtp' ) );
|
||||
}
|
||||
|
||||
public function get_nonce_name() {
|
||||
return self::ACTION_NAME;
|
||||
}
|
||||
|
||||
private function delete_options() {
|
||||
global $wpdb;
|
||||
$query = $wpdb->prepare( "DELETE FROM {$wpdb->prefix}options WHERE option_name LIKE '%%%s%%'", 'gravitysmtp_' );
|
||||
$wpdb->query( $query );
|
||||
|
||||
$query = $wpdb->prepare( "DELETE FROM {$wpdb->prefix}options WHERE option_name LIKE '%%%s%%'", 'gsmtp_' );
|
||||
$wpdb->query( $query );
|
||||
}
|
||||
|
||||
private function delete_tables() {
|
||||
global $wpdb;
|
||||
$query = "DROP TABLE IF EXISTS {$wpdb->prefix}gravitysmtp_events, {$wpdb->prefix}gravitysmtp_event_logs";
|
||||
$wpdb->query( $query );
|
||||
}
|
||||
|
||||
private function deactivate_plugin() {
|
||||
deactivate_plugins( '/gravitysmtp/gravitysmtp.php' );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user