-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpum-recaptcha.php
277 lines (237 loc) · 6.27 KB
/
wpum-recaptcha.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
/*
Plugin Name: WPUM Recaptcha Lite
Plugin URI: https://wpusermanager.com
Description: Addon for WP User Manager, stop spam registrations on your website for free.
Version: 2.0.4
Author: WP User Manager
Author URI: https://wpusermanager.com/
License: GPLv3+
Text Domain: wpum-recaptcha
Domain Path: /languages
*/
/**
* WPUM Recaptcha.
*
* Copyright (c) 2018 Alessandro Tesoro
*
* WPUM Recaptcha. 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 Recaptcha. 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-recaptcha
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WPUM_Recaptcha' ) ) :
/**
* Main WPUM_Recaptcha class.
*/
final class WPUM_Recaptcha {
/**
* WPUMR Instance.
*
* @var WPUM_Recaptcha the WPUM Instance
*/
protected static $_instance;
/**
* Main WPUMR Instance.
*
* Ensures that only one instance of WPUMR exists in memory at any one
* time. Also prevents needing to define globals all over the place.
*
* @return WPUM_Recaptcha
*/
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;
}
// Verify the addon can run first. If not, disable the addon automagically.
if ( ! $this->addon_can_run() ) {
return;
}
if ( $this->pro_addon_enabled() ) {
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';
}
/**
* Is the Pro addon enabled? Don't let them both run at the same time
*
* @return bool
*/
protected function pro_addon_enabled() {
if ( class_exists( 'WPUM_Recaptcha_Pro' ) ) {
add_action( 'admin_notices', array( $this, 'pro_addon_enabled_notice' ) );
return true;
}
return false;
}
/**
* Load required files for the addon.
*
* @return void
*/
public function includes() {
require_once WPUMR_PLUGIN_DIR . 'includes/settings.php';
require_once WPUMR_PLUGIN_DIR . 'includes/actions.php';
require_once WPUMR_PLUGIN_DIR . 'includes/ReCaptcha/RequestMethod/WPPost.php';
}
/**
* Setup plugin constants
*
* @access private
* @since 1.0.0
* @return void
*/
private function setup_constants() {
// Plugin version.
if ( ! defined( 'WPUMR_VERSION' ) ) {
define( 'WPUMR_VERSION', '2.0.4' );
}
// Plugin Folder Path.
if ( ! defined( 'WPUMR_PLUGIN_DIR' ) ) {
define( 'WPUMR_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
// Plugin Folder URL.
if ( ! defined( 'WPUMR_PLUGIN_URL' ) ) {
define( 'WPUMR_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
// Plugin Root File.
if ( ! defined( 'WPUMR_PLUGIN_FILE' ) ) {
define( 'WPUMR_PLUGIN_FILE', __FILE__ );
}
// Plugin Slug.
if ( ! defined( 'WPUMR_SLUG' ) ) {
define( 'WPUMR_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-recaptcha', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
/**
* Verify the plugin meets the WP and php requirements.
*
* @return boolean
*/
public function plugin_can_run() {
$requirements_check = new WP_Requirements_Check( array(
'title' => 'WPUM Recaptcha Lite',
'php' => '5.5',
'wp' => '4.7',
'file' => __FILE__,
) );
return $requirements_check->passes();
}
/**
* Verify that the current environment is supported.
*
* @return boolean
*/
private function addon_can_run() {
$requirements_check = new WPUM_Extension_Activation(
array(
'title' => 'WPUM Recaptcha Lite',
'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( 'Recaptcha' ) ); ?></p>
</div>
<?php
deactivate_plugins( plugin_basename( __FILE__ ) );
}
/**
* Show the Pro addon notice.
*
* @since 1.0.0
* @access public
*/
public function pro_addon_enabled_notice() { ?>
<div class="notice notice-warning">
<p><?php printf( '<strong>WP User Manager</strong> — The %s addon has been deactivated as the premium addon replaces it.', esc_html( 'Recaptcha' ) ); ?></p>
</div>
<?php
deactivate_plugins( plugin_basename( __FILE__ ) );
}
}
endif;
/**
* Start the addon.
*
* @return object
*/
function WPUMR() {
return WPUM_Recaptcha::instance();
}
WPUMR();