-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathgo_returns.php
180 lines (161 loc) · 4.49 KB
/
go_returns.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
<?php
function go_return_currency( $user_id ) {
global $wpdb;
$table_name_go_totals = $wpdb->prefix . "go_totals";
$currency = (int) $wpdb->get_var(
$wpdb->prepare(
"SELECT currency
FROM {$table_name_go_totals}
WHERE uid = %d",
$user_id
)
);
return $currency;
}
function go_return_points( $user_id ) {
global $wpdb;
$table_name_go_totals = $wpdb->prefix . "go_totals";
$points = (int) $wpdb->get_var(
$wpdb->prepare(
"SELECT points
FROM {$table_name_go_totals}
WHERE uid = %d",
$user_id
)
);
return $points;
}
function go_return_bonus_currency( $user_id ) {
global $wpdb;
$table_name_go_totals = $wpdb->prefix . "go_totals";
$bonus_currency = (int) $wpdb->get_var(
$wpdb->prepare(
"SELECT bonus_currency
FROM {$table_name_go_totals}
WHERE uid = %d",
$user_id
)
);
return $bonus_currency;
}
function go_return_penalty( $user_id ) {
global $wpdb;
$table_name_go_totals = $wpdb->prefix . "go_totals";
$penalty = (int) $wpdb->get_var(
$wpdb->prepare(
"SELECT penalty
FROM {$table_name_go_totals}
WHERE uid = %d",
$user_id
)
);
return $penalty;
}
function go_return_minutes( $user_id ) {
global $wpdb;
$table_name_go_totals = $wpdb->prefix . "go_totals";
$minutes = (int) $wpdb->get_var(
$wpdb->prepare(
"SELECT minutes
FROM {$table_name_go_totals}
WHERE uid = %d",
$user_id
)
);
return $minutes;
}
function go_display_points( $points ) {
$prefix = go_return_options( 'go_points_prefix' );
$suffix = go_return_options( 'go_points_suffix' );
return "{$prefix} {$points} {$suffix}";
}
function go_display_currency( $currency ) {
$prefix = go_return_options( 'go_currency_prefix' );
$suffix = go_return_options( 'go_currency_suffix' );
return "{$prefix} {$currency} {$suffix}";
}
function go_display_bonus_currency( $bonus_currency ) {
$prefix = go_return_options( 'go_bonus_currency_prefix' );
$suffix = go_return_options( 'go_bonus_currency_suffix' );
return "{$prefix} {$bonus_currency} {$suffix}";
}
function go_display_penalty( $penalty ) {
$prefix = go_return_options( 'go_penalty_prefix' );
$suffix = go_return_options( 'go_penalty_suffix' );
return "{$prefix} {$penalty} {$suffix}";
}
function go_display_minutes( $minutes ) {
$prefix = go_return_options( 'go_minutes_prefix' );
$suffix = go_return_options( 'go_minutes_suffix' );
return "{$prefix} {$minutes} {$suffix}";
}
/**
* Output currency formatted for the admin bar dropdown.
*
* Outputs any currency in the format (without quotations): "1234 Experience (XP)".
*
* @since 2.5.6
*
* @param STRING $currency_type Contains the base name of the currency to be displayed
* (e.g. "points", "currency", "bonus_currency", or "penalty" ).
* @param BOOLEAN $output Optional. TRUE will echo the currency, FALSE will return it (default).
* @return STRING/NULL Either echos or returns the currency. Returns FALSE on failure.
*/
function go_display_longhand_currency ( $currency_type, $amount, $output = false ) {
if ( "points" === $currency_type ||
"currency" === $currency_type ||
"bonus_currency" === $currency_type ||
"penalty" === $currency_type ||
"minutes" === $currency_type
) {
$currency_name = go_return_options( "go_{$currency_type}_name" );
$suffix = go_return_options( "go_{$currency_type}_suffix" );
$str = "{$amount} {$currency_name} ({$suffix})";
if ( $output ) {
echo $str;
} else {
return $str;
}
} else {
return false;
}
}
function go_filter_focuses( $elem ) {
if ( strpos( $elem, ':' ) === false && strpos( $elem, 'No '.go_return_options( 'go_focus_name' ) ) === false) {
return true;
} else {
return false;
}
}
function go_display_user_focuses( $user_id ) {
$user_focuses = get_user_meta( $user_id , 'go_focus', true );
if ( ! empty( $user_focuses ) ) {
if ( ! is_array( $user_focuses) ) {
$output = $user_focuses;
} else {
$filtered_user_focuses = array_filter( $user_focuses );
if ( count( array_unique( $filtered_user_focuses ) ) === 1 && reset( $filtered_user_focuses ) === ':' ) {
$output = 'No '.go_return_options( 'go_focus_name' );
} else {
$value = array_filter( $filtered_user_focuses, 'go_filter_focuses' );
$output = implode( ', ', $value );
}
}
} else {
$output = 'No '.go_return_options( 'go_focus_name' );
}
return $output;
}
function go_return_badge_count( $user_id ) {
global $wpdb;
$badge_count = (int) $wpdb->get_var(
$wpdb->prepare(
"SELECT badge_count
FROM {$wpdb->prefix}go_totals
WHERE uid = %d",
$user_id
)
);
return $badge_count;
}
?>