PluginProbe
User Registration & Membership – Free & Paid Memberships, Subscriptions, Content Restriction, User Profile, Custom User Registration & Login Builder / 3.0.3
User Registration & Membership – Free & Paid Memberships, Subscriptions, Content Restriction, User Profile, Custom User Registration & Login Builder v3.0.3
5.2.7 5.2.6 5.2.5 5.2.4 5.2.3 5.2.2 5.2.1 5.2.0 3.0 3.0.1 3.0.2 3.0.2.1 3.0.3 3.0.4 3.0.4.1 3.0.4.2 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.2.0 3.2.0.1 3.2.1 All 192 releases
user-registration / user-registration.php

user-registration.php in User Registration & Membership – Free & Paid Memberships, Subscriptions, Content Restriction, User Profile, Custom User Registration & Login Builder 3.0.3, at user-registration.php

486 lines 14.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php //phpcs:ignore
2 /**
3 * Plugin Name: User Registration
4 * Plugin URI: https://wpuserregistration.com/
5 * Description: Drag and Drop user registration form and login form builder.
6 * Version: 3.0.3
7 * Author: WPEverest
8 * Author URI: https://wpeverest.com
9 * Text Domain: user-registration
10 * Domain Path: /languages/
11 *
12 * @package UserRegistration
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 if ( ! class_exists( 'UserRegistration' ) ) :
20
21 /**
22 * Main UserRegistration Class.
23 *
24 * @class UserRegistration
25 * @version 1.0.0
26 */
27 final class UserRegistration {
28
29 /**
30 * Plugin version.
31 *
32 * @var string
33 */
34 public $version = '3.0.3';
35
36 /**
37 * Session instance.
38 *
39 * @var UR_Session|UR_Session_Handler
40 */
41 public $session = null;
42
43 /**
44 * Query instance.
45 *
46 * @var UR_Query
47 */
48 public $query = null;
49
50 /**
51 * Instance of this class.
52 *
53 * @var object
54 */
55 protected static $_instance = null;
56
57 /**
58 * Return an instance of this class.
59 *
60 * @return object A single instance of this class.
61 */
62 public static function instance() {
63 // If the single instance hasn't been set, set it now.
64 if ( is_null( self::$_instance ) ) {
65 self::$_instance = new self();
66 }
67
68 return self::$_instance;
69 }
70
71 /**
72 * Cloning is forbidden.
73 *
74 * @since 1.0
75 */
76 public function __clone() {
77 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'user-registration' ), '1.0' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
78 }
79
80 /**
81 * Unserializing instances of this class is forbidden.
82 *
83 * @since 1.0
84 */
85 public function __wakeup() {
86 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'user-registration' ), '1.0' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
87 }
88
89 /**
90 * UserRegistration Constructor.
91 */
92 public function __construct() {
93 $this->define_constants();
94 $this->includes();
95 $this->init_hooks();
96 add_action( 'plugins_loaded', array( $this, 'objects' ), 1 );
97
98 do_action( 'user_registration_loaded' );
99 }
100
101 /**
102 * Hook into actions and filters.
103 */
104 private function init_hooks() {
105 register_activation_hook( __FILE__, array( 'UR_Install', 'install' ) );
106 add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 );
107 add_action( 'init', array( $this, 'init' ), 0 );
108 add_action( 'init', array( 'UR_Shortcodes', 'init' ) );
109
110 add_filter( 'plugin_action_links_' . UR_PLUGIN_BASENAME, array( __CLASS__, 'plugin_action_links' ) );
111 add_filter( 'plugin_row_meta', array( __CLASS__, 'plugin_row_meta' ), 10, 2 );
112 }
113
114 /**
115 * Define FT Constants.
116 */
117 private function define_constants() {
118 $upload_dir = apply_filters( 'user_registration_upload_dir', wp_upload_dir() );
119 $this->define( 'UR_LOG_DIR', $upload_dir['basedir'] . '/ur-logs/' );
120 $this->define( 'UR_UPLOAD_PATH', $upload_dir['basedir'] . '/user_registration_uploads/' );
121 $this->define( 'UR_UPLOAD_URL', $upload_dir['baseurl'] . '/user_registration_uploads/' );
122 $this->define( 'UR_DS', DIRECTORY_SEPARATOR );
123 $this->define( 'UR_PLUGIN_FILE', __FILE__ );
124 $this->define( 'UR_ABSPATH', dirname( __FILE__ ) . UR_DS );
125 $this->define( 'UR_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
126 $this->define( 'UR_VERSION', $this->version );
127 $this->define( 'UR_TEMPLATE_DEBUG_MODE', false );
128 $this->define( 'UR_FORM_PATH', UR_ABSPATH . 'includes' . UR_DS . 'form' . UR_DS );
129 $this->define( 'UR_SESSION_CACHE_GROUP', 'ur_session_id' );
130 }
131
132 /**
133 * Define constant if not already set.
134 *
135 * @param string $name Name.
136 * @param string|bool $value Value.
137 */
138 private function define( $name, $value ) {
139 if ( ! defined( $name ) ) {
140 define( $name, $value );
141 }
142 }
143
144 /**
145 * What type of request is this?
146 *
147 * @param string $type admin, ajax, cron or frontend.
148 * @return bool
149 */
150 private function is_request( $type ) {
151 switch ( $type ) {
152 case 'admin':
153 return is_admin();
154 case 'ajax':
155 return defined( 'DOING_AJAX' );
156 case 'cron':
157 return defined( 'DOING_CRON' );
158 case 'frontend':
159 return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
160 }
161 }
162
163 /**
164 * Includes.
165 */
166 private function includes() {
167
168 /**
169 * Class autoloader.
170 */
171 include_once UR_ABSPATH . 'includes/class-ur-autoloader.php';
172
173 /**
174 * Interfaces.
175 */
176 include_once UR_ABSPATH . 'includes/interfaces/class-ur-logger-interface.php';
177 include_once UR_ABSPATH . 'includes/interfaces/class-ur-log-handler-interface.php';
178
179 /**
180 * Abstract classes
181 */
182 include_once UR_ABSPATH . 'includes/abstracts/abstract-ur-form-field.php';
183 include_once UR_ABSPATH . 'includes/abstracts/abstract-ur-field-settings.php';
184 include_once UR_ABSPATH . 'includes/abstracts/abstract-ur-log-handler.php';
185 include_once UR_ABSPATH . 'includes/abstracts/abstract-ur-session.php';
186
187 /**
188 * Core classes.
189 */
190 include_once UR_ABSPATH . 'includes/functions-ur-core.php';
191 include_once UR_ABSPATH . 'includes/class-ur-install.php';
192 include_once UR_ABSPATH . 'includes/class-ur-post-types.php'; // Registers post types.
193 include_once UR_ABSPATH . 'includes/class-ur-user-approval.php';
194 include_once UR_ABSPATH . 'includes/class-ur-smart-tags.php'; // User Approval class.
195 include_once UR_ABSPATH . 'includes/class-ur-emailer.php';
196 include_once UR_ABSPATH . 'includes/class-ur-ajax.php';
197 include_once UR_ABSPATH . 'includes/class-ur-query.php';
198 include_once UR_ABSPATH . 'includes/class-ur-email-confirmation.php';
199 include_once UR_ABSPATH . 'includes/class-ur-email-approval.php';
200 include_once UR_ABSPATH . 'includes/class-ur-privacy.php';
201 include_once UR_ABSPATH . 'includes/class-ur-form-block.php';
202 include_once UR_ABSPATH . 'includes/class-ur-cache-helper.php';
203
204 // Validation classes.
205 include_once UR_ABSPATH . 'includes/validation/class-ur-validation.php';
206 include_once UR_ABSPATH . 'includes/validation/class-ur-form-validation.php';
207 include_once UR_ABSPATH . 'includes/validation/class-ur-setting-validation.php';
208
209 include_once UR_ABSPATH . 'includes/RestApi/class-ur-rest-api.php';
210
211 /**
212 * Config classes.
213 */
214 include_once UR_ABSPATH . 'includes/admin/class-ur-config.php';
215
216 /**
217 * Plugin/Addon Updater.
218 */
219 include_once UR_ABSPATH . 'includes/class-ur-plugin-updater.php';
220
221 if ( $this->is_request( 'admin' ) ) {
222 include_once UR_ABSPATH . 'includes/admin/class-ur-admin.php';
223 include_once UR_ABSPATH . 'includes/abstracts/abstract-ur-meta-boxes.php';
224 }
225
226 if ( $this->is_request( 'frontend' ) ) {
227 $this->frontend_includes();
228 }
229
230 if ( $this->is_request( 'frontend' ) || $this->is_request( 'cron' ) ) {
231 include_once UR_ABSPATH . 'includes/class-ur-session-handler.php';
232 }
233 include_once UR_ABSPATH . 'includes/class-ur-cron.php';
234 include_once UR_ABSPATH . 'includes/stats/class-ur-stats.php';
235
236 $this->query = new UR_Query();
237 }
238
239 /**
240 * Include required frontend files.
241 */
242 public function frontend_includes() {
243 include_once UR_ABSPATH . 'includes/functions-ur-notice.php';
244 include_once UR_ABSPATH . 'includes/class-ur-form-handler.php'; // Form Handlers.
245 include_once UR_ABSPATH . 'includes/class-ur-frontend-scripts.php'; // Frontend Scripts.
246 include_once UR_ABSPATH . 'includes/frontend/class-ur-frontend.php';
247 include_once UR_ABSPATH . 'includes/class-ur-preview.php';
248 }
249
250 /**
251 * Function used to Init UserRegistration Template Functions - This makes them pluggable by plugins and themes.
252 */
253 public function include_template_functions() {
254 include_once UR_ABSPATH . 'includes/functions-ur-template.php';
255 }
256
257 /**
258 * Setup Objects.
259 *
260 * @since 1.7.2
261 */
262 public function objects() {
263 $this->form = new UR_Form_Handler();
264 }
265
266 /**
267 * Init UserRegistration when WordPress Initialises.
268 */
269 public function init() {
270 // Before init action.
271 do_action( 'before_user_registration_init' );
272
273 // Set up localisation.
274 $this->load_plugin_textdomain();
275
276 // Session class, handles session data for users - can be overwritten if custom handler is needed.
277 if ( $this->is_request( 'frontend' ) || $this->is_request( 'cron' ) || $this->is_request( 'admin' ) ) {
278 $session_class = apply_filters( 'user_registration_session_handler', 'UR_Session_Handler' );
279 $this->session = new $session_class();
280 }
281
282 // Init action.
283 do_action( 'user_registration_init' );
284 }
285
286 /**
287 * Load Localisation files.
288 *
289 * Note: the first-loaded translation file overrides any following ones if the same translation is present.
290 *
291 * Locales found in:
292 * - WP_LANG_DIR/user-registration/user-registration-LOCALE.mo
293 * - WP_LANG_DIR/plugins/user-registration-LOCALE.mo
294 */
295 public function load_plugin_textdomain() {
296 $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
297 $locale = apply_filters( 'plugin_locale', $locale, 'user-registration' );
298
299 unload_textdomain( 'user-registration' );
300 load_textdomain( 'user-registration', WP_LANG_DIR . '/user-registration/user-registration-' . $locale . '.mo' );
301 load_plugin_textdomain( 'user-registration', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
302 }
303
304 /**
305 * Get the plugin url.
306 *
307 * @return string
308 */
309 public function plugin_url() {
310 return untrailingslashit( plugins_url( '/', __FILE__ ) );
311 }
312
313 /**
314 * Get the plugin path.
315 *
316 * @return string
317 */
318 public function plugin_path() {
319 return untrailingslashit( plugin_dir_path( __FILE__ ) );
320 }
321
322 /**
323 * Get the template path.
324 *
325 * @return string
326 */
327 public function template_path() {
328 return apply_filters( 'user_registration_template_path', 'user-registration/' );
329 }
330
331 /**
332 * Get Ajax URL.
333 *
334 * @return string
335 */
336 public function ajax_url() {
337 return admin_url( 'admin-ajax.php', 'relative' );
338 }
339
340 /**
341 * Display action links in the Plugins list table.
342 *
343 * @param array $actions Plugin Action links.
344 * @return array
345 */
346 public static function plugin_action_links( $actions ) {
347 $new_actions = array(
348 'settings' => '<a href="' . admin_url( 'admin.php?page=user-registration-settings' ) . '" aria-label="' . esc_attr__( 'View User Registration settings', 'user-registration' ) . '">' . esc_html__( 'Settings', 'user-registration' ) . '</a>',
349 );
350
351 return array_merge( $new_actions, $actions );
352 }
353
354 /**
355 * Display row meta in the Plugins list table.
356 *
357 * @param array $plugin_meta Plugin Row Meta.
358 * @param string $plugin_file Plugin Row Meta.
359 * @return array
360 */
361 public static function plugin_row_meta( $plugin_meta, $plugin_file ) {
362 if ( UR_PLUGIN_BASENAME === $plugin_file ) {
363 $new_plugin_meta = array(
364 'docs' => '<a href="' . esc_url( apply_filters( 'user_registration_docs_url', 'https://docs.wpuserregistration.com/' ) ) . '" area-label="' . esc_attr__( 'View User Registration documentation', 'user-registration' ) . '">' . esc_html__( 'Docs', 'user-registration' ) . '</a>',
365 'support' => '<a href="' . esc_url( apply_filters( 'user_registration_support_url', 'https://wpuserregistration.com/support/' ) ) . '" area-label="' . esc_attr__( 'Visit free customer support', 'user-registration' ) . '">' . __( 'Free support', 'user-registration' ) . '</a>',
366 );
367
368 return array_merge( $plugin_meta, $new_plugin_meta );
369 }
370
371 return (array) $plugin_meta;
372 }
373 }
374
375 endif;
376
377 /**
378 * Check to see if UR already defined and resolve conflicts while installing PRO version.
379 *
380 * @since 2.0.4
381 */
382
383 if ( ! function_exists( 'UR' ) ) {
384
385 /**
386 * Main instance of UserRegistration.
387 *
388 * Returns the main instance of FT to prevent the need to use globals.
389 *
390 * @since 1.0.0
391 * @return UserRegistration
392 */
393 function UR() {
394 return UserRegistration::instance();
395 }
396 } else {
397
398 if ( ! function_exists( 'user_registration_pro_activated' ) ) {
399 /**
400 * When Pro version is activated, deactivate free version.
401 */
402 function user_registration_pro_activated() {
403 set_transient( 'user_registration_pro_activated', true );
404 user_registration_free_deactivate();
405 }
406 }
407 add_action( 'activate_user-registration-pro/user-registration.php', 'user_registration_pro_activated' );
408
409 if ( ! function_exists( 'user_registration_free_activated' ) ) {
410 /**
411 * When user activates free version, set the value that is to be used to handle both Free and Pro activation conflict.
412 */
413 function user_registration_free_activated() {
414
415 set_transient( 'user_registration_free_activated', true );
416
417 }
418 }
419 add_action( 'activate_user-registration/user-registration.php', 'user_registration_free_activated' );
420
421 if ( ! function_exists( 'user_registration_free_deactivated' ) ) {
422 /**
423 * When user deactivates free version, remove the value that was used to handle both Free and Pro activation conflict.
424 */
425 function user_registration_free_deactivated() {
426
427 global $user_registration_free_activated, $user_registration_free_deactivated;
428
429 $user_registration_free_activated = (bool) get_transient( 'user_registration_free_activated' );
430 $user_registration_free_deactivated = true;
431
432 delete_transient( 'user_registration_free_activated' );
433 }
434 }
435 add_action( 'deactivate_user-registration/user-registration.php', 'user_registration_free_deactivated' );
436
437 if ( ! function_exists( 'user_registration_free_deactivate' ) ) {
438 /**
439 * Deactivate Free version if Pro is already activated.
440 *
441 * @since 1.0.0
442 */
443 function user_registration_free_deactivate() {
444
445 $plugin = 'user-registration/user-registration.php';
446
447 deactivate_plugins( $plugin );
448 do_action( 'user_registration_free_deactivate', $plugin );
449 delete_transient( 'user_registration_pro_activated' );
450 }
451 }
452
453 add_action( 'admin_init', 'user_registration_free_deactivate' );
454
455 if ( ! function_exists( 'user_registration_free_notice' ) ) {
456 /**
457 * When user wants to activate Free version alongside Pro, then display the message.
458 */
459 function user_registration_free_notice() {
460
461 global $user_registration_free_activated, $user_registration_free_deactivated;
462
463 if (
464 empty( $user_registration_free_activated ) ||
465 empty( $user_registration_free_deactivated )
466 ) {
467 return;
468 }
469
470 echo '<div class="notice-warning notice is-dismissible"><p>' . wp_kses_post( __( 'As <strong>User Registration Pro</strong> is active, <strong>User Registration Free</strong> is now not needed.', 'user-registration' ) ) . '</p></div>';
471
472 if ( isset( $_GET['activate'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
473 unset( $_GET['activate'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
474 }
475
476 unset( $user_registration_free_activated, $user_registration_free_deactivated );
477 }
478 }
479 add_action( 'admin_notices', 'user_registration_free_notice' );
480
481 // Do not process the plugin code further.
482 return;
483 }
484 // Global for backwards compatibility.
485 $GLOBALS['user-registration'] = UR();
486