-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwpum-delete-account.php
226 lines (192 loc) · 5.11 KB
/
wpum-delete-account.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
/*
Plugin Name: WPUM Delete Account
Plugin URI: https://wpusermanager.com
Description: Allows the user to delete their own profile from the frontend account page. This is an addon for WP User Manager.
Version: 1.0.2
Author: WP User Manager
Author URI: https://wpusermanager.com/
License: GPLv3+
Text Domain: wpum-delete-account
Domain Path: /languages
*/
/**
* WPUM Delete Account.
*
* Copyright (c) 2018 Alessandro Tesoro
*
* WPUM Delete Account. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* WPUM Delete Account. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* @author Alessandro Tesoro
* @version 2.0.0
* @copyright (c) 2018 Alessandro Tesoro
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU LESSER GENERAL PUBLIC LICENSE
* @package wpum-delete-account
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WPUM_Delete_Account' ) ) :
/**
* Main WPUM_Delete_Account class.
*/
final class WPUM_Delete_Account {
/**
* WPUMDA Instance.
*
* @var WPUM_Delete_Account the WPUM Instance
*/
protected static $_instance;
/**
* @var string
*/
protected $version = '1.0.2';
/**
* Main WPUMDA Instance.
*
* Ensures that only one instance of WPUMDA exists in memory at any one
* time. Also prevents needing to define globals all over the place.
*
* @return WPUM_Delete_Account
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
self::$_instance->run();
}
return self::$_instance;
}
/**
* Only load the addon on the WPUM core hook, ensuring the plugin is active.
*/
public function run() {
add_action( 'after_wpum_init', array( $this, 'init' ) );
}
/**
* Get things up and running.
*/
public function init() {
if ( ! $this->autoload() ) {
return;
}
// Verify the plugin meets WP and PHP requirements.
if ( ! $this->plugin_can_run() ) {
return;
}
// Plugin is activated now proceed.
$this->setup_constants();
$this->includes();
$this->init_hooks();
}
/**
* Autoload composer and other required classes.
*
* @return bool
*/
protected function autoload() {
if ( ! file_exists( __DIR__ . '/vendor' ) || ! file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
add_action( 'admin_notices', array( $this, 'vendor_failed_notice' ) );
return false;
}
return require __DIR__ . '/vendor/autoload.php';
}
/**
* Load required files for the addon.
*
* @return void
*/
public function includes() {
require_once WPUMDA_PLUGIN_DIR . 'includes/settings.php';
require_once WPUMDA_PLUGIN_DIR . 'includes/actions.php';
}
/**
* Setup plugin constants
*
* @access private
* @since 1.0.0
* @return void
*/
private function setup_constants() {
// Plugin version.
if ( ! defined( 'WPUMDA_VERSION' ) ) {
define( 'WPUMDA_VERSION', $this->version );
}
// Plugin Folder Path.
if ( ! defined( 'WPUMDA_PLUGIN_DIR' ) ) {
define( 'WPUMDA_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
// Plugin Folder URL.
if ( ! defined( 'WPUMDA_PLUGIN_URL' ) ) {
define( 'WPUMDA_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
// Plugin Root File.
if ( ! defined( 'WPUMDA_PLUGIN_FILE' ) ) {
define( 'WPUMDA_PLUGIN_FILE', __FILE__ );
}
// Plugin Slug.
if ( ! defined( 'WPUMDA_SLUG' ) ) {
define( 'WPUMDA_SLUG', plugin_basename( __FILE__ ) );
}
}
/**
* Hook in our actions and filters.
*
* @return void
*/
private function init_hooks() {
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ), 0 );
}
/**
* Load plugin textdomain.
*
* @return void
*/
public function load_textdomain() {
load_plugin_textdomain( 'wpum-delete-account', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
/**
* Verify that the current environment is supported.
*
* @return bool
*/
private function plugin_can_run() {
$requirements_check = new WPUM_Extension_Activation( array(
'title' => 'WPUM Delete Account',
'wpum_version' => '2.0.0',
'file' => __FILE__,
) );
return $requirements_check->passes();
}
/**
* Show the Vendor build issue notice.
*
* @since 1.0.0
* @access public
*/
public function vendor_failed_notice() { ?>
<div class="error">
<p><?php printf( '<strong>WP User Manager</strong> — The %s addon plugin cannot be activated as it is missing the vendor directory.', esc_html( 'Delete Account' ) ); ?></p>
</div>
<?php
deactivate_plugins( plugin_basename( __FILE__ ) );
}
}
endif;
/**
* Start the addon.
*
* @return WPUM_Delete_Account
*/
function WPUMDA() {
return WPUM_Delete_Account::instance();
}
WPUMDA();