-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser-fields-shortcode.php
More file actions
79 lines (61 loc) · 2.06 KB
/
user-fields-shortcode.php
File metadata and controls
79 lines (61 loc) · 2.06 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
<?php
/**
* Plugin Name: User Fields Shortcode
* Plugin URI: http://www.yoohooplugins.com/plugins/
* Description: This plugin allows you to display user fields in your posts and pages using shortcodes.
* Version: 1.0
* Author: Yoohoo Plugins
* Author URI: http://www.yoohooplugins.com/
* License: GPLv2 or later
*/
function yh_user_fields_shortcode( $atts ) {
global $current_user;
// Return nothing if the user is logged-out.
if ( ! is_user_logged_in() ) {
return;
}
// Get the key from the shortcode attribute.
$key = esc_attr( $atts['key'] );
$value = $current_user->{$key};
// If it's a date, let's format it better.
if ( $key === 'user_registered' ) {
$value = date_i18n( get_option( 'date_format' ), strtotime( $value ) );
}
return esc_html( $value );
}
add_shortcode( 'user_field', 'yh_user_fields_shortcode' );
/**
* Shortcode for displaying EDD information
*/
function yh_edd_user_fields_shortcode( $atts ) {
global $current_user;
// Return nothing if the user is logged-out.
if ( ! is_user_logged_in() ) {
return;
}
// Make sure EDD is installed.
if ( ! class_exists( 'EDD_Customer' ) ) {
return;
}
////// Possible Keys.
// $customer->name;
// $customer->email;
// $customer->date_created;
// $customer->purchase_count;
// $customer->purchase_value;
// $customer->id; // Customer ID
// $customer->user_id; // WordPress user ID
// $customer->payment_ids
// Get the key from the shortcode attribute.
$key = esc_attr( $atts['key'] );
// Customer information
$customer = new EDD_Customer( $current_user->ID );
$value = $customer->{$key};
if ( $key == 'purchase_value' ) {
$value = edd_currency_filter( edd_format_amount( $value ) ) . ' <span style="font-size:12px">(<a href="https://yoohooplugins.com/account/purchase-history">View all</a>)</span>';
} else {
$value = esc_html( $value );
}
return $value;
}
add_shortcode( 'edd_user_field', 'yh_edd_user_fields_shortcode' );