-
Notifications
You must be signed in to change notification settings - Fork 146
/
wpuf.php
399 lines (347 loc) · 11 KB
/
wpuf.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
<?php
/*
Plugin Name: WP User Frontend
Plugin URI: https://wordpress.org/plugins/wp-user-frontend/
Description: Create, edit, delete, manages your post, pages or custom post types from frontend. Create registration forms, frontend profile and more...
Author: weDevs
Version: 4.0.12
Author URI: https://wedevs.com/?utm_source=WPUF_Author_URI
License: GPL2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: wp-user-frontend
Domain Path: /languages
*/
// don't call the file directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$autoload = __DIR__ . '/vendor/autoload.php';
if ( file_exists( $autoload ) ) {
require_once $autoload;
}
define( 'WPUF_VERSION', '4.0.12' );
define( 'WPUF_FILE', __FILE__ );
define( 'WPUF_ROOT', __DIR__ );
define( 'WPUF_ROOT_URI', plugins_url( '', __FILE__ ) );
define( 'WPUF_ASSET_URI', WPUF_ROOT_URI . '/assets' );
define( 'WPUF_INCLUDES', WPUF_ROOT . '/includes' );
use WeDevs\WpUtils\SingletonTrait;
/**
* Main bootstrap class for WP User Frontend
*/
final class WP_User_Frontend {
use SingletonTrait;
/**
* Form field value seperator
*
* @var string
*/
public static $field_separator = '| ';
/**
* Pro plugin checkup
*
* @var bool
*/
private $is_pro = false;
/**
* Minimum PHP version required
*
* @var string
*/
private $min_php = '5.6';
/**
* Holds various class instances
*
* @since 4.0.9
*
* @var array
*/
public $container = [];
/**
* Fire up the plugin
*/
public function __construct() {
if ( ! $this->is_supported_php() ) {
add_action( 'admin_notices', [ $this, 'php_version_notice' ] );
return;
}
register_activation_hook( __FILE__, [ $this, 'install' ] );
register_deactivation_hook( __FILE__, [ $this, 'uninstall' ] );
$this->includes();
$this->init_hooks();
// Insight class instantiate
$this->container['tracker'] = new WeDevs\Wpuf\Lib\WeDevs_Insights( __FILE__ );
do_action( 'wpuf_loaded' );
}
/**
* Check if the PHP version is supported
*
* @return bool
*/
public function is_supported_php( $min_php = null ) {
$min_php = $min_php ? $min_php : $this->min_php;
if ( version_compare( PHP_VERSION, $min_php, '<=' ) ) {
return false;
}
return true;
}
/**
* Show notice about PHP version
*
* @return void
*/
public function php_version_notice() {
if ( $this->is_supported_php() || ! current_user_can( 'manage_options' ) ) {
return;
}
$error = __( 'Your installed PHP Version is: ', 'wp-user-frontend' ) . PHP_VERSION . '. ';
$error .= __( 'The <strong>WP User Frontend</strong> plugin requires PHP version <strong>', 'wp-user-frontend' ) . $this->min_php . __( '</strong> or greater.', 'wp-user-frontend' ); ?>
<div class="error">
<p><?php printf( esc_html( $error ) ); ?></p>
</div>
<?php
}
/**
* Initialize the hooks
*
* @since 2.5.4
*
* @return void
*/
public function init_hooks() {
add_action( 'plugins_loaded', [ $this, 'wpuf_loader' ] );
add_action( 'plugins_loaded', [ $this, 'process_wpuf_pro_version' ] );
add_action( 'plugins_loaded', [ $this, 'plugin_upgrades' ] );
add_action( 'plugins_loaded', [ $this, 'instantiate' ] );
add_action( 'init', [ $this, 'load_textdomain' ] );
// do plugin upgrades
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), [ $this, 'plugin_action_links' ] );
add_action( 'widgets_init', [ $this, 'register_widgets' ] );
}
/**
* Include the required files
*
* @return void
*/
public function includes() {
require_once __DIR__ . '/wpuf-functions.php';
require_once __DIR__ . '/includes/class-frontend-render-form.php';
// add reCaptcha library if not found
if ( ! function_exists( 'recaptcha_get_html' ) ) {
require_once __DIR__ . '/Lib/recaptchalib.php';
require_once __DIR__ . '/Lib/invisible_recaptcha.php';
}
}
/**
* Instantiate the classes
*
* @return void
*/
public function instantiate() {
$this->container['assets'] = new WeDevs\Wpuf\Assets();
$this->container['subscription'] = new WeDevs\Wpuf\Admin\Subscription();
$this->container['fields'] = new WeDevs\Wpuf\Admin\Forms\Field_Manager();
$this->container['customize'] = new WeDevs\Wpuf\Admin\Customizer_Options();
$this->container['bank'] = new WeDevs\Wpuf\Lib\Gateway\Bank();
$this->container['paypal'] = new WeDevs\Wpuf\Lib\Gateway\Paypal();
$this->container['api'] = new WeDevs\Wpuf\API();
$this->container['integrations'] = new WeDevs\Wpuf\Integrations();
if ( is_admin() ) {
$this->container['admin'] = new WeDevs\Wpuf\Admin();
$this->container['setup_wizard'] = new WeDevs\Wpuf\Setup_Wizard();
$this->container['pro_upgrades'] = new WeDevs\Wpuf\Pro_Upgrades();
$this->container['privacy'] = new WeDevs\Wpuf\WPUF_Privacy();
} else {
$this->container['frontend'] = new WeDevs\Wpuf\Frontend();
}
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
$this->container['ajax'] = new WeDevs\Wpuf\Ajax();
}
}
/**
* Create tables on plugin activation
*
* @global object $wpdb
*/
public function install() {
$installer = new WeDevs\Wpuf\Installer();
$installer->install();
}
/**
* Do plugin upgrades
*
* @since 2.2
*
* @return void
*/
public function plugin_upgrades() {
if ( ! is_admin() && ! current_user_can( 'manage_options' ) ) {
return;
}
$this->container['upgrades'] = new WeDevs\Wpuf\Admin\Upgrades();
}
/**
* Check whether the version of wpuf pro is prior to the code restructure
*
* @since WPUF_FREE
*
* @return void
*/
public function process_wpuf_pro_version() {
// check whether the version of wpuf pro is prior to the code restructure
if ( defined( 'WPUF_PRO_VERSION' ) && version_compare( WPUF_PRO_VERSION, '4', '<' ) ) {
// deactivate_plugins( WPUF_PRO_FILE );
add_action( 'admin_notices', [ $this, 'wpuf_upgrade_notice' ] );
}
}
/**
* Show WordPress error notice if WP User Frontend not found
*
* @since 2.4.2
*/
public function wpuf_upgrade_notice() {
?>
<div class="notice error" id="wpuf-pro-installer-notice" style="padding: 1em; position: relative;">
<h2><?php esc_html_e( 'Your WP User Frontend Pro is almost ready!', 'wp-user-frontend' ); ?></h2>
<p>
<?php
/* translators: 1: opening anchor tag, 2: closing anchor tag. */
echo sprintf( __( 'We\'ve pushed a major update on both <b>WP User Frontend Free</b> and <b>WP User Frontend Pro</b> that requires you to use latest version of both. Please update the WPUF pro to the latest version. <br><strong>Please make sure to take a complete backup of your site before updating.</strong>', 'wp-user-frontend' ), '<a target="_blank" href="https://wordpress.org/plugins/wp-user-frontend/">', '</a>' );
?>
</p>
</div>
<?php
}
/**
* Load wpuf Free class if not pro
*
* @since 2.5.4
*/
public function wpuf_loader() {
$has_pro = class_exists( 'WP_User_Frontend_Pro' );
if ( $has_pro ) {
$this->is_pro = true;
} else {
$this->container['free_loader'] = new WeDevs\Wpuf\Free\Free_Loader();
}
// Remove the what's new option.
delete_option( 'wpuf_whats_new' );
delete_option( 'wpufpro_whats_new' );
}
/**
* Manage task on plugin deactivation
*
* @return void
*/
public static function uninstall() {
wp_clear_scheduled_hook( 'wpuf_remove_expired_post_hook' );
}
/**
* Load the translation file for current language.
*
* @since version 0.7
*
* @author Tareq Hasan
*/
public function load_textdomain() {
load_plugin_textdomain( 'wp-user-frontend', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* The main logging function
*
* @uses error_log
*
* @param string $type type of the error. e.g: debug, error, info
* @param string $msg
*/
public static function log( $type = '', $msg = '' ) {
$msg = sprintf( "[%s][%s] %s\n", date( 'd.m.Y h:i:s' ), $type, $msg );
error_log( $msg, 3, __DIR__ . '/log.txt' );
}
/**
* Returns if the plugin is in PRO version
*
* @since 2.3.2
*
* @return bool
*/
public function is_pro() {
return $this->is_pro;
}
/**
* Plugin action links
*
* @param array $links
*
* @since 2.3.3
*
* @return array
*/
public function plugin_action_links( $links ) {
if ( ! $this->is_pro() ) {
$links[] = '<a href="' . WeDevs\Wpuf\Free\Pro_Prompt::get_pro_url() . '" target="_blank" style="color: red;">Get PRO</a>';
}
$links[] = '<a href="' . admin_url( 'admin.php?page=wpuf-settings' ) . '">Settings</a>';
$links[] = '<a href="https://wedevs.com/docs/wp-user-frontend-pro/getting-started/how-to-install/" target="_blank">Documentation</a>';
return $links;
}
/**
* Register widgets
*
* @since 4.0.0
*
* @return void
*/
public function register_widgets() {
$this->container['widgets'] = new WeDevs\Wpuf\Widgets\Manager();
}
public function license_expired() {
echo '<div class="error">';
echo '<p>Your <strong>WP User Frontend Pro</strong> License has been expired. Please <a href="https://wedevs.com/account/" target="_blank">renew your license</a>.</p>';
echo '</div>';
}
/**
* Get the global field seperator for WPUF
*
* @since 4.0.0
*
* @return string
*/
public function get_field_seperator() {
return self::$field_separator;
}
/**
* Magic getter to bypass referencing objects
*
* @since 4.0.9
*
* @param string $prop
*
* @return object Class Instance
*/
public function __get( $prop ) {
if ( array_key_exists( $prop, $this->container ) ) {
return $this->container[ $prop ];
}
}
/**
* Get the DB version key
*
* @since 4.0.11
*
* @return string
*/
public function get_db_version_key() {
return 'wpuf_version';
}
}
/**
* Returns the singleton instance
*
* @return WP_User_Frontend
*/
function wpuf() {
return WP_User_Frontend::instance();
}
// kickoff
wpuf();