-
Notifications
You must be signed in to change notification settings - Fork 361
/
pmpro_account.php
428 lines (379 loc) · 21.9 KB
/
pmpro_account.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
<?php
/*
Shortcode to show membership account information
*/
function pmpro_shortcode_account($atts, $content=null, $code="")
{
global $wpdb, $current_user;
// $atts ::= array of attributes
// $content ::= text within enclosing form of shortcode element
// $code ::= the shortcode found, when == callback name
// examples: [pmpro_account] [pmpro_account sections="membership,profile"/]
extract(shortcode_atts(array(
'section' => '',
'sections' => 'membership,profile,invoices,links',
'title' => null,
), $atts));
// Did they use 'section' instead of 'sections'?
if ( ! empty( $section ) ) {
$sections = $section;
}
// Extract the user-defined sections for the shortcode.
$sections = array_map( 'trim', explode( ',', $sections ) );
// Start the output buffer to capture the content of the shortcode.
ob_start();
// If multiple sections are being shown, set title to null.
// Titles can only be changed from the default if only one section is being shown.
if ( count( $sections ) > 1 ) {
$title = null;
}
// We want to show the actual levels for admins.
add_filter( 'pmpro_disable_admin_membership_access', '__return_true', 15 );
// Get the current user's membership levels.
$mylevels = pmpro_getMembershipLevelsForUser();
// Remove the filter so we don't mess up other stuff.
remove_filter( 'pmpro_disable_admin_membership_access', '__return_true', 15 );
// Just to be sure, only inclue the levels that allow signups.
$pmpro_levels = pmpro_getAllLevels();
?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro' ) ); ?>">
<?php if ( in_array( 'profile', $sections ) ) {
?>
<section id="pmpro_account-profile" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_section', 'pmpro_account-profile' ) ); ?>">
<?php
if ( '' !== $title ) { // Check if title is being forced to not show.
// If a custom title was not set, use the default. Otherwise, show the custom title.
?>
<h2 class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_section_title pmpro_font-x-large' ) ); ?>"><?php echo esc_html( null === $title ? __( 'My Account', 'paid-memberships-pro' ) : $title ); ?></h2>
<?php
}
?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card' ) ); ?>">
<?php
// Get the current user.
wp_get_current_user();
?>
<h3 class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card_title pmpro_font-large pmpro_heading-with-avatar' ) ); ?>">
<?php echo get_avatar( $current_user->ID, 48 ); ?>
<?php
/* translators: the current user's display name */
printf( esc_html__( 'Welcome, %s', 'paid-memberships-pro' ), esc_html( $current_user->display_name ) );
?>
</h3>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card_content' ) ); ?>">
<ul class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list pmpro_list-plain' ) ); ?>">
<?php do_action('pmpro_account_bullets_top');?>
<li class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list_item' ) ); ?>"><strong><?php esc_html_e( 'Username', 'paid-memberships-pro' ); ?>:</strong> <?php echo esc_html( $current_user->user_login ); ?></li>
<li class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list_item' ) ); ?>"><strong><?php esc_html_e( 'Email', 'paid-memberships-pro' );?>:</strong> <?php echo esc_html( $current_user->user_email ); ?></li>
<?php do_action('pmpro_account_bullets_bottom');?>
</ul>
</div> <!-- end pmpro_card_content -->
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card_actions' ) ); ?>">
<?php
// Get the edit profile and change password links if 'Member Profile Edit Page' is set.
if ( ! empty( get_option( 'pmpro_member_profile_edit_page_id' ) ) ) {
$edit_profile_url = pmpro_url( 'member_profile_edit' );
$change_password_url = add_query_arg( 'view', 'change-password', pmpro_url( 'member_profile_edit' ) );
} elseif ( ! pmpro_block_dashboard() ) {
$edit_profile_url = admin_url( 'profile.php' );
$change_password_url = admin_url( 'profile.php' );
}
// Build the links to return.
$pmpro_profile_action_links = array();
if ( ! empty( $edit_profile_url) ) {
$pmpro_profile_action_links['edit-profile'] = sprintf( '<a id="pmpro_actionlink-profile" href="%s">%s</a>', esc_url( $edit_profile_url ), esc_html__( 'Edit Profile', 'paid-memberships-pro' ) );
}
if ( ! empty( $change_password_url ) ) {
$pmpro_profile_action_links['change-password'] = sprintf( '<a id="pmpro_actionlink-change-password" href="%s">%s</a>', esc_url( $change_password_url ), esc_html__( 'Change Password', 'paid-memberships-pro' ) );
}
$pmpro_profile_action_links['logout'] = sprintf( '<a id="pmpro_actionlink-logout" href="%s">%s</a>', esc_url( wp_logout_url() ), esc_html__( 'Log Out', 'paid-memberships-pro' ) );
// Wrap each action link item in a <span>
$pmpro_profile_action_links = array_map( function( $link ) {
return '<span class="' . esc_attr( pmpro_get_element_class( 'pmpro_card_action' ) ) . '">' . $link . '</span>';
}, $pmpro_profile_action_links );
/**
* Filter the profile action links.
*
* @param array $pmpro_profile_action_links Profile action links.
* @return array $pmpro_profile_action_links Profile action links.
*/
$pmpro_profile_action_links = apply_filters( 'pmpro_account_profile_action_links', $pmpro_profile_action_links );
$allowed_html = array(
'a' => array (
'class' => array(),
'href' => array(),
'id' => array(),
'target' => array(),
'title' => array(),
),
'span' => array(
'class' => array(),
),
);
echo wp_kses( implode( '<span class="' . esc_attr( pmpro_get_element_class( 'pmpro_card_action_separator' ) ) . '">' . pmpro_actions_nav_separator() . '</span>', $pmpro_profile_action_links ), $allowed_html );
?>
</div> <!-- end pmpro_card_actions -->
</div> <!-- end pmpro_card -->
</section> <!-- end pmpro_account-profile -->
<?php } ?>
<?php if ( in_array( 'membership', $sections) || in_array( 'memberships', $sections ) ) {
?>
<section id="pmpro_account-membership" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_section', 'pmpro_account-membership' ) ); ?>">
<?php
if ( '' !== $title ) { // Check if title is being forced to not show.
// If a custom title was not set, use the default. Otherwise, show the custom title.
?>
<h2 class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_section_title pmpro_font-x-large' ) ); ?>"><?php echo esc_html( null === $title ? __( 'My Memberships', 'paid-memberships-pro' ) : $title ); ?></h2>
<?php
}
?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_section_content' ) ); ?>">
<?php if ( empty( $mylevels ) ) {
$url = pmpro_url( 'levels' );
?>
<div id="pmpro_account-membership-none" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card' ) ); ?>">
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card_content' ) ); ?>">
<p><?php echo wp_kses( sprintf( __( "You do not have an active membership. <a href='%s'>Choose a membership level.</a>", 'paid-memberships-pro' ), $url ), array( 'a' => array( 'href' => array() ) ) ); ?></p>
</div> <!-- end pmpro_card_content -->
</div> <!-- end pmpro_card -->
<?php
} else {
foreach ( $mylevels as $level ) {
?>
<div id="pmpro_account-membership-<?php echo esc_attr( $level->ID ); ?>" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card' ) ); ?>">
<h3 class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card_title pmpro_font-large' ) ); ?>"><?php echo esc_html( $level->name ); ?></h3>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card_content' ) ); ?>">
<ul class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list pmpro_list-plain pmpro_list-with-labels pmpro_cols-3' ) ); ?>">
<?php
// Show information about the first active subscription for this level.
$subscription = null;
$subscriptions = PMPro_Subscription::get_subscriptions_for_user( $current_user->ID, $level->id );
if ( ! empty( $subscriptions ) ) {
$subscription = $subscriptions[0];
?>
<li class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list_item' ) ); ?>">
<span class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list_item_label' ) ); ?>"><?php esc_html_e( 'Subscription', 'paid-memberships-pro' ); ?></span>
<span class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list_item_value' ) ); ?>"><?php echo esc_html( $subscription->get_cost_text() ); ?></span>
</li>
<li class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list_item' ) ); ?>">
<span class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list_item_label' ) ); ?>"><?php esc_html_e( 'Next payment on', 'paid-memberships-pro' ); ?></span>
<span class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list_item_value' ) ); ?>"><?php echo esc_html( $subscription->get_next_payment_date( get_option( 'date_format' ) ) ); ?></span>
</li>
<?php
}
$expiration_text = pmpro_get_membership_expiration_text( $level, $current_user, '' );
if ( ! empty( $expiration_text ) ) {
?>
<li class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list_item' ) ); ?>">
<span class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list_item_label' ) ); ?>"><?php esc_html_e( 'Expires', 'paid-memberships-pro' ); ?></span>
<span class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list_item_value' ) ); ?>"><?php echo wp_kses_post( $expiration_text ); ?></span>
</li>
<?php
}
?>
</ul> <!-- end pmpro_list -->
</div> <!-- end pmpro_card_content -->
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card_actions' ) ); ?>">
<?php
/**
* Fires before the member action links.
*/
do_action( 'pmpro_member_action_links_before' );
?>
<?php
// Build the links to return.
$pmpro_member_action_links = array();
if ( array_key_exists($level->id, $pmpro_levels) && pmpro_isLevelExpiringSoon( $level ) ) {
$pmpro_member_action_links['renew'] = '<a id="pmpro_actionlink-renew" href="' . esc_url( add_query_arg( 'pmpro_level', $level->id, pmpro_url( 'checkout', '', 'https' ) ) ) . '" aria-label="' . esc_attr( sprintf( esc_html__( 'Renew %1$s Membership', 'paid-memberships-pro' ), $level->name ) ) . '">' . esc_html__( 'Renew', 'paid-memberships-pro' ) . '</a>';
}
// Check if we should show the update billing link.
if ( ! empty( $subscription ) ) {
// Check if this subscription is for the default gateaway (we can currently only update billing info for the default gateway).
if ( $subscription->get_gateway() == get_option( 'pmpro_gateway' ) ) {
// Check if the gateway supports updating billing info.
$gateway_obj = $subscription->get_gateway_object();
if ( ! empty( $gateway_obj ) && method_exists( $gateway_obj, 'supports' ) && $gateway_obj->supports( 'payment_method_updates' ) ) {
// Make sure that the subscription has an order, which is necessary to update.
$newest_orders = $subscription->get_orders( array( 'limit' => 1 ) );
if ( ! empty( $newest_orders ) ) {
$pmpro_member_action_links['update-billing'] = sprintf( '<a id="pmpro_actionlink-update-billing" href="%s">%s</a>', pmpro_url( 'billing', 'pmpro_subscription_id=' . $subscription->get_id(), 'https' ), esc_html__( 'Update Billing Info', 'paid-memberships-pro' ) );
}
}
}
}
// Check if we should show the change membership level link.
$show_change_link = false;
// Get the group for this level.
$level_group_id = pmpro_get_group_id_for_level( $level->ID );
$level_group = pmpro_get_level_group( $level_group_id );
// Show the link if there is more than one level available.
if ( count( $pmpro_levels ) > 1 ) {
$show_change_link = true;
}
// Do not show the link if the group does not allow multiple selections.
if ( ! empty( $level_group ) && ! empty( $level_group->allow_multiple_selections ) ) {
$show_change_link = false;
}
if ( ! empty( $show_change_link ) ) {
$pmpro_member_action_links['change'] = '<a id="pmpro_actionlink-change" href="' . esc_url( pmpro_url( 'levels' ) ) . '" aria-label="' . esc_attr( sprintf( esc_html__( 'Change %1$s Membership', 'paid-memberships-pro' ), $level->name ) ) . '">' . esc_html__( 'Change', 'paid-memberships-pro' ) . '</a>';
}
$pmpro_member_action_links['cancel'] = '<a id="pmpro_actionlink-cancel" href="' . esc_url( add_query_arg( 'levelstocancel', $level->id, pmpro_url( 'cancel' ) ) ) . '" aria-label="' . esc_attr( sprintf( esc_html__( 'Cancel %1$s Membership', 'paid-memberships-pro' ), $level->name ) ) . '">' . esc_html__( 'Cancel', 'paid-memberships-pro' ) . '</a>';
// Wrap each action link item in a <span>
$pmpro_member_action_links = array_map( function( $link ) {
return '<span class="' . esc_attr( pmpro_get_element_class( 'pmpro_card_action' ) ) . '">' . $link . '</span>';
}, $pmpro_member_action_links );
/**
* Filter the member action links.
*
* @param array $pmpro_member_action_links Member action links.
* @param int $level->id The ID of the membership level.
* @return array $pmpro_member_action_links Member action links.
*/
$pmpro_member_action_links = apply_filters( 'pmpro_member_action_links', $pmpro_member_action_links, $level->id );
$allowed_html = array(
'a' => array (
'class' => array(),
'href' => array(),
'id' => array(),
'target' => array(),
'title' => array(),
'aria-label' => array(),
),
'span' => array(
'class' => array(),
),
);
echo wp_kses( implode( '<span class="' . esc_attr( pmpro_get_element_class( 'pmpro_card_action_separator' ) ) . '">' . pmpro_actions_nav_separator() . '</span>', $pmpro_member_action_links ), $allowed_html );
?>
<?php
/**
* Fires after the member action links.
*/
do_action( 'pmpro_member_action_links_after' );
?>
</div> <!-- end pmpro_card_actions -->
</div> <!-- end pmpro_card -->
<?php } ?>
<?php } ?>
</div> <!-- end pmpro_section_content -->
</section> <!-- end pmpro_account-membership -->
<?php } ?>
<?php if ( in_array( 'invoices', $sections ) ) {
// Get the last 6 orders for the current user.
$orders = MemberOrder::get_orders(
array(
'limit' => 6,
'status' => array( 'pending', 'refunded', 'success' ),
'user_id' => $current_user->ID,
)
);
// Show the orders section if there are orders.
if ( ! empty( $orders ) ) {
?>
<section id="pmpro_account-orders" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_section', 'pmpro_account-orders' ) ); ?>">
<?php
if ( '' !== $title ) { // Check if title is being forced to not show.
// If a custom title was not set, use the default. Otherwise, show the custom title.
?>
<h2 class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_section_title pmpro_font-x-large' ) ); ?>"><?php echo esc_html( null === $title ? __( 'Order History', 'paid-memberships-pro' ) : $title ); ?></h2>
<?php
}
?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card' ) ); ?>">
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card_content' ) ); ?>">
<table class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_table pmpro_table_orders', 'pmpro_table_orders' ) ); ?>">
<thead>
<tr>
<th class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_table_order-date' ) ); ?>"><?php esc_html_e( 'Date', 'paid-memberships-pro' ); ?></th>
<th class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_table_order-level' ) ); ?>"><?php esc_html_e( 'Level', 'paid-memberships-pro' ); ?></th>
<th class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_table_order-total' ) ); ?>"><?php esc_html_e( 'Total', 'paid-memberships-pro' ); ?></th>
<th class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_table_order-status' ) ); ?>"><?php esc_html_e( 'Status', 'paid-memberships-pro'); ?></th>
</tr>
</thead>
<tbody>
<?php
$count = 0;
foreach ( $orders as $order ) {
// Only show the first 5 orders.
if ( $count++ > 4 ) {
break;
}
// Get a member order object.
$order_id = $order->id;
$order = new MemberOrder;
$order->getMemberOrderByID($order_id);
$order->getMembershipLevel();
// Set the display status and tag style.
if ( in_array( $order->status, array( '', 'success', 'cancelled' ) ) ) {
$display_status = esc_html__( 'Paid', 'paid-memberships-pro' );
$tag_style = 'success';
} elseif ( $order->status == 'pending' ) {
// Some Add Ons set status to pending.
$display_status = esc_html__( 'Pending', 'paid-memberships-pro' );
$tag_style = 'alert';
} elseif ( $order->status == 'refunded' ) {
$display_status = esc_html__( 'Refunded', 'paid-memberships-pro' );
$tag_style = 'error';
}
?>
<tr id="pmpro_table_order-<?php echo esc_attr( $order->code ); ?>">
<th class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_table_order-date' ) ); ?>" data-title="<?php esc_attr_e( 'Date', 'paid-memberships-pro' ); ?>"><a href="<?php echo esc_url( pmpro_url( "invoice", "?invoice=" . $order->code ) ) ?>"><?php echo esc_html( date_i18n(get_option("date_format"), $order->getTimestamp()) )?></a></th>
<td class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_table_order-level' ) ); ?>" data-title="<?php esc_attr_e( 'Level', 'paid-memberships-pro' ); ?>"><?php if(!empty($order->membership_level)) echo esc_html( $order->membership_level->name ); else echo esc_html__("N/A", 'paid-memberships-pro' );?></td>
<td class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_table_order-amount' ) ); ?>" data-title="<?php esc_attr_e( 'Amount', 'paid-memberships-pro' ); ?>"><?php
//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo pmpro_escape_price( $order->get_formatted_total() ); ?></td>
<td class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_table_order-status' ) ); ?>" data-title="<?php esc_attr_e( 'Status', 'paid-memberships-pro' ); ?>">
<span class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_tag pmpro_tag-' . $tag_style ) ); ?>"><?php echo esc_html( $display_status ); ?></span>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div> <!-- end pmpro_card_content -->
<?php
// Show the "View All Orders" link if there are more than 5 orders.
if ( $count == 6 ) {
?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card_actions' ) ); ?>">
<a href="<?php echo esc_url( pmpro_url( 'invoice' ) ); ?>"><?php esc_html_e( 'View All Orders →', 'paid-memberships-pro' );?></a>
</div>
<?php
}
?>
</div> <!-- end pmpro_card -->
</section> <!-- end pmpro_account-orders -->
<?php } ?>
<?php } ?>
<?php if ( in_array('links', $sections ) && ( has_filter( 'pmpro_member_links_top' ) || has_filter( 'pmpro_member_links_bottom' ) ) ) { ?>
<section id="pmpro_account-links" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_section', 'pmpro_account-links' ) ); ?>">
<?php
if ( '' !== $title ) { // Check if title is being forced to not show.
// If a custom title was not set, use the default. Otherwise, show the custom title.
?>
<h2 class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_section_title pmpro_font-x-large' ) ); ?>"><?php echo esc_html( null === $title ? __( 'Member Links', 'paid-memberships-pro' ) : $title ); ?></h2>
<?php
}
?>
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card' ) ); ?>">
<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_card_content' ) ); ?>">
<ul class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_list' ) ); ?>">
<?php
do_action("pmpro_member_links_top");
?>
<?php
do_action("pmpro_member_links_bottom");
?>
</ul>
</div> <!-- end pmpro_card_content -->
</div> <!-- end pmpro_card -->
</section> <!-- end pmpro_account-links -->
<?php } ?>
</div> <!-- end pmpro -->
<?php
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_shortcode('pmpro_account', 'pmpro_shortcode_account');