forked from weDevsOfficial/wp-user-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpuf.php
919 lines (768 loc) · 32.6 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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
<?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: Tareq Hasan
Version: 3.1.5
Author URI: https://tareq.co
License: GPL2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: wp-user-frontend
Domain Path: /languages
*/
define( 'WPUF_VERSION', '3.1.5' );
define( 'WPUF_FILE', __FILE__ );
define( 'WPUF_ROOT', dirname( __FILE__ ) );
define( 'WPUF_ROOT_URI', plugins_url( '', __FILE__ ) );
define( 'WPUF_ASSET_URI', WPUF_ROOT_URI . '/assets' );
/**
* Main bootstrap class for WP User Frontend
*
* @package WP User Frontend
*/
final class WP_User_Frontend {
/**
* Holds various class instances
*
* @since 2.5.7
*
* @var array
*/
private $container = array();
/**
* Form field value seperator
*
* @var string
*/
static $field_separator = '| ';
/**
* The singleton instance
*
* @var WP_User_Frontend
*/
private static $_instance;
/**
* Pro plugin checkup
*
* @var boolean
*/
private $is_pro = false;
/**
* Minimum PHP version required
*
* @var string
*/
private $min_php = '5.4.0';
/**
* Fire up the plugin
*/
public function __construct() {
if ( ! $this->is_supported_php() ) {
add_action( 'admin_notices', array( $this, 'php_version_notice' ) );
return;
}
register_activation_hook( __FILE__, array( $this, 'install' ) );
register_deactivation_hook( __FILE__, array( $this, 'uninstall' ) );
$this->includes();
$this->init_hooks();
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
*/
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( $error ); ?></p>
</div>
<?php
}
/**
* Initialize the hooks
*
* @since 2.5.4
*
* @return void
*/
public function init_hooks() {
add_action( 'plugins_loaded', array( $this, 'wpuf_loader' ) );
add_action( 'plugins_loaded', array( $this, 'plugin_upgrades' ) );
add_action( 'plugins_loaded', array( $this, 'instantiate' ) );
add_action( 'init', array( $this, 'load_textdomain' ) );
add_action( 'admin_init', array( $this, 'block_admin_access' ) );
add_filter( 'show_admin_bar', array( $this, 'show_admin_bar' ) );
// enqueue plugin scripts, don't remove priority.
// If remove or set priority under 1000 then registered styles will not load on WC Marketplace vendor dashboard.
// we have integration with WC Marketplace plugin since version 3.0 where WC Marketplae vendors' can submit post
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 9999 );
// do plugin upgrades
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
// add custom css
add_action( 'wp_head', array( $this, 'add_custom_css' ) );
// set schedule event
add_action( 'wpuf_remove_expired_post_hook', array( $this, 'action_to_remove_exipred_post' ) );
add_action( 'wp_ajax_wpuf_weforms_install', array( $this, 'install_weforms' ) );
// Insight class instentiate
$this->container['insights'] = new WPUF_WeDevs_Insights( __FILE__ );
}
/**
* Magic getter to bypass referencing plugin.
*
* @since 2.5.7
*
* @param string $prop
*
* @return mixed
*/
public function __get( $prop ) {
if ( array_key_exists( $prop, $this->container ) ) {
return $this->container[ $prop ];
}
return $this->{$prop};
}
/**
* Schedules the post expiry event
*
* @since 2.2.7
*/
public static function set_schedule_events() {
wp_schedule_event( time(), 'daily', 'wpuf_remove_expired_post_hook' );
}
/**
* Action when posts expiration date is passed
*
* @since 2.2.7
*/
public function action_to_remove_exipred_post() {
$args = array(
'meta_key' => 'wpuf-post_expiration_date',
'meta_value' => date( 'Y-m-d' ),
'meta_compare' => '<',
'post_type' => get_post_types(),
'post_status' => 'publish',
'posts_per_page' => -1
);
$mail_subject = apply_filters( 'wpuf_post_expiry_mail_subject', sprintf( '[%s] %s', get_bloginfo( 'name' ), __( 'Your Post Has Been Expired', 'wp-user-frontend' ) ) );
$posts = get_posts( $args );
foreach ( $posts as $each_post ) {
$post_to_update = array(
'ID' => $each_post->ID,
'post_status' => get_post_meta( $each_post->ID, 'wpuf-expired_post_status', true ) ? get_post_meta( $each_post->ID, 'wpuf-expired_post_status', true ) : 'draft'
);
wp_update_post( $post_to_update );
$message = get_post_meta( $each_post->ID, 'wpuf-post_expiration_message', true );
if ( ! empty( $message ) ) {
wp_mail( get_the_author_meta( 'user_email', $each_post->post_author ), $mail_subject, $message );
}
}
// save an option for debugging purpose
update_option( 'wpuf_expiry_posts_last_cleaned', date( 'F j, Y g:i a' ) );
}
/**
* Singleton Instance
*
* @return \self
*/
public static function init() {
if ( ! self::$_instance ) {
self::$_instance = new WP_User_Frontend();
}
return self::$_instance;
}
/**
* Include the required files
*
* @return void
*/
public function includes() {
require_once dirname( __FILE__ ) . '/wpuf-functions.php';
require_once dirname( __FILE__ ) . '/lib/gateway/paypal.php';
require_once dirname( __FILE__ ) . '/lib/gateway/bank.php';
require_once dirname( __FILE__ ) . '/lib/class-wedevs-insights.php';
require_once WPUF_ROOT . '/includes/class-frontend-render-form.php';
require_once WPUF_ROOT . '/admin/form-builder/class-wpuf-form-builder-field-settings.php';
// global classes/functions
require_once WPUF_ROOT . '/class/upload.php';
require_once WPUF_ROOT . '/admin/form-template.php';
require_once WPUF_ROOT . '/class/post-form-template.php';
require_once WPUF_ROOT . '/class/subscription.php';
require_once WPUF_ROOT . '/class/render-form.php';
require_once WPUF_ROOT . '/class/payment.php';
require_once WPUF_ROOT . '/class/frontend-form-post.php';
require_once WPUF_ROOT . '/class/frontend-account.php';
require_once WPUF_ROOT . '/includes/class-form.php';
require_once WPUF_ROOT . '/includes/class-form-manager.php';
require_once WPUF_ROOT . '/includes/class-login-widget.php';
require_once WPUF_ROOT . '/includes/setup-wizard.php';
require_once WPUF_ROOT . '/includes/countries-state.php';
require_once WPUF_ROOT . '/includes/class-billing-address.php';
include_once WPUF_ROOT . '/includes/class-gutenblock.php';
include_once WPUF_ROOT . '/includes/class-form-preview.php';
include_once WPUF_ROOT . '/includes/class-customizer.php';
if ( class_exists( 'WeDevs_Dokan' ) ) {
require_once WPUF_ROOT . '/includes/class-dokan-integration.php';
}
if ( class_exists( 'WCMp' ) ) {
require_once WPUF_ROOT . '/includes/class-wcmp-integration.php';
}
if ( class_exists( 'WC_Vendors' ) ) {
require_once WPUF_ROOT . '/includes/class-wc-vendors-integration.php';
}
require_once WPUF_ROOT . '/includes/class-user.php';
require_once WPUF_ROOT . '/includes/class-user-subscription.php';
if ( is_admin() ) {
require_once WPUF_ROOT . '/admin/settings-options.php';
require_once WPUF_ROOT . '/admin/class-admin-settings.php';
require_once WPUF_ROOT . '/admin/form-handler.php';
require_once WPUF_ROOT . '/admin/form.php';
require_once WPUF_ROOT . '/admin/posting.php';
require_once WPUF_ROOT . '/admin/class-admin-subscription.php';
require_once WPUF_ROOT . '/admin/installer.php';
require_once WPUF_ROOT . '/admin/class-admin-welcome.php';
require_once WPUF_ROOT . '/admin/promotion.php';
require_once WPUF_ROOT . '/admin/post-forms-list-table.php';
require_once WPUF_ROOT . '/includes/free/admin/shortcode-button.php';
require_once WPUF_ROOT . '/admin/form-builder/class-wpuf-admin-form-builder.php';
require_once WPUF_ROOT . '/admin/form-builder/class-wpuf-admin-form-builder-ajax.php';
include_once WPUF_ROOT . '/lib/class-weforms-upsell.php';
include_once WPUF_ROOT . '/includes/class-whats-new.php';
include_once WPUF_ROOT . '/includes/class-acf.php';
include_once WPUF_ROOT . '/includes/class-privacy.php';
} else {
require_once WPUF_ROOT . '/class/frontend-dashboard.php';
require_once WPUF_ROOT . '/includes/free/class-registration.php';
require_once WPUF_ROOT . '/includes/free/class-login.php';
}
// add reCaptcha library if not found
if ( ! function_exists( 'recaptcha_get_html' ) ) {
require_once dirname( __FILE__ ) . '/lib/recaptchalib.php';
require_once dirname( __FILE__ ) . '/lib/invisible_recaptcha.php';
}
require_once WPUF_ROOT . '/includes/class-frontend-form-post.php';
require_once WPUF_ROOT . '/includes/class-field-manager.php';
require_once WPUF_ROOT . '/includes/class-pro-upgrades.php';
require_once WPUF_ROOT . '/includes/fields/field-trait.php';
}
/**
* Instantiate the classes
*
* @return void
*/
function instantiate() {
$this->container['upload'] = new WPUF_Upload();
$this->container['paypal'] = new WPUF_Paypal();
$this->container['form_template'] = new WPUF_Admin_Form_Template();
$this->container['subscription'] = WPUF_Subscription::init();
$this->container['frontend_post'] = WPUF_Frontend_Form_Post::init();
$this->container['account'] = new WPUF_Frontend_Account();
$this->container['billing_address'] = new WPUF_Ajax_Address_Form();
$this->container['forms'] = new WPUF_Form_Manager();
$this->container['preview'] = new WPUF_Form_Preview();
$this->container['block'] = new WPUF_Form_Block();
$this->container['customize'] = new WPUF_Customizer_Options();
if ( class_exists( 'WeDevs_Dokan' ) ) {
$this->container['dokan_integration'] = new WPUF_Dokan_Integration();
}
if ( class_exists( 'WCMp' ) ) {
$this->container['wcmp_integration'] = new WPUF_WCMp_Integration();
}
if ( class_exists( 'WC_Vendors' ) ) {
$this->container['WCV_Integration'] = new WPUF_WC_Vendors_Integration();
}
if ( is_admin() ) {
$this->container['settings'] = WPUF_Admin_Settings::init();
$this->container['form_handler'] = new WPUF_Admin_Form_Handler();
$this->container['admin_form'] = new WPUF_Admin_Form();
$this->container['admin_posting'] = WPUF_Admin_Posting::init();
$this->container['admin_subscription'] = new WPUF_Admin_Subscription();
$this->container['admin_installer'] = new WPUF_Admin_Installer();
$this->container['admin_promotion'] = new WPUF_Admin_Promotion();
$this->container['welcome'] = new WPUF_Admin_Welcome();
$this->container['whats_new'] = new WPUF_Whats_New();
$this->container['wpuf_acf'] = new WPUF_ACF_Compatibility();
$this->container['privacy'] = new WPUF_Privacy();
} else {
$this->container['dashboard'] = new WPUF_Frontend_Dashboard();
$this->container['payment'] = new WPUF_Payment();
$this->container['login'] = WPUF_Simple_Login::init();
$this->container['registration'] = WPUF_Registration::init();
}
$this->container['fields'] = new WPUF_Field_Manager();
$this->container['frontend_form'] = WPUF_Frontend_Form::init();
$this->container['pro_upgrades'] = new WPUF_Pro_Upgrades();
}
/**
* Create tables on plugin activation
*
* @global object $wpdb
*/
public static function install() {
require_once WPUF_ROOT . '/includes/class-installer.php';
$installer = new WPUF_Installer();
$installer->install();
}
/**
* Do plugin upgrades
*
* @since 2.2
*
* @return void
*/
function plugin_upgrades() {
if ( ! is_admin() && ! current_user_can( 'manage_options' ) ) {
return;
}
require_once WPUF_ROOT . '/includes/class-upgrades.php';
$upgrader = new WPUF_Upgrades();
if ( $upgrader->needs_update() ) {
$upgrader->perform_updates();
}
}
/**
* Load wpuf free class if not pro
*
* @since 2.5.4
*/
function wpuf_loader() {
$is_expired = wpuf_is_license_expired();
$has_pro = class_exists( 'WP_User_Frontend_Pro' );
if ( $has_pro && $is_expired ) {
add_action( 'admin_notices', array( $this, 'license_expired' ) );
}
if ( $has_pro ) {
$this->is_pro = true;
add_action( 'admin_notices', array( $this,'wpuf_latest_pro_activation_notice') );
} else {
include dirname( __FILE__ ) . '/includes/free/loader.php';
$this->container['free_loader'] = new WPUF_Free_Loader();
}
}
/**
* Latest Pro Activation Message
*
* @return void
*/
function wpuf_latest_pro_activation_notice() {
if ( ! version_compare(WPUF_PRO_VERSION, '3.1.0', '<' ) ) {
return;
}
$offer_msg = __( '<p style="font-size: 13px">
<strong class="highlight-text" style="font-size: 18px; display:block; margin-bottom:8px"> UPDATE REQUIRED </strong>
WP User Frontend Pro is not working because you are using an old version of WP User Frontend Pro. Please update <strong>WPUF Pro</strong> to >= <strong>v3.1.0</strong> to work with the latest version of WP User Frontend
</p>', 'wp-user-frontend' );
?>
<div class="notice is-dismissible" id="wpuf-update-offer-notice">
<table>
<tbody>
<tr>
<td class="image-container">
<img src="https://ps.w.org/wp-user-frontend/assets/icon-256x256.png" alt="">
</td>
<td class="message-container">
<?php echo $offer_msg; ?>
</td>
<td><a href="https://wedevs.com/account/downloads/" class="button button-primary promo-btn" target="_blank"><?php _e( 'Update WP User Frontend Pro Now', 'wp-user-frontend' ); ?></a></td>
</tr>
</tbody>
</table>
<!-- <a href="https://wedevs.com/account/downloads/" class="button button-primary promo-btn" target="_blank"><?php _e( 'Update WP User Frontend Pro NOW', 'wp-user-frontend' ); ?></a> -->
</div><!-- #wpuf-update-offer-notice -->
<style>
#wpuf-update-offer-notice {
background-size: cover;
border: 0px;
padding: 10px;
opacity: 0;
border-left: 3px solid red;
}
.wrap > #wpuf-update-offer-notice {
opacity: 1;
}
#wpuf-update-offer-notice table {
border-collapse: collapse;
width: 70%;
}
#wpuf-update-offer-notice table td {
padding: 0;
}
#wpuf-update-offer-notice table td.image-container {
background-color: #fff;
vertical-align: middle;
width: 95px;
}
#wpuf-update-offer-notice img {
max-width: 100%;
max-height: 100px;
vertical-align: middle;
border-radius: 100%;
}
#wpuf-update-offer-notice table td.message-container {
padding: 0 10px;
}
#wpuf-update-offer-notice h2{
color: #000;
margin-bottom: 10px;
font-weight: normal;
margin: 16px 0 14px;
-webkit-text-shadow: 0.1px 0.1px 0px rgba(250, 250, 250, 0.24);
-moz-text-shadow: 0.1px 0.1px 0px rgba(250, 250, 250, 0.24);
-o-text-shadow: 0.1px 0.1px 0px rgba(250, 250, 250, 0.24);
text-shadow: 0.1px 0.1px 0px rgba(250, 250, 250, 0.24);
}
#wpuf-update-offer-notice h2 span {
position: relative;
top: 0;
}
#wpuf-update-offer-notice p{
color: #000;
font-size: 14px;
margin-bottom: 10px;
-webkit-text-shadow: 0.1px 0.1px 0px rgba(250, 250, 250, 0.24);
-moz-text-shadow: 0.1px 0.1px 0px rgba(250, 250, 250, 0.24);
-o-text-shadow: 0.1px 0.1px 0px rgba(250, 250, 250, 0.24);
text-shadow: 0.1px 0.1px 0px rgba(250, 250, 250, 0.24);
}
#wpuf-update-offer-notice p strong.highlight-text{
color: #000;
}
#wpuf-update-offer-notice p a {
color: #000;
}
#wpuf-update-offer-notice .notice-dismiss:before {
color: #000;
}
#wpuf-update-offer-notice span.dashicons-megaphone {
position: absolute;
bottom: 46px;
right: 248px;
color: rgba(253, 253, 253, 0.29);
font-size: 96px;
transform: rotate(-21deg);
}
#wpuf-update-offer-notice a.promo-btn{
background: #0073aa;
/*border-color: #fafafa #fafafa #fafafa;*/
box-shadow: 0 1px 0 #fafafa;
color: #fff;
text-decoration: none;
text-shadow: none;
position: absolute;
top: 40px;
right: 26px;
height: 40px;
line-height: 40px;
width: 300px;
text-align: center;
font-weight: 600;
}
</style>
<script type='text/javascript'>
jQuery('body').on('click', '#wpuf-update-offer-notice .notice-dismiss', function(e) {
e.preventDefault();
wp.ajax.post('wpuf-dismiss-update-offer-notice', {
dismissed: true
});
});
</script>
<?php
}
/**
* Manage task on plugin deactivation
*
* @return void
*/
public static function uninstall() {
wp_clear_scheduled_hook( 'wpuf_remove_expired_post_hook' );
}
/**
* Enqueues Styles and Scripts when the shortcodes are used only
*
* @uses has_shortcode()
*
* @since 0.2
*/
function enqueue_scripts() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
global $post;
$scheme = is_ssl() ? 'https' : 'http';
$api_key = wpuf_get_option( 'gmap_api_key', 'wpuf_general' );
$load_gmap = apply_filters( 'wpuf_load_gmap_script', true );
$pay_page = intval( wpuf_get_option( 'payment_page', 'wpuf_payment' ) );
if ( ! empty( $api_key ) && $load_gmap ) {
wp_enqueue_script( 'google-maps', $scheme . '://maps.google.com/maps/api/js?libraries=places&key=' . $api_key, array(), null );
}
if ( isset( $post->ID ) ) {
?>
<script type="text/javascript" id="wpuf-language-script">
var error_str_obj = {
'required' : '<?php esc_attr_e( 'is required', 'wp-user-frontend' ); ?>',
'mismatch' : '<?php esc_attr_e( 'does not match', 'wp-user-frontend' ); ?>',
'validation' : '<?php esc_attr_e( 'is not valid', 'wp-user-frontend' ); ?>'
}
</script>
<?php
wp_register_script( 'wpuf-form', WPUF_ASSET_URI . '/js/frontend-form' . $suffix . '.js', array( 'jquery' ) );
}
wp_register_style( 'wpuf-css', WPUF_ASSET_URI . '/css/frontend-forms.css' );
// register css files for different layouts of frontend form
wp_register_style( 'wpuf-layout1', WPUF_ASSET_URI . '/css/frontend-form/layout1.css' );
wp_register_style( 'wpuf-layout2', WPUF_ASSET_URI . '/css/frontend-form/layout2.css' );
wp_register_style( 'wpuf-layout3', WPUF_ASSET_URI . '/css/frontend-form/layout3.css' );
wp_register_style( 'wpuf-layout4', WPUF_ASSET_URI . '/css/frontend-form/layout4.css' );
wp_register_style( 'wpuf-layout5', WPUF_ASSET_URI . '/css/frontend-form/layout5.css' );
wp_register_script( 'wpuf-subscriptions', WPUF_ASSET_URI . '/js/subscriptions.js', array( 'jquery' ), false, true );
if ( wpuf_get_option( 'load_script', 'wpuf_general', 'on' ) == 'on' ) {
$this->plugin_scripts();
} elseif ( wpuf_has_shortcode( 'wpuf-login' ) || wpuf_has_shortcode( 'wpuf-registration' ) || wpuf_has_shortcode( 'wpuf-meta' ) || wpuf_has_shortcode( 'wpuf_form' ) || wpuf_has_shortcode( 'wpuf_edit' ) || wpuf_has_shortcode( 'wpuf_profile' ) || wpuf_has_shortcode( 'wpuf_dashboard' ) || wpuf_has_shortcode( 'weforms' ) || wpuf_has_shortcode( 'wpuf_account' ) || wpuf_has_shortcode( 'wpuf_sub_pack' ) || ( isset( $post->ID ) && ( $pay_page == $post->ID ) ) || isset( $_GET['wpuf_preview'] ) ) {
$this->plugin_scripts();
}
}
/**
* add custom css to head
*/
function add_custom_css() {
global $post;
if ( ! is_a( $post, 'WP_Post' ) ) {
return;
}
if ( wpuf_has_shortcode( 'wpuf-login', $post->ID )
|| wpuf_has_shortcode( 'wpuf-registration', $post->ID )
|| wpuf_has_shortcode( 'wpuf-meta', $post->ID )
|| wpuf_has_shortcode( 'wpuf_form', $post->ID )
|| wpuf_has_shortcode( 'wpuf_edit', $post->ID )
|| wpuf_has_shortcode( 'wpuf_profile', $post->ID )
|| wpuf_has_shortcode( 'wpuf_dashboard', $post->ID )
|| wpuf_has_shortcode( 'wpuf_sub_pack', $post->ID )
|| wpuf_has_shortcode( 'wpuf-login', $post->ID )
|| wpuf_has_shortcode( 'wpuf_form', $post->ID )
|| wpuf_has_shortcode( 'wpuf_account', $post->ID )
) {
?>
<style>
<?php echo $custom_css = wpuf_get_option( 'custom_css', 'wpuf_general' ); ?>
</style>
<?php
}
}
function plugin_scripts() {
wp_enqueue_style( 'wpuf-css' );
wp_enqueue_style( 'jquery-ui', WPUF_ASSET_URI . '/css/jquery-ui-1.9.1.custom.css' );
wp_enqueue_style( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.css', array(), WPUF_VERSION );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_script( 'jquery-ui-autocomplete' );
wp_enqueue_script( 'suggest' );
wp_enqueue_script( 'jquery-ui-slider' );
wp_enqueue_script( 'plupload-handlers' );
wp_enqueue_script( 'jquery-ui-timepicker', WPUF_ASSET_URI . '/js/jquery-ui-timepicker-addon.js', array( 'jquery-ui-datepicker' ) );
wp_enqueue_script( 'wpuf-upload', WPUF_ASSET_URI . '/js/upload.js', array( 'jquery', 'plupload-handlers', 'jquery-ui-sortable' ) );
wp_enqueue_script( 'wpuf-form' );
wp_enqueue_script( 'wpuf-subscriptions' );
wp_enqueue_script( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.js', array(), WPUF_VERSION );
wp_localize_script( 'wpuf-form', 'wpuf_frontend', apply_filters( 'wpuf_frontend_js_data' , array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'error_message' => __( 'Please fix the errors to proceed', 'wp-user-frontend' ),
'nonce' => wp_create_nonce( 'wpuf_nonce' ),
'word_limit' => __( 'Word limit reached', 'wp-user-frontend' ),
'cancelSubMsg' => __( 'Are you sure you want to cancel your current subscription ?', 'wp-user-frontend' ),
'delete_it' => __( 'Yes', 'wp-user-frontend' ),
'cancel_it' => __( 'No', 'wp-user-frontend' ),
)) );
wp_localize_script( 'wpuf-subscriptions', 'wpuf_subscription', apply_filters( 'wpuf_subscription_js_data' , array(
'pack_notice' => __( 'Please Cancel Your Currently Active Pack first!', 'wp-user-frontend' ),
)) );
wp_localize_script( 'wpuf-upload', 'wpuf_frontend_upload', array(
'confirmMsg' => __( 'Are you sure?', 'wp-user-frontend' ),
'delete_it' => __( 'Yes, delete it', 'wp-user-frontend' ),
'cancel_it' => __( 'No, cancel it', 'wp-user-frontend' ),
'nonce' => wp_create_nonce( 'wpuf_nonce' ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'plupload' => array(
'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce( 'wpuf-upload-nonce' ),
'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
'filters' => array(
array(
'title' => __( 'Allowed Files', 'wp-user-frontend' ),
'extensions' => '*'
)
),
'multipart' => true,
'urlstream_upload' => true,
'warning' => __( 'Maximum number of files reached!', 'wp-user-frontend' ),
'size_error' => __( 'The file you have uploaded exceeds the file size limit. Please try again.', 'wp-user-frontend' ),
'type_error' => __( 'You have uploaded an incorrect file type. Please try again.', 'wp-user-frontend' )
)
) );
}
/**
* Block user access to admin panel for specific roles
*
* @global string $pagenow
*/
function block_admin_access() {
global $pagenow;
// bail out if we are from WP Cli
if ( defined( 'WP_CLI' ) ) {
return;
}
$access_level = wpuf_get_option( 'admin_access', 'wpuf_general', 'read' );
$valid_pages = array( 'admin-ajax.php', 'admin-post.php', 'async-upload.php', 'media-upload.php' );
if ( ! current_user_can( $access_level ) && ! in_array( $pagenow, $valid_pages ) ) {
// wp_die( __( 'Access Denied. Your site administrator has blocked your access to the WordPress back-office.', 'wpuf' ) );
wp_redirect( home_url() );
exit;
}
}
/**
* Show/hide admin bar to the permitted user level
*
* @since 2.2.3
* @return void
*/
function show_admin_bar($val) {
if ( !is_user_logged_in() ) {
return false;
}
$roles = wpuf_get_option( 'show_admin_bar', 'wpuf_general', array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' ) );
$roles = $roles ? $roles : array();
$current_user = wp_get_current_user();
if ( !in_array( $current_user->roles[0], $roles ) ) {
return false;
}
return $val;
}
/**
* Load the translation file for current language.
*
* @since version 0.7
* @author Tareq Hasan
*/
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, dirname( __FILE__ ) . '/log.txt' );
}
/**
* Returns if the plugin is in PRO version
*
* @since 2.3.2
*
* @return boolean
*/
public function is_pro() {
return $this->is_pro;
}
/**
* Plugin action links
*
* @param array $links
*
* @since 2.3.3
*
* @return array
*/
function plugin_action_links( $links ) {
if ( ! $this->is_pro() ) {
$links[] = '<a href="' . WPUF_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://docs.wedevs.com/docs/wp-user-frontend-pro/getting-started/how-to-install/" target="_blank">Documentation</a>';
return $links;
}
/**
* Show renew prompt once the license key is expired
*
* @since 2.3.13
*
* @return void
*/
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>';
}
/**
* If the core isn't installed
*
* @return void
*/
public function maybe_weforms_install() {
if ( class_exists( 'WeForms' ) ) {
return;
}
// install the core
add_action( 'wp_ajax_wpuf_weforms_install', array( $this, 'install_weforms' ) );
}
/**
* Install weforms plugin via ajax
*
* @return void
*/
public function install_weforms() {
if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'wpuf-weforms-installer-nonce' ) ) {
wp_send_json_error( __( 'Error: Nonce verification failed', 'wp-user-frontend' ) );
}
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
if ( file_exists( WP_PLUGIN_DIR . '/weforms/weforms.php' ) ) {
activate_plugin( 'weforms/weforms.php' );
wp_send_json_success();
}
$plugin = 'weforms';
$api = plugins_api( 'plugin_information', array(
'slug' => $plugin,
'fields' => array(
'sections' => false
)
) );
$upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() );
$result = $upgrader->install( $api->download_link );
if ( is_wp_error( $result ) ) {
wp_send_json_error( $result );
}
$result = activate_plugin( 'weforms/weforms.php' );
if ( is_wp_error( $result ) ) {
wp_send_json_error( $result );
}
wp_send_json_success();
}
}
/**
* Returns the singleton instance
*
* @return \WP_User_Frontend
*/
function wpuf() {
return WP_User_Frontend::init();
}
// kickoff
wpuf();