forked from strangerstudios/paid-memberships-pro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pmpro_member.php
138 lines (126 loc) · 3.36 KB
/
pmpro_member.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
<?php
/*
Shortcode to show a specific user field for current user or specified user ID.
*/
function pmpro_member_shortcode($atts, $content=null, $code='')
{
// $atts ::= array of attributes
// $content ::= text within enclosing form of shortcode element
// $code ::= the shortcode found, when == callback name
// examples: [pmpro_member field='last_name']
global $current_user;
extract(shortcode_atts(array(
'user_id' => $current_user->ID,
'field' => NULL
), $atts));
/*
- pmpro_next_payment()
-
*/
//membership level fields
$pmpro_level_fields = array(
'membership_id',
'membership_name',
'membership_description',
'membership_confirmation',
'membership_initial_payment',
'membership_billing_amount',
'membership_cycle_number',
'membership_cycle_period',
'membership_billing_limit',
'membership_trial_amount',
'membership_trial_limit',
'membership_startdate',
'membership_enddate',
);
//pmpro-related fields stored in user meta
$pmpro_user_meta_fields = array(
'bfirstname',
'blastname',
'baddress1',
'baddress2',
'bcity',
'bstate',
'bzipcode',
'bcountry',
'bphone',
'bemail',
'CardType',
'AccountNumber',
'ExpirationMonth',
'ExpirationYear',
);
//fields stored in wp_users column
$user_column_fields = array(
'user_login',
'user_email',
'user_url',
'user_registered',
'display_name',
);
//date fields
$date_fields = array(
'startdate',
'enddate',
'modified',
'user_registered',
'next_payment_date',
);
//price fields
$price_fields = array(
'initial_payment',
'billing_amount',
'trial_amount',
);
if($field == 'level_cost') {
$membership_level = pmpro_getMembershipLevelForUser($user_id);
if( !empty($membership_level ) )
$r = pmpro_getLevelCost($membership_level, false, true);
else
$r = '';
} elseif($field == 'next_payment_date') {
//next_payment_date
$r = pmpro_next_payment($user_id);
} elseif(in_array( $field, $pmpro_level_fields )) {
//membership level fields
$field = str_replace('membership_', '', $field);
$membership_level = pmpro_getMembershipLevelForUser($user_id);
if(!empty($membership_level))
$r = $membership_level->{$field};
else
$r = '';
} elseif(in_array( $field, $pmpro_user_meta_fields )) {
//pmpro-related fields stored in user meta
$field = 'pmpro_' . $field;
$r = get_user_meta($user_id, $field, true);
} elseif(in_array( $field, $user_column_fields )) {
//wp_users column
$user = get_userdata($user_id);
$r = $user->{$field};
} else {
//assume user meta
$r = get_user_meta($user_id, $field, true);
}
//Check for dates to reformat them.
if(in_array( $field, $date_fields )) {
if(empty($r) || $r == '0000-00-00 00:00:00')
$r = '';
elseif(is_numeric($r))
$r = date_i18n(get_option('date_format'), $r); //timestamp
else
$r = date_i18n(get_option('date_format'), strtotime($r, current_time('timestamp'))); //YYYY-MM-DD/etc format
}
//Check for prices to reformat them.
if(in_array( $field, $price_fields )) {
if(empty($r) || $r == '0.00')
$r = '';
else
$r = pmpro_formatPrice($r);
}
/**
* Filter
*/
$r = apply_filters('pmpro_member_shortcode_field', $r, $user_id, $field);
return $r;
}
add_shortcode('pmpro_member', 'pmpro_member_shortcode');