-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathpmpro-signup-shortcode.php
More file actions
591 lines (519 loc) · 26.1 KB
/
pmpro-signup-shortcode.php
File metadata and controls
591 lines (519 loc) · 26.1 KB
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
<?php
/**
* Plugin Name: Paid Memberships Pro - Signup Shortcode & Block
* Plugin URI: https://www.paidmembershipspro.com/add-ons/pmpro-signup-shortcode/
* Description: Embed signup forms anywhere on your WordPress site. Designed to simplify membership registration, especially for free levels.
* Version: 1.2
* Author: Paid Memberships Pro
* Author URI: https://www.paidmembershipspro.com
* Text Domain: pmpro-signup-shortcode
* Domain Path: /languages
* License: GPL-3.0
*/
/**
* Load the languages folder for translations.
*/
function pmprosus_load_textdomain(){
load_plugin_textdomain( 'pmpro-signup-shortcode', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
add_action( 'plugins_loaded', 'pmprosus_load_textdomain' );
/*
Use Email Address as Username and Generate a Password
*/
function pmprosus_skip_username_password() {
// Copy email to username if no username field is present
if ( ! empty( $_REQUEST['bemail'] ) && ! isset( $_REQUEST['username'] ) ) {
$_REQUEST['username'] = function_exists( 'pmpro_generateUsername' ) ? pmpro_generateUsername( '', '', sanitize_email( $_REQUEST['bemail'] ) ) : sanitize_email( $_REQUEST['bemail'] );
}
if ( ! empty( $_POST['bemail'] ) && ! isset( $_POST['username'] ) ) {
$_POST['username'] = sanitize_email( $_POST['bemail'] );
}
if ( ! empty( $_GET['bemail'] ) && ! isset( $_GET['username'] ) ) {
$_GET['username'] = sanitize_email( $_GET['bemail'] );
}
// Autogenerate password if no field is present.
if ( ! empty( $_REQUEST['bemail'] ) && ! isset( $_REQUEST['password'] ) && ! is_user_logged_in() ) {
// Generate password.
$_REQUEST['password'] = wp_generate_password();
$_REQUEST['password2'] = $_REQUEST['password'];
if ( function_exists( 'pmpro_start_session' ) ) {
pmpro_start_session();
}
$_SESSION['pmprosus_autogenerated_password'] = $_REQUEST['password'];
}
if ( ! empty( $_POST['bemail'] ) && ! isset( $_POST['password'] ) && ! is_user_logged_in() ) {
$_POST['password'] = wp_generate_password();
$_POST['password2'] = $_POST['password'];
}
if ( ! empty( $_GET['bemail'] ) && ! isset( $_GET['password'] ) && ! is_user_logged_in() ) {
$_GET['password'] = wp_generate_password();
$_GET['password2'] = $_GET['password'];
}
}
add_action( 'init', 'pmprosus_skip_username_password' );
/*
Add password to confirmation email if it was autogenerated
*/
function pmprosus_pmpro_email_data($data, $email) {
if ( function_exists( 'pmpro_start_session' ) ) {
pmpro_start_session();
}
// Include the generated password in the confirmation email.
if ( ! empty( $_SESSION['pmprosus_autogenerated_password'] ) && strpos( $email->template, 'checkout_' ) !== false ) {
$data['user_email'] = sprintf(
/* translators: 1: Password, 2: Email */
__('Password: %1$s Email: %2$s', 'pmpro-signup-shortcode'),
sanitize_text_field( $_SESSION['pmprosus_autogenerated_password'] ),
esc_html( $data['user_email'] )
);
// Clear session variable
unset( $_SESSION['pmprosus_autogenerated_password'] );
}
return $data;
}
add_filter('pmpro_email_data', 'pmprosus_pmpro_email_data', 10, 2);
/*
Make sure we load our version of the shortcode instead of the one bundled in Register Helper.
*/
function pmprosus_load_shortcode() {
remove_shortcode('pmpro_signup');
add_shortcode('pmpro_signup', 'pmprosus_signup_shortcode');
}
add_action('init', 'pmprosus_load_shortcode');
/*
Save referrer to session
*/
function pmprosus_init_referrer() {
if(!empty($_REQUEST['pmprosus_referrer'])) {
$_SESSION['pmprosus_referrer'] = $_REQUEST['pmprosus_referrer'];
$_SESSION['pmprosus_redirect_to'] = $_REQUEST['redirect_to'];
}
}
add_action('init', 'pmprosus_init_referrer');
/*
Redirect to referrer if set.
*/
function pmprosus_pmpro_confirmation_url($url, $user_id, $level) {
global $post;
//figure out referrer
if(!empty($_REQUEST['pmprosus_referrer']))
$referrer = sanitize_url( $_REQUEST['pmprosus_referrer'] );
elseif(!empty($_SESSION['pmprosus_referrer']))
$referrer = sanitize_url( $_SESSION['pmprosus_referrer'] );
else
$referrer = '';
//figure out redirect_to
if(!empty($_REQUEST['redirect_to']))
$redirect = sanitize_url( $_REQUEST['redirect_to'] );
elseif(!empty($_SESSION['pmprosus_redirect_to']))
$redirect = sanitize_url( $_SESSION['pmprosus_redirect_to'] );
else
$redirect = '';
//unset session vars
unset($_SESSION['pmprosus_referrer']);
unset($_SESSION['pmprosus_redirect_to']);
//save referrer to user meta
update_user_meta($user_id, 'pmprosus_referrer', $referrer );
//change confirmation URL to redirect if set
if($redirect) {
$url = $redirect;
}
return $url;
}
add_filter('pmpro_confirmation_url', 'pmprosus_pmpro_confirmation_url', 10, 3);
/*
This shortcode will show a signup form with account fields based on attributes.
If the level is not free, the user will be taken to the membership checkout
page to enter billing information.
*/
function pmprosus_signup_shortcode( $atts, $content=null, $code="" ) {
global $current_user, $pmpro_level, $username, $email, $pmpro_pages;
// $atts ::= array of attributes
// $content ::= text within enclosing form of shortcode element
// $code ::= the shortcode found, when == callback name
// examples: [pmpro_signup level="3" short="1" intro="0" submit_button="Signup Now"]
//make sure PMPro is activated
if ( ! function_exists( 'pmpro_getLevel' ) ) {
return esc_html__( 'Paid Memberships Pro must be installed to use the pmpro_signup shortcode.', 'pmpro-signup-shortcode' );
}
//set defaults
extract(shortcode_atts(array(
'intro' => "0",
'hidelabels' => NULL,
'level' => NULL,
'login' => true,
'redirect' => NULL,
'short' => NULL,
'submit_button' => __( "Sign Up Now", "pmpro-signup-shortcode" ),
'title' => NULL,
'custom_fields' => true,
'confirm_email' => true,
'confirm_password' => true,
'levels' => NULL,
), $atts));
// If there is a current level in global, save it to a backup variable.
$pmpro_level_backup = $pmpro_level;
// Filters the $title value to allow either dynamic or static titles. Note: Returns string if it's a string.
$title_display = filter_var( $title, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE );
$login = filter_var( $login, FILTER_VALIDATE_BOOLEAN );
$custom_fields = filter_var( $custom_fields, FILTER_VALIDATE_BOOLEAN );
$confirm_email = filter_var( $confirm_email, FILTER_VALIDATE_BOOLEAN );
$confirm_password = filter_var( $confirm_password, FILTER_VALIDATE_BOOLEAN );
$intro = pmprosus_filter_bool_or_string( $intro );
$short = pmprosus_filter_bool_or_string( $short );
$hidelabels = filter_var( $hidelabels, FILTER_VALIDATE_BOOLEAN );
$levels = is_null( $levels ) ? null : sanitize_text_field( $levels );
if ( $levels === '' ) {
$levels = null;
}
// Build the list of levels for multi-level mode and identify which ones the current user already holds.
$pmpro_levels = array();
$held_level_ids = array();
if ( $levels !== null ) {
$all_levels = pmpro_sort_levels_by_order( pmpro_getAllLevels( false, true ) );
$all_levels = apply_filters( 'pmpro_levels_array', $all_levels );
if ( $levels === 'all' ) {
$pmpro_levels = $all_levels;
} else {
$level_ids = array_map( 'intval', array_map( 'trim', explode( ',', $levels ) ) );
foreach ( $all_levels as $a_level ) {
if ( in_array( (int) $a_level->id, $level_ids, true ) ) {
$pmpro_levels[] = $a_level;
}
}
}
// If the list collapses to a single level, fall back to single-level mode and let the rest of the function handle it.
if ( count( $pmpro_levels ) === 1 ) {
$level = (int) $pmpro_levels[0]->id;
$levels = null;
$pmpro_levels = array();
} elseif ( ! empty( $pmpro_levels ) ) {
if ( ! empty( $current_user->ID ) ) {
foreach ( $pmpro_levels as $a_level ) {
if ( pmpro_hasMembershipLevel( $a_level->id, $current_user->ID ) ) {
$held_level_ids[] = (int) $a_level->id;
}
}
}
// Choose the default-selected level: prefer the requested $level if it is in the list and not held; otherwise the first non-held level.
$requested_level = ! empty( $level ) ? (int) $level : 0;
$level = 0;
if ( $requested_level ) {
foreach ( $pmpro_levels as $a_level ) {
if ( (int) $a_level->id === $requested_level && ! in_array( $requested_level, $held_level_ids, true ) ) {
$level = $requested_level;
break;
}
}
}
if ( empty( $level ) ) {
foreach ( $pmpro_levels as $a_level ) {
if ( ! in_array( (int) $a_level->id, $held_level_ids, true ) ) {
$level = (int) $a_level->id;
break;
}
}
}
}
}
// Should we display the default title if $title is true.
if ( $title_display === true ) {
if ( $levels !== null ) {
// Multi-level mode: suppress the auto-built "Register For X" title. Custom title strings ($title_display === null) bypass this block entirely and render unchanged.
$title = '';
} elseif ( ! empty( $level ) ) {
$title = 'Register For ' . pmpro_getLevel( $level )->name;
} else {
$title = 'Register For ' . get_option( 'blogname' );
}
} elseif ( $title_display === false ) {
$title = '';
}
// Set the level for this signup shortcode so level-specific checkout fields appear. Get the first level if no level is specified to use.
if ( ! empty( $level ) ) {
$pmpro_level = pmpro_getLevel( $level );
}
// Get field values from URL or user.
if ( isset( $_REQUEST['username'] ) ) {
$username = sanitize_user( stripslashes( $_REQUEST['username'] ) );
} elseif ( is_user_logged_in() ) {
$username = $current_user->user_login;
} else {
$username = '';
}
// Get email value from URL or user.
if ( isset ( $_REQUEST['email'] ) ) {
$bemail = sanitize_email( stripslashes( $_REQUEST['email'] ) );
} elseif ( is_user_logged_in() ) {
$bemail = $current_user->user_email;
} else {
$bemail = '';
}
// In multi-level mode, suppress per-level UI (custom fields) and bool-true intro. Custom intro strings still render.
if ( $levels !== null ) {
$custom_fields = false;
if ( $intro === true ) {
$intro = false;
}
}
// treat this page load as a checkout
add_filter( 'pmpro_is_checkout', '__return_true' );
/**
* Mirror the core checkout preheader action so anything that hooks into it (recaptcha JS enqueue, TOS global, gateway setup, etc.) also fires here.
*
* @since 1.2
*
* @param object $pmpro_level The level being signed up for.
*/
do_action( 'pmpro_checkout_preheader', $pmpro_level );
ob_start();
// Do some conditional checks before showing the form.
if ( $levels === null && empty( $level ) && current_user_can( 'manage_options' ) ) { ?>
<div class="pmpro_message pmpro_alert"><?php esc_html_e('[pmpro_signup] Admin Only Shortcode Alert: No membership level specified.', 'pmpro-signup-shortcode'); ?></div>
<?php } elseif ( $levels === null && ! empty( $current_user->ID ) && pmpro_hasMembershipLevel( $level, $current_user->ID ) ) {
if ( current_user_can("manage_options") ) { ?>
<div class="pmpro_message pmpro_alert"><?php esc_html_e('[pmpro_signup] Admin Only Shortcode Alert: You are logged in as an administrator and already have the membership level specified.', 'pmpro-signup-shortcode'); ?></div>
<?php } ?>
<?php } elseif ( $levels === null && empty( $pmpro_level ) ) { ?>
<?php if( current_user_can( 'manage_options' ) ) { ?>
<div class="pmpro_message pmpro_alert"><?php printf( esc_html__( '[pmpro_signup] Admin Only Shortcode Alert: The membership level specified is not valid. (ID:%s)', 'pmpro-signup-shortcode' ), esc_html( $level ) ); ?></div>
<?php } ?>
<?php } elseif ( $levels !== null && empty( $pmpro_levels ) ) { ?>
<?php if ( current_user_can( 'manage_options' ) ) { ?>
<div class="pmpro_message pmpro_alert"><?php esc_html_e( '[pmpro_signup] Admin Only Shortcode Alert: None of the membership levels specified are valid.', 'pmpro-signup-shortcode' ); ?></div>
<?php } ?>
<?php } elseif ( $levels !== null && ! empty( $current_user->ID ) && count( $held_level_ids ) === count( $pmpro_levels ) ) { ?>
<div class="pmpro_message pmpro_alert"><?php esc_html_e( 'You already have all of the available memberships.', 'pmpro-signup-shortcode' ); ?></div>
<?php } else { ?>
<style>
.pmpro_signup_form-hidelabels .pmpro_form_field label.pmpro_form_label:not(.pmpro_signup_form-hidelabels .pmpro_form_field-checkbox label.pmpro_form_label):not(.pmpro_signup_form-hidelabels .pmpro_form_field-checkbox_grouped label.pmpro_form_label) {
border: 0;
clip: rect(0, 0, 0, 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
white-space: nowrap;
}
</style>
<?php
// Build the selectors for the form based on shortcode attributes.
$classes = array();
$classes[] = 'pmpro_form';
$classes[] = 'pmpro_signup_form';
if( ! empty( $hidelabels ) ) {
$classes[] = 'pmpro_signup_form-hidelabels';
}
$class = implode( ' ', array_unique( $classes ) );
?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro' ) ); ?>">
<form id="pmpro_form" class="<?php echo esc_attr( pmpro_get_element_class( $class, 'pmpro_signup_form' ) ); ?>" action="<?php echo esc_url( pmpro_url("checkout") ); ?>" method="post">
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card' ) ); ?>">
<?php
if ( ! empty( $title ) ) {
?>
<h2 class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card_title pmpro_font-large' ) ); ?>"><?php echo esc_html( $title ); ?></h2>
<?php
} else {
echo '<br />';
}
?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card_content' ) ); ?>">
<input type="hidden" id="pmpro_signup_shortcode" name="pmpro_signup_shortcode" value="1" />
<?php do_action( 'pmpro_signup_form_before_fields' ); ?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_fields' ) ); ?>">
<?php if ( ! empty( $intro ) ) { ?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_fields-description' ) ); ?>">
<?php echo wp_kses_post( wpautop($intro) ); ?>
</div>
<?php } ?>
<?php
if ( $levels === null ) { ?>
<input type="hidden" id="level" name="level" value="<?php echo intval( $level ); ?>" />
<?php } else { ?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_field pmpro_form_field-select pmpro_form_field-levels' ) ); ?>">
<label for="level" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_label' ) ); ?>"><?php esc_html_e( 'Membership Level', 'pmpro-signup-shortcode' );?></label>
<select name="level" id="level" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_input pmpro_form_input-select pmpro_form_input-level' ) ); ?>">
<?php foreach ( $pmpro_levels as $dropdown_level ) {
$cost_text = pmpro_getLevelCost( $dropdown_level, false, true );
$option_name = $dropdown_level->name;
if ( ! empty( $cost_text ) ) {
$option_name .= ' - ' . $cost_text;
}
$is_held = in_array( (int) $dropdown_level->id, $held_level_ids, true );
if ( $is_held ) {
$option_name .= ' (' . __( 'Current Level', 'pmpro-signup-shortcode' ) . ')';
}
?>
<option value="<?php echo esc_attr( $dropdown_level->id ); ?>" <?php selected( $level, $dropdown_level->id ); ?> <?php disabled( $is_held ); ?>>
<?php echo wp_kses_post( $option_name ); ?>
</option>
<?php } ?>
</select>
</div> <!-- end pmpro_form_field-levels -->
<?php } ?>
<?php if ( ! empty( $current_user->ID ) ) { ?>
<div id="pmpro_account_loggedin">
<?php
$allowed_html = array(
'a' => array(
'href' => array(),
'target' => array(),
'title' => array(),
),
'strong' => array(),
);
echo wp_kses(
sprintf(
/* translators: 1: Username, 2: Logout URL */
__('You are logged in as <strong>%1$s</strong>. If you would like to use a different account for this membership, <a href="%2$s">log out now</a>.', 'pmpro-signup-shortcode'),
$current_user->user_login,
esc_url( wp_logout_url( $_SERVER['REQUEST_URI'] ) )
),
$allowed_html
);
?>
</div>
<?php } else { ?>
<?php if ( $short !== 'emailonly') { ?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_field pmpro_form_field-text pmpro_form_field-username', 'pmpro_form_field-username' ) ); ?>">
<label for="username" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_label' ) ); ?>"><?php esc_html_e('Username', 'pmpro-signup-shortcode' );?></label>
<input id="username" name="username" type="text" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_input pmpro_form_input-text', 'username' ) ); ?>" autocomplete="username" value="<?php echo esc_attr( $username ); ?>" <?php if( ! empty( $hidelabels ) ) { ?>placeholder="<?php esc_attr_e('Username', 'pmpro-signup-shortcode'); ?>"<?php } ?> />
</div> <!-- end pmpro_form_field-username -->
<?php } ?>
<?php if ( ! empty( $custom_fields ) ) { do_action("pmpro_checkout_after_username"); } ?>
<?php if ( $short !== 'emailonly') { ?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_field pmpro_form_field-password' ) ); ?>">
<label for="password" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_label' ) ); ?>"><?php esc_html_e('Password', 'pmpro-signup-shortcode');?></label>
<input type="password" name="password" id="password" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_input pmpro_form_input-password', 'password' ) ); ?>" autocomplete="new-password" spellcheck="false" value="" <?php if( ! empty( $hidelabels ) ) { ?> placeholder="<?php esc_attr_e('Password', 'pmpro-signup-shortcode');?>"<?php } ?> />
</div> <!-- end pmpro_form_field-password -->
<?php } ?>
<?php if( ! empty( $short ) || ! $confirm_password ) { ?>
<input type="hidden" name="password2_copy" value="1" />
<?php } else { ?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_field pmpro_form_field-password', 'pmpro_form_field-password2' ) ); ?>">
<label for="password2" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_label' ) ); ?>"><?php esc_html_e('Confirm Password', 'pmpro-signup-shortcode');?></label>
<input type="password" name="password2" id="password2" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_input pmpro_form_input-password', 'password2' ) ); ?>" autocomplete="new-password" spellcheck="false" value="" <?php if( ! empty( $hidelabels ) ) { ?>placeholder="<?php esc_attr_e('Confirm Password', 'pmpro-signup-shortcode');?>"<?php } ?> />
</div> <!-- end pmpro_form_field-password2 -->
<?php } ?>
<?php if ( ! empty( $custom_fields ) ) { do_action("pmpro_checkout_after_password"); } ?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_field pmpro_form_field-email pmpro_form_field-bemail', 'pmpro_form_field-bemail' ) ); ?>">
<label for="bemail" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_label' ) ); ?>"><?php esc_html_e('E-mail Address', 'pmpro-signup-shortcode');?></label>
<input id="bemail" name="bemail" type="email" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_input pmpro_form_input-email', 'bemail' ) ); ?>" value="<?php echo esc_attr( $bemail ); ?>" <?php if( ! empty( $hidelabels ) ) { ?> placeholder="<?php esc_attr_e('E-mail Address', 'pmpro-signup-shortcode');?>"<?php } ?> />
</div> <!-- end pmpro_form_field-bemail -->
<?php if( ! empty( $short ) || ! $confirm_email ) { ?>
<input type="hidden" name="bconfirmemail_copy" value="1" />
<?php } else { ?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_field pmpro_form_field-email pmpro_form_field-bconfirmemail', 'pmpro_form_field-bconfirmemail' ) ); ?>">
<label for="bconfirmemail" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_label' ) ); ?>"><?php esc_html_e('Confirm E-mail', 'pmpro-signup-shortcode');?></label>
<input id="bconfirmemail" name="bconfirmemail" type="email" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_input pmpro_form_input-email', 'bconfirmemail' ) ); ?>" value="" <?php if( ! empty( $hidelabels ) ) { ?>placeholder="<?php esc_attr_e('Confirm E-mail', 'pmpro-signup-shortcode');?>"<?php } ?> />
</div> <!-- end pmpro_form_field-bconfirmemail -->
<?php } ?>
<input type="hidden" name="pmprosus_referrer" value="<?php echo esc_attr($_SERVER['REQUEST_URI']);?>" />
<?php
if ( $redirect == 'referrer' ) {
$redirect_to = $_SERVER['REQUEST_URI'];
} elseif ( $redirect == 'account' ) {
$redirect_to = get_permalink( $pmpro_pages['account'] );
} elseif ( empty( $redirect ) ) {
$redirect_to = '';
} else {
$redirect_to = $redirect;
}
?>
<input type="hidden" name="redirect_to" value="<?php echo esc_url($redirect_to);?>" />
<?php if ( ! empty( $custom_fields ) ) { do_action("pmpro_checkout_after_email"); } ?>
<div class="pmpro_hidden">
<label for="fullname"><?php esc_html_e('Full Name', 'pmpro-signup-shortcode');?></label>
<input id="fullname" name="fullname" type="text" class="input" size="30" value="" /> <strong><?php esc_html_e('LEAVE THIS BLANK', 'pmpro-signup-shortcode');?></strong>
</div>
<?php } ?>
<?php
if ( ! empty( $custom_fields ) ) { do_action( 'pmpro_checkout_after_user_fields' ); } ?>
<?php
if ( ! empty( $custom_fields ) ) {
/**
* Add checkout boxes, including user fields, to the signup form.
*
* @param object $pmpro_level The PMPro Level object being purchased.
*/
do_action( 'pmpro_checkout_boxes', $pmpro_level );
}
?>
<?php if ( ! empty( $custom_fields ) ) { do_action( 'pmpro_signup_form_before_submit' ); } ?>
</div> <!-- end pmpro_form_fields -->
<?php
// Add nonce.
wp_nonce_field( 'pmpro_checkout_nonce', 'pmpro_checkout_nonce' );
/**
* Hook to add content before the submit button on the signup form.
*
* @since 1.2
*/
do_action( 'pmpro_checkout_before_submit_button', $pmpro_level ); ?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_form_submit' ) ); ?>">
<span id="pmpro_submit_span">
<input type="hidden" name="submit-checkout" value="1" />
<input type="submit" id="pmpro_btn-submit" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_btn pmpro_btn-submit-checkout', 'pmpro_btn-submit-checkout' ) ); ?>" value="<?php echo esc_attr( $submit_button ); ?>" />
</span>
</div>
<?php do_action( 'pmpro_signup_form_after_submit' ); ?>
</div> <!-- end pmpro_card_content -->
<?php if ( ! empty( $login ) && empty( $current_user->ID ) ) { ?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card_actions' ) ); ?>">
<div class="login-link">
<a href="<?php echo esc_url( wp_login_url( get_permalink() ) ); ?>"><?php esc_html_e( 'Log In','pmpro-signup-shortcode' ); ?></a>
</div>
</div> <!-- end pmpro_card_actions -->
<?php } ?>
</div> <!-- end pmpro_card -->
</form> <!-- end pmpro_form -->
<?php do_action( 'pmpro_signup_form_after_form' ); ?>
</div> <!-- end pmpro -->
<?php } ?>
<?php
$temp_content = ob_get_contents();
ob_end_clean();
// Set the global level back to the correct object.
$pmpro_level = $pmpro_level_backup;
return $temp_content;
}
/**
* Helper function to filter a "dual" type of attribute that could be true|false or a string.
* Tries to filter as boolean first, then fallback as sanitized string.
*
* @since 1.2
*
* @param bool|string $value The attribute value we want to filter.
* @return bool|string The filtered boolean or string value.
*/
function pmprosus_filter_bool_or_string( $value ) {
$is_bool = filter_var( $value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE );
return ! is_null( $is_bool ) ? $is_bool : sanitize_text_field( $value );
}
/**
* Register blocks for the Block Editor.
*
* @since 1.2
*/
function pmprosus_register_block_type() {
register_block_type( __DIR__ . '/blocks/build/pmpro-signup-block' );
}
add_action( 'init', 'pmprosus_register_block_type' );
/*
Function to add links to the plugin row meta
*/
function pmprosus_plugin_row_meta($links, $file) {
if(strpos($file, 'pmpro-signup-shortcode.php') !== false)
{
$new_links = array(
'<a href="' . esc_url('https://www.paidmembershipspro.com/add-ons/pmpro-signup-shortcode/') . '" title="' . esc_attr( __( 'View Documentation', 'pmpro-signup-shortcode' ) ) . '">' . esc_html__( 'Docs', 'pmpro-signup-shortcode' ) . '</a>',
'<a href="' . esc_url('https://www.paidmembershipspro.com/support/') . '" title="' . esc_attr( __( 'Visit Customer Support Forum', 'pmpro-signup-shortcode' ) ) . '">' . esc_html__( 'Support', 'pmpro-signup-shortcode' ) . '</a>',
);
$links = array_merge($links, $new_links);
}
return $links;
}
add_filter('plugin_row_meta', 'pmprosus_plugin_row_meta', 10, 2);