PluginProbe
User Frontend – Membership, User Registration, User Profile, User Directory & Content Restriction with Frontend Post Submission / trunk
User Frontend – Membership, User Registration, User Profile, User Directory & Content Restriction with Frontend Post Submission vtrunk
4.3.11 4.3.10 4.3.9 4.3.8 4.3.7 4.3.6 4.3.3 4.3.4 4.3.5 4.3.2 trunk 1.1 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.5 2.5.1 2.5.2 2.5.3 2.5.5 2.5.6 2.5.7 2.5.8 All 152 releases
wp-user-frontend / wpuf.php

wpuf.php in User Frontend – Membership, User Registration, User Profile, User Directory & Content Restriction with Frontend Post Submission trunk, at wpuf.php

467 lines 13.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WP User Frontend
4 Plugin URI: https://wordpress.org/plugins/wp-user-frontend/
5 Description: Create, edit, delete, manages your post, pages or custom post types from frontend. Create registration forms, frontend profile and more...
6 Author: weDevs
7 Version: 4.3.11
8 Author URI: https://wedevs.com/?utm_source=WPUF_Author_URI
9 Requires at least: 5.0
10 Requires PHP: 7.4
11 License: GPL2 or later
12 License URI: https://www.gnu.org/licenses/gpl-2.0.html
13 Text Domain: wp-user-frontend
14 Domain Path: /languages
15 */
16
17 // don't call the file directly
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit;
20 }
21
22 $autoload = __DIR__ . '/vendor/autoload.php';
23
24 if ( file_exists( $autoload ) ) {
25 require_once $autoload;
26 }
27
28 define( 'WPUF_VERSION', '4.3.11' );
29 define( 'WPUF_FILE', __FILE__ );
30 define( 'WPUF_ROOT', __DIR__ );
31 define( 'WPUF_ROOT_URI', plugins_url( '', __FILE__ ) );
32 define( 'WPUF_ASSET_URI', WPUF_ROOT_URI . '/assets' );
33 define( 'WPUF_INCLUDES', WPUF_ROOT . '/includes' );
34
35 use WeDevs\WpUtils\SingletonTrait;
36
37 /**
38 * Main bootstrap class for WP User Frontend
39 */
40 final class WP_User_Frontend {
41 use SingletonTrait;
42
43 /**
44 * Form field value seperator
45 *
46 * @var string
47 */
48 public static $field_separator = '| ';
49
50 /**
51 * Pro plugin checkup
52 *
53 * @var bool
54 */
55 private $is_pro = false;
56
57 /**
58 * Minimum PHP version required
59 *
60 * @var string
61 */
62 private $min_php = '5.6';
63
64 /**
65 * Holds various class instances
66 *
67 * @since 4.0.9
68 *
69 * @var array
70 */
71 public $container = [];
72
73 /**
74 * Fire up the plugin
75 */
76 public function __construct() {
77 if ( ! $this->is_supported_php() ) {
78 add_action( 'admin_notices', [ $this, 'php_version_notice' ] );
79
80 return;
81 }
82
83 register_activation_hook( __FILE__, [ $this, 'install' ] );
84 register_deactivation_hook( __FILE__, [ $this, 'uninstall' ] );
85
86 $this->includes();
87 $this->init_hooks();
88
89 do_action( 'wpuf_loaded' );
90 }
91
92 /**
93 * Check if the PHP version is supported
94 *
95 * @return bool
96 */
97 public function is_supported_php( $min_php = null ) {
98 $min_php = $min_php ? $min_php : $this->min_php;
99
100 if ( version_compare( PHP_VERSION, $min_php, '<=' ) ) {
101 return false;
102 }
103
104 return true;
105 }
106
107 /**
108 * Show notice about PHP version
109 *
110 * @return void
111 */
112 public function php_version_notice() {
113 if ( $this->is_supported_php() || ! current_user_can( 'manage_options' ) ) {
114 return;
115 }
116
117 $error = __( 'Your installed PHP Version is: ', 'wp-user-frontend' ) . PHP_VERSION . '. ';
118 $error .= __( 'The <strong>WP User Frontend</strong> plugin requires PHP version <strong>', 'wp-user-frontend' ) . $this->min_php . __( '</strong> or greater.', 'wp-user-frontend' ); ?>
119 <div class="error">
120 <p><?php printf( esc_html( $error ) ); ?></p>
121 </div>
122 <?php
123 }
124
125 /**
126 * Initialize the hooks
127 *
128 * @since 2.5.4
129 *
130 * @return void
131 */
132 public function init_hooks() {
133 add_action( 'plugins_loaded', [ $this, 'init_insights' ], 8 );
134 add_action( 'plugins_loaded', [ $this, 'wpuf_loader' ] );
135 add_action( 'plugins_loaded', [ $this, 'process_wpuf_pro_version' ] );
136 add_action( 'plugins_loaded', [ $this, 'plugin_upgrades' ] );
137 add_action( 'plugins_loaded', [ $this, 'instantiate' ] );
138
139 add_action( 'init', [ $this, 'load_textdomain' ] );
140
141 // do plugin upgrades
142 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), [ $this, 'plugin_action_links' ] );
143
144 add_action( 'widgets_init', [ $this, 'register_widgets' ] );
145 }
146
147 public function init_insights() {
148 // Insight class instantiate
149 $this->container['tracker'] = new WeDevs\Wpuf\Lib\WeDevs_Insights( __FILE__ );
150 }
151
152 /**
153 * Include the required files
154 *
155 * @return void
156 */
157 public function includes() {
158 require_once __DIR__ . '/wpuf-functions.php';
159 require_once __DIR__ . '/includes/class-frontend-render-form.php';
160
161 // add reCaptcha library if not found
162 if ( ! function_exists( 'recaptcha_get_html' ) ) {
163 require_once __DIR__ . '/Lib/recaptchalib.php';
164 require_once __DIR__ . '/Lib/invisible_recaptcha.php';
165 }
166
167 // AI Form Builder includes
168 require_once __DIR__ . '/includes/AI_Manager.php';
169
170 // Gateway helper functions
171 require_once __DIR__ . '/Lib/Gateway/gateway-functions.php';
172 }
173
174 /**
175 * Instantiate the classes
176 *
177 * @return void
178 */
179 public function instantiate() {
180 $this->container['assets'] = new WeDevs\Wpuf\Assets();
181 $this->container['subscription'] = new WeDevs\Wpuf\Admin\Subscription();
182 $this->container['fields'] = new WeDevs\Wpuf\Admin\Forms\Field_Manager();
183 $this->container['customize'] = new WeDevs\Wpuf\Admin\Customizer_Options();
184
185 // Initialize legacy gateway classes for backward compatibility
186 $this->container['bank'] = new WeDevs\Wpuf\Lib\Gateway\Bank();
187 $this->container['paypal'] = new WeDevs\Wpuf\Lib\Gateway\Paypal();
188
189 // Initialize new gateway manager inside init hook for translation issue
190 add_action( 'init', [ $this, 'init_gateway_manager' ] );
191
192 $this->container['api'] = new WeDevs\Wpuf\API();
193 $this->container['integrations'] = new WeDevs\Wpuf\Integrations();
194 $this->container['ai_manager'] = new WeDevs\Wpuf\AI_Manager();
195 $this->container['post_form_block'] = new WeDevs\Wpuf\Blocks\PostForm();
196
197 if ( is_admin() ) {
198 $this->container['admin'] = new WeDevs\Wpuf\Admin();
199 $this->container['setup_wizard'] = new WeDevs\Wpuf\Setup_Wizard();
200 $this->container['pro_upgrades'] = new WeDevs\Wpuf\Pro_Upgrades();
201 $this->container['privacy'] = new WeDevs\Wpuf\WPUF_Privacy();
202
203 // Load Frontend when in Elementor editor or Elementor AJAX so shortcodes
204 // like wpuf_form and wpuf_account are registered and do_shortcode() works.
205 // Without this, is_admin() is true and Frontend is skipped, so do_shortcode()
206 // returns the raw shortcode. Covers: (1) editor page ?action=elementor,
207 // (2) render_widget AJAX when changing "Select Form" (action=elementor_ajax).
208 $get_action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
209 $request_act = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) : '';
210 $is_elementor = ( $get_action === 'elementor' )
211 || ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) && $request_act === 'elementor_ajax' );
212
213
214 if ( $is_elementor ) {
215 $this->container['frontend'] = new WeDevs\Wpuf\Frontend();
216 }
217 } else {
218 $this->container['frontend'] = new WeDevs\Wpuf\Frontend();
219 }
220
221 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
222 // Initialize the ajax class inside init hook for translation issue
223 add_action( 'init', [ $this, 'init_ajax' ] );
224 }
225 }
226
227 /**
228 * Initialize the ajax class
229 *
230 * @since 4.1.4
231 *
232 * @return void
233 */
234 public function init_ajax() {
235 $this->container['ajax'] = new WeDevs\Wpuf\Ajax();
236 }
237
238 /**
239 * Initialize the gateway manager
240 *
241 * @since WPUF_PRO_SINCE
242 *
243 * @return void
244 */
245 public function init_gateway_manager() {
246 $this->container['gateway_manager'] = new WeDevs\Wpuf\Lib\Gateway\Gateway_Manager();
247 }
248
249 /**
250 * Create tables on plugin activation
251 *
252 * @global object $wpdb
253 */
254 public function install() {
255 $installer = new WeDevs\Wpuf\Installer();
256 $installer->install();
257 }
258
259 /**
260 * Do plugin upgrades
261 *
262 * @since 2.2
263 *
264 * @return void
265 */
266 public function plugin_upgrades() {
267 if ( ! is_admin() && ! current_user_can( 'manage_options' ) ) {
268 return;
269 }
270
271 $this->container['upgrades'] = new WeDevs\Wpuf\Admin\Upgrades();
272 }
273
274 /**
275 * Check whether the version of wpuf pro is prior to the code restructure
276 *
277 * @since WPUF_FREE
278 *
279 * @return void
280 */
281 public function process_wpuf_pro_version() {
282 // check whether the version of wpuf pro is prior to the code restructure
283 if ( defined( 'WPUF_PRO_VERSION' ) && version_compare( WPUF_PRO_VERSION, '4', '<' ) ) {
284 // deactivate_plugins( WPUF_PRO_FILE );
285
286 add_action( 'admin_notices', [ $this, 'wpuf_upgrade_notice' ] );
287 }
288 }
289
290 /**
291 * Show WordPress error notice if WP User Frontend not found
292 *
293 * @since 2.4.2
294 */
295 public function wpuf_upgrade_notice() {
296 ?>
297 <div class="notice error" id="wpuf-pro-installer-notice" style="padding: 1em; position: relative;">
298 <h2><?php esc_html_e( 'Your WP User Frontend Pro is almost ready!', 'wp-user-frontend' ); ?></h2>
299 <p>
300 <?php
301 echo wp_kses_post(
302 sprintf(
303 __( 'We\'ve pushed a major update on both <b>WP User Frontend Free</b> and <b>%1$sWP User Frontend Pro%2$s</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' ),
304 '<a target="_blank" href="https://wordpress.org/plugins/wp-user-frontend/">',
305 '</a>'
306 )
307 );
308 ?>
309 </p>
310 </div>
311 <?php
312 }
313
314 /**
315 * Load wpuf Free class if not pro
316 *
317 * @since 2.5.4
318 */
319 public function wpuf_loader() {
320 $has_pro = class_exists( 'WP_User_Frontend_Pro' );
321
322 if ( $has_pro ) {
323 $this->is_pro = true;
324 } else {
325 $this->container['free_loader'] = new WeDevs\Wpuf\Free\Free_Loader();
326
327 $this->container['free_loader']->includes();
328 $this->container['free_loader']->instantiate();
329 $this->container['free_loader']->run_hooks();
330 }
331
332 // Remove the what's new option.
333 delete_option( 'wpuf_whats_new' );
334 delete_option( 'wpufpro_whats_new' );
335 }
336
337 /**
338 * Manage task on plugin deactivation
339 *
340 * @return void
341 */
342 public static function uninstall() {
343 wp_clear_scheduled_hook( 'wpuf_remove_expired_post_hook' );
344 }
345
346 /**
347 * Load the translation file for current language.
348 *
349 * @since version 0.7
350 *
351 * @author Tareq Hasan
352 */
353 public function load_textdomain() {
354 load_plugin_textdomain( 'wp-user-frontend', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
355 }
356
357 /**
358 * The main logging function
359 *
360 * @uses error_log
361 *
362 * @param string $type type of the error. e.g: debug, error, info
363 * @param string $msg
364 */
365 public static function log( $type = '', $msg = '' ) {
366 $msg = sprintf( "[%s][%s] %s\n", date( 'd.m.Y h:i:s' ), $type, $msg ); // phpcs:ignore
367 error_log( $msg, 3, __DIR__ . '/log.txt' );
368 }
369
370 /**
371 * Returns if the plugin is in PRO version
372 *
373 * @since 2.3.2
374 *
375 * @return bool
376 */
377 public function is_pro() {
378 return $this->is_pro;
379 }
380
381 /**
382 * Plugin action links
383 *
384 * @param array $links
385 *
386 * @since 2.3.3
387 *
388 * @return array
389 */
390 public function plugin_action_links( $links ) {
391 $links[] = '<a href="' . admin_url( 'admin.php?page=wpuf-settings' ) . '">' . esc_html( 'Settings' ) . '</a>';
392 $links[] = '<a href="https://wedevs.com/docs/wp-user-frontend-pro/getting-started/how-to-install/" target="_blank"> '. esc_html( 'Docs' ) . '</a>';
393
394 if ( ! $this->is_pro() ) {
395 $links[] = '<a href="https://wedevs.com/wp-user-frontend-pro/pricing/?utm_source=installed_plugins" target="_blank" style="color: #64C273;"> '. esc_html( 'Upgrade to Pro' ) . '</a>';
396 $links[] = '<a href="https://wedevs.com/coupons/?utm_source=installed_plugins" target="_blank" style="color: #5368FF;">'. esc_html( 'Check Discounts' ) . '</a>';
397 }
398
399 return $links;
400 }
401
402 /**
403 * Register widgets
404 *
405 * @since 4.0.0
406 *
407 * @return void
408 */
409 public function register_widgets() {
410 $this->container['widgets'] = new WeDevs\Wpuf\Widgets\Manager();
411 }
412 public function license_expired() {
413 echo '<div class="error">';
414 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>';
415 echo '</div>';
416 }
417
418 /**
419 * Get the global field seperator for WPUF
420 *
421 * @since 4.0.0
422 *
423 * @return string
424 */
425 public function get_field_seperator() {
426 return self::$field_separator;
427 }
428
429 /**
430 * Magic getter to bypass referencing objects
431 *
432 * @since 4.0.9
433 *
434 * @param string $prop
435 *
436 * @return object Class Instance
437 */
438 public function __get( $prop ) {
439 if ( array_key_exists( $prop, $this->container ) ) {
440 return $this->container[ $prop ];
441 }
442 }
443
444 /**
445 * Get the DB version key
446 *
447 * @since 4.0.11
448 *
449 * @return string
450 */
451 public function get_db_version_key() {
452 return 'wpuf_version';
453 }
454 }
455
456 /**
457 * Returns the singleton instance
458 *
459 * @return WP_User_Frontend
460 */
461 function wpuf() {
462 return WP_User_Frontend::instance();
463 }
464
465 // kickoff
466 wpuf();
467