1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Currency Functions |
4
|
|
|
* |
5
|
|
|
* @package Give |
6
|
|
|
* @subpackage Functions |
7
|
|
|
* @copyright Copyright (c) 2017, WordImpress |
8
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License |
9
|
|
|
* @since 1.8.17 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Get the set currency |
14
|
|
|
* |
15
|
|
|
* @since 1.0 |
16
|
|
|
* @since 1.8.15 Upgrade function to handle dynamic currency |
17
|
|
|
* |
18
|
|
|
* @param int $donation_or_form_id Donation or Form ID |
19
|
|
|
* @param array|object $args Additional data |
20
|
|
|
* |
21
|
|
|
* @return string The currency code |
22
|
|
|
*/ |
23
|
|
|
function give_get_currency( $donation_or_form_id = null, $args = array() ) { |
24
|
|
|
|
25
|
|
|
// Get currency from donation |
26
|
|
|
if ( is_numeric( $donation_or_form_id ) && 'give_payment' === get_post_type( $donation_or_form_id ) ) { |
27
|
|
|
$donation_meta = give_get_meta( $donation_or_form_id, '_give_payment_meta', true ); |
28
|
|
|
|
29
|
|
|
if ( ! empty( $donation_meta['currency'] ) ) { |
30
|
|
|
$currency = $donation_meta['currency']; |
31
|
|
|
} else { |
32
|
|
|
$currency = give_get_option( 'currency', 'USD' ); |
33
|
|
|
} |
34
|
|
|
} else { |
35
|
|
|
$currency = give_get_option( 'currency', 'USD' ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Filter the currency on basis of donation or form id or addtional data. |
40
|
|
|
* |
41
|
|
|
* @since 1.0 |
42
|
|
|
*/ |
43
|
|
|
return apply_filters( 'give_currency', $currency, $donation_or_form_id, $args ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get the set currency position |
48
|
|
|
* |
49
|
|
|
* @since 1.3.6 |
50
|
|
|
* |
51
|
|
|
* @return string The currency code |
52
|
|
|
*/ |
53
|
|
|
function give_get_currency_position() { |
54
|
|
|
|
55
|
|
|
$currency_pos = give_get_option( 'currency_position', 'before' ); |
56
|
|
|
|
57
|
|
|
return apply_filters( 'give_currency_position', $currency_pos ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get Currencies List |
62
|
|
|
* |
63
|
|
|
* @since 1.8.17 |
64
|
|
|
* |
65
|
|
|
* @return array $currencies A list of the available currencies |
66
|
|
|
*/ |
67
|
|
|
function give_get_currencies_list() { |
68
|
|
|
$currencies = array( |
69
|
|
|
'USD' => array( |
70
|
|
|
'admin_label' => __( 'US Dollars ($)', 'give' ), |
71
|
|
|
'symbol' => '$', |
72
|
|
|
'setting' => array( |
73
|
|
|
'currency_position' => 'before', |
74
|
|
|
'thousands_separator' => ',', |
75
|
|
|
'decimal_separator' => '.', |
76
|
|
|
'number_decimals' => 2, |
77
|
|
|
), |
78
|
|
|
), |
79
|
|
|
'EUR' => array( |
80
|
|
|
'admin_label' => __( 'Euros (€)', 'give' ), |
81
|
|
|
'symbol' => '€', |
82
|
|
|
'setting' => array( |
83
|
|
|
'currency_position' => 'before', |
84
|
|
|
'thousands_separator' => '.', |
85
|
|
|
'decimal_separator' => ',', |
86
|
|
|
'number_decimals' => 2, |
87
|
|
|
), |
88
|
|
|
), |
89
|
|
|
'GBP' => array( |
90
|
|
|
'admin_label' => __( 'Pounds Sterling (£)', 'give' ), |
91
|
|
|
'symbol' => '£', |
92
|
|
|
'setting' => array( |
93
|
|
|
'currency_position' => 'before', |
94
|
|
|
'thousands_separator' => ',', |
95
|
|
|
'decimal_separator' => '.', |
96
|
|
|
'number_decimals' => 2, |
97
|
|
|
), |
98
|
|
|
), |
99
|
|
|
'AUD' => array( |
100
|
|
|
'admin_label' => __( 'Australian Dollars ($)', 'give' ), |
101
|
|
|
'symbol' => '$', |
102
|
|
|
'setting' => array( |
103
|
|
|
'currency_position' => 'before', |
104
|
|
|
'thousands_separator' => ',', |
105
|
|
|
'decimal_separator' => '.', |
106
|
|
|
'number_decimals' => 2, |
107
|
|
|
), |
108
|
|
|
), |
109
|
|
|
'BRL' => array( |
110
|
|
|
'admin_label' => __( 'Brazilian Real (R$)', 'give' ), |
111
|
|
|
'symbol' => 'R$', |
112
|
|
|
'setting' => array( |
113
|
|
|
'currency_position' => 'before', |
114
|
|
|
'thousands_separator' => ',', |
115
|
|
|
'decimal_separator' => '.', |
116
|
|
|
'number_decimals' => 2, |
117
|
|
|
), |
118
|
|
|
), |
119
|
|
|
'CAD' => array( |
120
|
|
|
'admin_label' => __( 'Canadian Dollars ($)', 'give' ), |
121
|
|
|
'symbol' => '$', |
122
|
|
|
'setting' => array( |
123
|
|
|
'currency_position' => 'before', |
124
|
|
|
'thousands_separator' => ',', |
125
|
|
|
'decimal_separator' => '.', |
126
|
|
|
'number_decimals' => 2, |
127
|
|
|
), |
128
|
|
|
), |
129
|
|
|
'CZK' => array( |
130
|
|
|
'admin_label' => __( 'Czech Koruna (Kč)', 'give' ), |
131
|
|
|
'symbol' => 'Kč', |
132
|
|
|
'setting' => array( |
133
|
|
|
'currency_position' => 'after', |
134
|
|
|
'thousands_separator' => ',', |
135
|
|
|
'decimal_separator' => '.', |
136
|
|
|
'number_decimals' => 2, |
137
|
|
|
), |
138
|
|
|
), |
139
|
|
|
'DKK' => array( |
140
|
|
|
'admin_label' => __( 'Danish Krone (kr.)', 'give' ), |
141
|
|
|
'symbol' => ' kr. ', |
142
|
|
|
'setting' => array( |
143
|
|
|
'currency_position' => 'before', |
144
|
|
|
'thousands_separator' => ',', |
145
|
|
|
'decimal_separator' => '.', |
146
|
|
|
'number_decimals' => 2, |
147
|
|
|
), |
148
|
|
|
), |
149
|
|
|
'HKD' => array( |
150
|
|
|
'admin_label' => __( 'Hong Kong Dollar ($)', 'give' ), |
151
|
|
|
'symbol' => '$', |
152
|
|
|
'setting' => array( |
153
|
|
|
'currency_position' => 'before', |
154
|
|
|
'thousands_separator' => ',', |
155
|
|
|
'decimal_separator' => '.', |
156
|
|
|
'number_decimals' => 2, |
157
|
|
|
), |
158
|
|
|
), |
159
|
|
|
'HUF' => array( |
160
|
|
|
'admin_label' => __( 'Hungarian Forint (Ft)', 'give' ), |
161
|
|
|
'symbol' => 'Ft', |
162
|
|
|
'setting' => array( |
163
|
|
|
'currency_position' => 'after', |
164
|
|
|
'thousands_separator' => ',', |
165
|
|
|
'decimal_separator' => '.', |
166
|
|
|
'number_decimals' => 2, |
167
|
|
|
), |
168
|
|
|
), |
169
|
|
|
'ILS' => array( |
170
|
|
|
'admin_label' => __( 'Israeli Shekel (₪)', 'give' ), |
171
|
|
|
'symbol' => '₪', |
172
|
|
|
'setting' => array( |
173
|
|
|
'currency_position' => 'after', |
174
|
|
|
'thousands_separator' => ',', |
175
|
|
|
'decimal_separator' => '.', |
176
|
|
|
'number_decimals' => 2, |
177
|
|
|
), |
178
|
|
|
), |
179
|
|
|
'JPY' => array( |
180
|
|
|
'admin_label' => __( 'Japanese Yen (¥)', 'give' ), |
181
|
|
|
'symbol' => '¥', |
182
|
|
|
'setting' => array( |
183
|
|
|
'currency_position' => 'before', |
184
|
|
|
'thousands_separator' => ',', |
185
|
|
|
'decimal_separator' => '.', |
186
|
|
|
'number_decimals' => 0, |
187
|
|
|
), |
188
|
|
|
), |
189
|
|
|
'MYR' => array( |
190
|
|
|
'admin_label' => __( 'Malaysian Ringgits (RM)', 'give' ), |
191
|
|
|
'symbol' => 'RM', |
192
|
|
|
'setting' => array( |
193
|
|
|
'currency_position' => 'before', |
194
|
|
|
'thousands_separator' => ',', |
195
|
|
|
'decimal_separator' => '.', |
196
|
|
|
'number_decimals' => 2, |
197
|
|
|
), |
198
|
|
|
), |
199
|
|
|
'MXN' => array( |
200
|
|
|
'admin_label' => __( 'Mexican Peso ($)', 'give' ), |
201
|
|
|
'symbol' => '$', |
202
|
|
|
'setting' => array( |
203
|
|
|
'currency_position' => 'before', |
204
|
|
|
'thousands_separator' => ',', |
205
|
|
|
'decimal_separator' => '.', |
206
|
|
|
'number_decimals' => 2, |
207
|
|
|
), |
208
|
|
|
), |
209
|
|
|
'MAD' => array( |
210
|
|
|
'admin_label' => __( 'Moroccan Dirham (.د.م)', 'give' ), |
211
|
|
|
'symbol' => '.د.م', |
212
|
|
|
'setting' => array( |
213
|
|
|
'currency_position' => 'before', |
214
|
|
|
'thousands_separator' => ',', |
215
|
|
|
'decimal_separator' => '.', |
216
|
|
|
'number_decimals' => 2, |
217
|
|
|
), |
218
|
|
|
), |
219
|
|
|
'NZD' => array( |
220
|
|
|
'admin_label' => __( 'New Zealand Dollar ($)', 'give' ), |
221
|
|
|
'symbol' => '$', |
222
|
|
|
'setting' => array( |
223
|
|
|
'currency_position' => 'before', |
224
|
|
|
'thousands_separator' => ',', |
225
|
|
|
'decimal_separator' => '.', |
226
|
|
|
'number_decimals' => 2, |
227
|
|
|
), |
228
|
|
|
), |
229
|
|
|
'NOK' => array( |
230
|
|
|
'admin_label' => __( 'Norwegian Krone (Kr.)', 'give' ), |
231
|
|
|
'symbol' => 'kr.', |
232
|
|
|
'setting' => array( |
233
|
|
|
'currency_position' => 'before', |
234
|
|
|
'thousands_separator' => '.', |
235
|
|
|
'decimal_separator' => ',', |
236
|
|
|
'number_decimals' => 2, |
237
|
|
|
), |
238
|
|
|
), |
239
|
|
|
'PHP' => array( |
240
|
|
|
'admin_label' => __( 'Philippine Pesos (₱)', 'give' ), |
241
|
|
|
'symbol' => '₱', |
242
|
|
|
'setting' => array( |
243
|
|
|
'currency_position' => 'before', |
244
|
|
|
'thousands_separator' => ',', |
245
|
|
|
'decimal_separator' => '.', |
246
|
|
|
'number_decimals' => 2, |
247
|
|
|
), |
248
|
|
|
), |
249
|
|
|
'PLN' => array( |
250
|
|
|
'admin_label' => __( 'Polish Zloty (zł)', 'give' ), |
251
|
|
|
'symbol' => 'zł', |
252
|
|
|
'setting' => array( |
253
|
|
|
'currency_position' => 'after', |
254
|
|
|
'thousands_separator' => ' ', |
255
|
|
|
'decimal_separator' => ',', |
256
|
|
|
'number_decimals' => 2, |
257
|
|
|
), |
258
|
|
|
), |
259
|
|
|
'SGD' => array( |
260
|
|
|
'admin_label' => __( 'Singapore Dollar ($)', 'give' ), |
261
|
|
|
'symbol' => '$', |
262
|
|
|
'setting' => array( |
263
|
|
|
'currency_position' => 'before', |
264
|
|
|
'thousands_separator' => ',', |
265
|
|
|
'decimal_separator' => '.', |
266
|
|
|
'number_decimals' => 2, |
267
|
|
|
), |
268
|
|
|
), |
269
|
|
|
'KRW' => array( |
270
|
|
|
'admin_label' => __( 'South Korean Won (₩)', 'give' ), |
271
|
|
|
'symbol' => '₩', |
272
|
|
|
'setting' => array( |
273
|
|
|
'currency_position' => 'before', |
274
|
|
|
'thousands_separator' => ',', |
275
|
|
|
'decimal_separator' => '.', |
276
|
|
|
'number_decimals' => 0, |
277
|
|
|
), |
278
|
|
|
), |
279
|
|
|
'ZAR' => array( |
280
|
|
|
'admin_label' => __( 'South African Rand (R)', 'give' ), |
281
|
|
|
'symbol' => 'R', |
282
|
|
|
'setting' => array( |
283
|
|
|
'currency_position' => 'before', |
284
|
|
|
'thousands_separator' => ' ', |
285
|
|
|
'decimal_separator' => '.', |
286
|
|
|
'number_decimals' => 2, |
287
|
|
|
), |
288
|
|
|
), |
289
|
|
|
'SEK' => array( |
290
|
|
|
'admin_label' => __( 'Swedish Krona (kr)', 'give' ), |
291
|
|
|
'symbol' => ' kr. ', |
292
|
|
|
'setting' => array( |
293
|
|
|
'currency_position' => 'before', |
294
|
|
|
'thousands_separator' => ' ', |
295
|
|
|
'decimal_separator' => ',', |
296
|
|
|
'number_decimals' => 2, |
297
|
|
|
), |
298
|
|
|
), |
299
|
|
|
'CHF' => array( |
300
|
|
|
'admin_label' => __( 'Swiss Franc (Fr)', 'give' ), |
301
|
|
|
'symbol' => 'Fr', |
302
|
|
|
'setting' => array( |
303
|
|
|
'currency_position' => 'before', |
304
|
|
|
'thousands_separator' => ',', |
305
|
|
|
'decimal_separator' => '.', |
306
|
|
|
'number_decimals' => 2, |
307
|
|
|
), |
308
|
|
|
), |
309
|
|
|
'TWD' => array( |
310
|
|
|
'admin_label' => __( 'Taiwan New Dollars (NT$)', 'give' ), |
311
|
|
|
'symbol' => 'NT$', |
312
|
|
|
'setting' => array( |
313
|
|
|
'currency_position' => 'before', |
314
|
|
|
'thousands_separator' => '\'', |
315
|
|
|
'decimal_separator' => '.', |
316
|
|
|
'number_decimals' => 2, |
317
|
|
|
), |
318
|
|
|
), |
319
|
|
|
'THB' => array( |
320
|
|
|
'admin_label' => __( 'Thai Baht (฿)', 'give' ), |
321
|
|
|
'symbol' => '฿', |
322
|
|
|
'setting' => array( |
323
|
|
|
'currency_position' => 'before', |
324
|
|
|
'thousands_separator' => ',', |
325
|
|
|
'decimal_separator' => '.', |
326
|
|
|
'number_decimals' => 2, |
327
|
|
|
), |
328
|
|
|
), |
329
|
|
|
'INR' => array( |
330
|
|
|
'admin_label' => __( 'Indian Rupee (₹)', 'give' ), |
331
|
|
|
'symbol' => '₹', |
332
|
|
|
'setting' => array( |
333
|
|
|
'currency_position' => 'before', |
334
|
|
|
'thousands_separator' => ',', |
335
|
|
|
'decimal_separator' => '.', |
336
|
|
|
'number_decimals' => 2, |
337
|
|
|
), |
338
|
|
|
), |
339
|
|
|
'TRY' => array( |
340
|
|
|
'admin_label' => __( 'Turkish Lira (₺)', 'give' ), |
341
|
|
|
'symbol' => '₺', |
342
|
|
|
'setting' => array( |
343
|
|
|
'currency_position' => 'after', |
344
|
|
|
'thousands_separator' => ',', |
345
|
|
|
'decimal_separator' => '.', |
346
|
|
|
'number_decimals' => 2, |
347
|
|
|
), |
348
|
|
|
), |
349
|
|
|
'IRR' => array( |
350
|
|
|
'admin_label' => __( 'Iranian Rial (﷼)', 'give' ), |
351
|
|
|
'symbol' => '﷼', |
352
|
|
|
'setting' => array( |
353
|
|
|
'currency_position' => 'after', |
354
|
|
|
'thousands_separator' => ',', |
355
|
|
|
'decimal_separator' => '.', |
356
|
|
|
'number_decimals' => 2, |
357
|
|
|
), |
358
|
|
|
), |
359
|
|
|
'RUB' => array( |
360
|
|
|
'admin_label' => __( 'Russian Rubles (руб)', 'give' ), |
361
|
|
|
'symbol' => '₽', |
362
|
|
|
'setting' => array( |
363
|
|
|
'currency_position' => 'before', |
364
|
|
|
'thousands_separator' => '.', |
365
|
|
|
'decimal_separator' => ',', |
366
|
|
|
'number_decimals' => 2, |
367
|
|
|
), |
368
|
|
|
), |
369
|
|
|
'AED' => array( |
370
|
|
|
'admin_label' => __( 'United Arab Emirates dirham (د.إ)', 'give' ), |
371
|
|
|
'symbol' => 'د.إ', |
372
|
|
|
'setting' => array( |
373
|
|
|
'currency_position' => 'before', |
374
|
|
|
'thousands_separator' => ',', |
375
|
|
|
'decimal_separator' => '.', |
376
|
|
|
'number_decimals' => 2, |
377
|
|
|
), |
378
|
|
|
), |
379
|
|
|
'AMD' => array( |
380
|
|
|
'admin_label' => __( 'Armenian dram (AMD)', 'give' ), |
381
|
|
|
'symbol' => 'AMD', // Add backward compatibility. Using AMD in place of ֏ |
382
|
|
|
'setting' => array( |
383
|
|
|
'currency_position' => 'before', |
384
|
|
|
'thousands_separator' => ',', |
385
|
|
|
'decimal_separator' => '.', |
386
|
|
|
'number_decimals' => 2, |
387
|
|
|
), |
388
|
|
|
), |
389
|
|
|
'ANG' => array( |
390
|
|
|
'admin_label' => __( 'Netherlands Antillean guilder (ƒ)', 'give' ), |
391
|
|
|
'symbol' => 'ƒ', |
392
|
|
|
'setting' => array( |
393
|
|
|
'currency_position' => 'before', |
394
|
|
|
'thousands_separator' => '.', |
395
|
|
|
'decimal_separator' => ',', |
396
|
|
|
'number_decimals' => 2, |
397
|
|
|
), |
398
|
|
|
), |
399
|
|
|
'ARS' => array( |
400
|
|
|
'admin_label' => __( 'Argentine peso ($)', 'give' ), |
401
|
|
|
'symbol' => '$', |
402
|
|
|
'setting' => array( |
403
|
|
|
'currency_position' => 'before', |
404
|
|
|
'thousands_separator' => '.', |
405
|
|
|
'decimal_separator' => ',', |
406
|
|
|
'number_decimals' => 2, |
407
|
|
|
), |
408
|
|
|
), |
409
|
|
|
'AWG' => array( |
410
|
|
|
'admin_label' => __( 'Aruban florin (ƒ)', 'give' ), |
411
|
|
|
'symbol' => 'ƒ', |
412
|
|
|
'setting' => array( |
413
|
|
|
'currency_position' => 'before', |
414
|
|
|
'thousands_separator' => ',', |
415
|
|
|
'decimal_separator' => '.', |
416
|
|
|
'number_decimals' => 2, |
417
|
|
|
), |
418
|
|
|
), |
419
|
|
|
'BAM' => array( |
420
|
|
|
'admin_label' => __( 'Bosnia and Herzegovina convertible mark (KM)', 'give' ), |
421
|
|
|
'symbol' => 'KM', |
422
|
|
|
'setting' => array( |
423
|
|
|
'currency_position' => 'before', |
424
|
|
|
'thousands_separator' => ',', |
425
|
|
|
'decimal_separator' => '.', |
426
|
|
|
'number_decimals' => 2, |
427
|
|
|
), |
428
|
|
|
), |
429
|
|
|
'BDT' => array( |
430
|
|
|
'admin_label' => __( 'Bangladeshi taka (৳)', 'give' ), |
431
|
|
|
'symbol' => '৳', |
432
|
|
|
'setting' => array( |
433
|
|
|
'currency_position' => 'before', |
434
|
|
|
'thousands_separator' => ',', |
435
|
|
|
'decimal_separator' => '.', |
436
|
|
|
'number_decimals' => 2, |
437
|
|
|
), |
438
|
|
|
), |
439
|
|
|
'BHD' => array( |
440
|
|
|
'admin_label' => __( 'Bahraini dinar (.د.ب)', 'give' ), |
441
|
|
|
'symbol' => '.د.ب', |
442
|
|
|
'setting' => array( |
443
|
|
|
'currency_position' => 'before', |
444
|
|
|
'thousands_separator' => ',', |
445
|
|
|
'decimal_separator' => '.', |
446
|
|
|
'number_decimals' => 3, |
447
|
|
|
), |
448
|
|
|
), |
449
|
|
|
'BMD' => array( |
450
|
|
|
'admin_label' => __( 'Bermudian dollar (BD$)', 'give' ), |
451
|
|
|
'symbol' => 'BD$', |
452
|
|
|
'setting' => array( |
453
|
|
|
'currency_position' => 'before', |
454
|
|
|
'thousands_separator' => ',', |
455
|
|
|
'decimal_separator' => '.', |
456
|
|
|
'number_decimals' => 2, |
457
|
|
|
), |
458
|
|
|
), |
459
|
|
|
'BND' => array( |
460
|
|
|
'admin_label' => __( 'Brunei dollar (B$)', 'give' ), |
461
|
|
|
'symbol' => 'B$', |
462
|
|
|
'setting' => array( |
463
|
|
|
'currency_position' => 'before', |
464
|
|
|
'thousands_separator' => ',', |
465
|
|
|
'decimal_separator' => '.', |
466
|
|
|
'number_decimals' => 2, |
467
|
|
|
), |
468
|
|
|
), |
469
|
|
|
'BOB' => array( |
470
|
|
|
'admin_label' => __( 'Bolivian boliviano (Bs.)', 'give' ), |
471
|
|
|
'symbol' => 'Bs.', |
472
|
|
|
'setting' => array( |
473
|
|
|
'currency_position' => 'before', |
474
|
|
|
'thousands_separator' => ',', |
475
|
|
|
'decimal_separator' => '.', |
476
|
|
|
'number_decimals' => 2, |
477
|
|
|
), |
478
|
|
|
), |
479
|
|
|
'BSD' => array( |
480
|
|
|
'admin_label' => __( 'Bahamian dollar (B$)', 'give' ), |
481
|
|
|
'symbol' => 'B$', |
482
|
|
|
'setting' => array( |
483
|
|
|
'currency_position' => 'before', |
484
|
|
|
'thousands_separator' => ',', |
485
|
|
|
'decimal_separator' => '.', |
486
|
|
|
'number_decimals' => 2, |
487
|
|
|
), |
488
|
|
|
), |
489
|
|
|
'BWP' => array( |
490
|
|
|
'admin_label' => __( 'Botswana pula (P)', 'give' ), |
491
|
|
|
'symbol' => 'P', |
492
|
|
|
'setting' => array( |
493
|
|
|
'currency_position' => 'before', |
494
|
|
|
'thousands_separator' => ',', |
495
|
|
|
'decimal_separator' => '.', |
496
|
|
|
'number_decimals' => 2, |
497
|
|
|
), |
498
|
|
|
), |
499
|
|
|
'BZD' => array( |
500
|
|
|
'admin_label' => __( 'Belizean dollar (BZ$)', 'give' ), |
501
|
|
|
'symbol' => 'BZ$', |
502
|
|
|
'setting' => array( |
503
|
|
|
'currency_position' => 'before', |
504
|
|
|
'thousands_separator' => ',', |
505
|
|
|
'decimal_separator' => '.', |
506
|
|
|
'number_decimals' => 2, |
507
|
|
|
), |
508
|
|
|
), |
509
|
|
|
'CLP' => array( |
510
|
|
|
'admin_label' => __( 'Chilean peso ($)', 'give' ), |
511
|
|
|
'symbol' => '$', |
512
|
|
|
'setting' => array( |
513
|
|
|
'currency_position' => 'before', |
514
|
|
|
'thousands_separator' => '.', |
515
|
|
|
'decimal_separator' => '', |
516
|
|
|
'number_decimals' => 0, |
517
|
|
|
), |
518
|
|
|
), |
519
|
|
|
'CNY' => array( |
520
|
|
|
'admin_label' => __( 'Chinese yuan (¥)', 'give' ), |
521
|
|
|
'symbol' => '¥', |
522
|
|
|
'setting' => array( |
523
|
|
|
'currency_position' => 'before', |
524
|
|
|
'thousands_separator' => ',', |
525
|
|
|
'decimal_separator' => '.', |
526
|
|
|
'number_decimals' => 2, |
527
|
|
|
), |
528
|
|
|
), |
529
|
|
|
'COP' => array( |
530
|
|
|
'admin_label' => __( 'Colombian peso ($)', 'give' ), |
531
|
|
|
'symbol' => '$', |
532
|
|
|
'setting' => array( |
533
|
|
|
'currency_position' => 'before', |
534
|
|
|
'thousands_separator' => '.', |
535
|
|
|
'decimal_separator' => ',', |
536
|
|
|
'number_decimals' => 2, |
537
|
|
|
), |
538
|
|
|
), |
539
|
|
|
'CRC' => array( |
540
|
|
|
'admin_label' => __( 'Costa Rican colón (₡)', 'give' ), |
541
|
|
|
'symbol' => '₡', |
542
|
|
|
'setting' => array( |
543
|
|
|
'currency_position' => 'before', |
544
|
|
|
'thousands_separator' => '.', |
545
|
|
|
'decimal_separator' => ',', |
546
|
|
|
'number_decimals' => 2, |
547
|
|
|
), |
548
|
|
|
), |
549
|
|
|
'CUC' => array( |
550
|
|
|
'admin_label' => __( 'Cuban convertible peso (₱)', 'give' ), |
551
|
|
|
'symbol' => '₱', |
552
|
|
|
'setting' => array( |
553
|
|
|
'currency_position' => 'before', |
554
|
|
|
'thousands_separator' => ',', |
555
|
|
|
'decimal_separator' => '.', |
556
|
|
|
'number_decimals' => 2, |
557
|
|
|
), |
558
|
|
|
), |
559
|
|
|
'CUP' => array( |
560
|
|
|
'admin_label' => __( 'Cuban convertible peso (₱)', 'give' ), |
561
|
|
|
'symbol' => '₱', |
562
|
|
|
'setting' => array( |
563
|
|
|
'currency_position' => 'before', |
564
|
|
|
'thousands_separator' => ',', |
565
|
|
|
'decimal_separator' => '.', |
566
|
|
|
'number_decimals' => 2, |
567
|
|
|
), |
568
|
|
|
), |
569
|
|
|
'DOP' => array( |
570
|
|
|
'admin_label' => __( 'Dominican peso (RD$)', 'give' ), |
571
|
|
|
'symbol' => 'RD$', |
572
|
|
|
'setting' => array( |
573
|
|
|
'currency_position' => 'before', |
574
|
|
|
'thousands_separator' => ',', |
575
|
|
|
'decimal_separator' => '.', |
576
|
|
|
'number_decimals' => 2, |
577
|
|
|
), |
578
|
|
|
), |
579
|
|
|
'EGP' => array( |
580
|
|
|
'admin_label' => __( 'Egyptian pound (E£)', 'give' ), |
581
|
|
|
'symbol' => 'E£', |
582
|
|
|
'setting' => array( |
583
|
|
|
'currency_position' => 'before', |
584
|
|
|
'thousands_separator' => ',', |
585
|
|
|
'decimal_separator' => '.', |
586
|
|
|
'number_decimals' => 2, |
587
|
|
|
), |
588
|
|
|
), |
589
|
|
|
'GIP' => array( |
590
|
|
|
'admin_label' => __( 'Gibraltar pound (£)', 'give' ), |
591
|
|
|
'symbol' => '£', |
592
|
|
|
'setting' => array( |
593
|
|
|
'currency_position' => 'before', |
594
|
|
|
'thousands_separator' => ',', |
595
|
|
|
'decimal_separator' => '.', |
596
|
|
|
'number_decimals' => 2, |
597
|
|
|
), |
598
|
|
|
), |
599
|
|
|
'GTQ' => array( |
600
|
|
|
'admin_label' => __( 'Guatemalan quetzal (Q)', 'give' ), |
601
|
|
|
'symbol' => 'Q', |
602
|
|
|
'setting' => array( |
603
|
|
|
'currency_position' => 'before', |
604
|
|
|
'thousands_separator' => ',', |
605
|
|
|
'decimal_separator' => '.', |
606
|
|
|
'number_decimals' => 2, |
607
|
|
|
), |
608
|
|
|
), |
609
|
|
|
'HNL' => array( |
610
|
|
|
'admin_label' => __( 'Honduran lempira (L)', 'give' ), |
611
|
|
|
'symbol' => 'L', |
612
|
|
|
'setting' => array( |
613
|
|
|
'currency_position' => 'before', |
614
|
|
|
'thousands_separator' => ',', |
615
|
|
|
'decimal_separator' => '.', |
616
|
|
|
'number_decimals' => 2, |
617
|
|
|
), |
618
|
|
|
), |
619
|
|
|
'HRK' => array( |
620
|
|
|
'admin_label' => __( 'Croatian kuna (kn)', 'give' ), |
621
|
|
|
'symbol' => 'kn', |
622
|
|
|
'setting' => array( |
623
|
|
|
'currency_position' => 'after', |
624
|
|
|
'thousands_separator' => '.', |
625
|
|
|
'decimal_separator' => ',', |
626
|
|
|
'number_decimals' => 2, |
627
|
|
|
), |
628
|
|
|
), |
629
|
|
|
'IDR' => array( |
630
|
|
|
'admin_label' => __( 'Indonesian rupiah (Rp)', 'give' ), |
631
|
|
|
'symbol' => 'Rp', |
632
|
|
|
'setting' => array( |
633
|
|
|
'currency_position' => 'before', |
634
|
|
|
'thousands_separator' => '.', |
635
|
|
|
'decimal_separator' => ',', |
636
|
|
|
'number_decimals' => 2, |
637
|
|
|
), |
638
|
|
|
), |
639
|
|
|
'ISK' => array( |
640
|
|
|
'admin_label' => __( 'Icelandic króna (kr)', 'give' ), |
641
|
|
|
'symbol' => 'kr', |
642
|
|
|
'setting' => array( |
643
|
|
|
'currency_position' => 'after', |
644
|
|
|
'thousands_separator' => '.', |
645
|
|
|
'decimal_separator' => '', |
646
|
|
|
'number_decimals' => 0, |
647
|
|
|
), |
648
|
|
|
), |
649
|
|
|
'JMD' => array( |
650
|
|
|
'admin_label' => __( 'Jamaican dollar (J$)', 'give' ), |
651
|
|
|
'symbol' => 'j$', |
652
|
|
|
'setting' => array( |
653
|
|
|
'currency_position' => 'before', |
654
|
|
|
'thousands_separator' => ',', |
655
|
|
|
'decimal_separator' => '.', |
656
|
|
|
'number_decimals' => 2, |
657
|
|
|
), |
658
|
|
|
), |
659
|
|
|
'JOD' => array( |
660
|
|
|
'admin_label' => __( 'Jordanian dinar (د.ا)', 'give' ), |
661
|
|
|
'symbol' => 'د.ا', |
662
|
|
|
'setting' => array( |
663
|
|
|
'currency_position' => 'before', |
664
|
|
|
'thousands_separator' => ',', |
665
|
|
|
'decimal_separator' => '.', |
666
|
|
|
'number_decimals' => 3, |
667
|
|
|
), |
668
|
|
|
), |
669
|
|
|
'KES' => array( |
670
|
|
|
'admin_label' => __( 'Kenyan shilling (KSh)', 'give' ), |
671
|
|
|
'symbol' => 'KSh', |
672
|
|
|
'setting' => array( |
673
|
|
|
'currency_position' => 'before', |
674
|
|
|
'thousands_separator' => ',', |
675
|
|
|
'decimal_separator' => '.', |
676
|
|
|
'number_decimals' => 2, |
677
|
|
|
), |
678
|
|
|
), |
679
|
|
|
'KWD' => array( |
680
|
|
|
'admin_label' => __( 'Kuwaiti dinar (د.ك)', 'give' ), |
681
|
|
|
'symbol' => 'د.ك', |
682
|
|
|
'setting' => array( |
683
|
|
|
'currency_position' => 'before', |
684
|
|
|
'thousands_separator' => ',', |
685
|
|
|
'decimal_separator' => '.', |
686
|
|
|
'number_decimals' => 3, |
687
|
|
|
), |
688
|
|
|
), |
689
|
|
|
'KYD' => array( |
690
|
|
|
'admin_label' => __( 'Cayman Islands dollar (KY$)', 'give' ), |
691
|
|
|
'symbol' => 'KY$', |
692
|
|
|
'setting' => array( |
693
|
|
|
'currency_position' => 'before', |
694
|
|
|
'thousands_separator' => ',', |
695
|
|
|
'decimal_separator' => '.', |
696
|
|
|
'number_decimals' => 2, |
697
|
|
|
), |
698
|
|
|
), |
699
|
|
|
'MKD' => array( |
700
|
|
|
'admin_label' => __( 'Macedonian denar (ден)', 'give' ), |
701
|
|
|
'symbol' => 'ден', |
702
|
|
|
'setting' => array( |
703
|
|
|
'currency_position' => 'before', |
704
|
|
|
'thousands_separator' => ',', |
705
|
|
|
'decimal_separator' => '.', |
706
|
|
|
'number_decimals' => 2, |
707
|
|
|
), |
708
|
|
|
), |
709
|
|
|
'NPR' => array( |
710
|
|
|
'admin_label' => __( 'Nepalese rupee (NɌs)', 'give' ), |
711
|
|
|
'symbol' => '₨', |
712
|
|
|
'setting' => array( |
713
|
|
|
'currency_position' => 'before', |
714
|
|
|
'thousands_separator' => ',', |
715
|
|
|
'decimal_separator' => '.', |
716
|
|
|
'number_decimals' => 2, |
717
|
|
|
), |
718
|
|
|
), |
719
|
|
|
'OMR' => array( |
720
|
|
|
'admin_label' => __( 'Omani rial (ر.ع.)', 'give' ), |
721
|
|
|
'symbol' => 'ر.ع.', |
722
|
|
|
'setting' => array( |
723
|
|
|
'currency_position' => 'before', |
724
|
|
|
'thousands_separator' => ',', |
725
|
|
|
'decimal_separator' => '.', |
726
|
|
|
'number_decimals' => 3, |
727
|
|
|
), |
728
|
|
|
), |
729
|
|
|
'PEN' => array( |
730
|
|
|
'admin_label' => __( 'Peruvian nuevo sol (S/.)', 'give' ), |
731
|
|
|
'symbol' => 'S/.', |
732
|
|
|
'setting' => array( |
733
|
|
|
'currency_position' => 'before', |
734
|
|
|
'thousands_separator' => ',', |
735
|
|
|
'decimal_separator' => '.', |
736
|
|
|
'number_decimals' => 2, |
737
|
|
|
), |
738
|
|
|
), |
739
|
|
|
'PKR' => array( |
740
|
|
|
'admin_label' => __( 'Pakistani rupee (Ɍs)', 'give' ), |
741
|
|
|
'symbol' => '₨', |
742
|
|
|
'setting' => array( |
743
|
|
|
'currency_position' => 'before', |
744
|
|
|
'thousands_separator' => ',', |
745
|
|
|
'decimal_separator' => '.', |
746
|
|
|
'number_decimals' => 2, |
747
|
|
|
), |
748
|
|
|
), |
749
|
|
|
'RON' => array( |
750
|
|
|
'admin_label' => __( 'Romanian leu (L)', 'give' ), |
751
|
|
|
'symbol' => 'L', |
752
|
|
|
'setting' => array( |
753
|
|
|
'currency_position' => 'after', |
754
|
|
|
'thousands_separator' => '.', |
755
|
|
|
'decimal_separator' => ',', |
756
|
|
|
'number_decimals' => 2, |
757
|
|
|
), |
758
|
|
|
), |
759
|
|
|
'SAR' => array( |
760
|
|
|
'admin_label' => __( 'Saudi riyal (ر.س)', 'give' ), |
761
|
|
|
'symbol' => 'ر.س', |
762
|
|
|
'setting' => array( |
763
|
|
|
'currency_position' => 'before', |
764
|
|
|
'thousands_separator' => ',', |
765
|
|
|
'decimal_separator' => '.', |
766
|
|
|
'number_decimals' => 2, |
767
|
|
|
), |
768
|
|
|
), |
769
|
|
|
'SZL' => array( |
770
|
|
|
'admin_label' => __( 'Swazi lilangeni (L)', 'give' ), |
771
|
|
|
'symbol' => 'L', |
772
|
|
|
'setting' => array( |
773
|
|
|
'currency_position' => 'before', |
774
|
|
|
'thousands_separator' => ',', |
775
|
|
|
'decimal_separator' => '.', |
776
|
|
|
'number_decimals' => 2, |
777
|
|
|
), |
778
|
|
|
), |
779
|
|
|
'TOP' => array( |
780
|
|
|
'admin_label' => __( 'Tongan paʻanga (T$)', 'give' ), |
781
|
|
|
'symbol' => 'T$', |
782
|
|
|
'setting' => array( |
783
|
|
|
'currency_position' => 'before', |
784
|
|
|
'thousands_separator' => ',', |
785
|
|
|
'decimal_separator' => '.', |
786
|
|
|
'number_decimals' => 2, |
787
|
|
|
), |
788
|
|
|
), |
789
|
|
|
'TZS' => array( |
790
|
|
|
'admin_label' => __( 'Tanzanian shilling (TSh)', 'give' ), |
791
|
|
|
'symbol' => 'TSh', |
792
|
|
|
'setting' => array( |
793
|
|
|
'currency_position' => 'before', |
794
|
|
|
'thousands_separator' => ',', |
795
|
|
|
'decimal_separator' => '.', |
796
|
|
|
'number_decimals' => 2, |
797
|
|
|
), |
798
|
|
|
), |
799
|
|
|
'UAH' => array( |
800
|
|
|
'admin_label' => __( 'Ukrainian hryvnia (₴)', 'give' ), |
801
|
|
|
'symbol' => '₴', |
802
|
|
|
'setting' => array( |
803
|
|
|
'currency_position' => 'before', |
804
|
|
|
'thousands_separator' => ' ', |
805
|
|
|
'decimal_separator' => ',', |
806
|
|
|
'number_decimals' => 2, |
807
|
|
|
), |
808
|
|
|
), |
809
|
|
|
'UYU' => array( |
810
|
|
|
'admin_label' => __( 'Uruguayan peso ($U)', 'give' ), |
811
|
|
|
'symbol' => '$U', |
812
|
|
|
'setting' => array( |
813
|
|
|
'currency_position' => 'before', |
814
|
|
|
'thousands_separator' => '.', |
815
|
|
|
'decimal_separator' => ',', |
816
|
|
|
'number_decimals' => 2, |
817
|
|
|
), |
818
|
|
|
), |
819
|
|
|
'VEF' => array( |
820
|
|
|
'admin_label' => __( 'Venezuelan bolívar (Bs)', 'give' ), |
821
|
|
|
'symbol' => 'Bs', |
822
|
|
|
'setting' => array( |
823
|
|
|
'currency_position' => 'before', |
824
|
|
|
'thousands_separator' => '.', |
825
|
|
|
'decimal_separator' => ',', |
826
|
|
|
'number_decimals' => 2, |
827
|
|
|
), |
828
|
|
|
), |
829
|
|
|
'XCD' => array( |
830
|
|
|
'admin_label' => __( 'East Caribbean dollar (EC$)', 'give' ), |
831
|
|
|
'symbol' => 'EC$', |
832
|
|
|
'setting' => array( |
833
|
|
|
'currency_position' => 'before', |
834
|
|
|
'thousands_separator' => ',', |
835
|
|
|
'decimal_separator' => '.', |
836
|
|
|
'number_decimals' => 2, |
837
|
|
|
), |
838
|
|
|
), |
839
|
|
|
); |
840
|
|
|
|
841
|
|
|
/** |
842
|
|
|
* Filter the currencies |
843
|
|
|
* Note: you can register new currency by using this filter |
844
|
|
|
* array( |
845
|
|
|
* 'admin_label' => '', // required |
846
|
|
|
* 'symbol' => '', // required |
847
|
|
|
* 'setting' => '' // required |
848
|
|
|
* .... |
849
|
|
|
* ) |
850
|
|
|
* |
851
|
|
|
* @since 1.8.15 |
852
|
|
|
* |
853
|
|
|
* @param array $currencies |
854
|
|
|
*/ |
855
|
|
|
return (array) apply_filters( 'give_currencies', $currencies ); |
856
|
|
|
} |
857
|
|
|
|
858
|
|
|
/** |
859
|
|
|
* Get Currencies |
860
|
|
|
* |
861
|
|
|
* @since 1.0 |
862
|
|
|
* |
863
|
|
|
* @param string $info Specify currency info |
864
|
|
|
* |
865
|
|
|
* @return array $currencies A list of the available currencies |
866
|
|
|
*/ |
867
|
|
|
function give_get_currencies( $info = 'admin_label' ) { |
868
|
|
|
|
869
|
|
|
$currencies = give_get_currencies_list(); |
870
|
|
|
|
871
|
|
|
// Backward compatibility: handle old way of currency registration. |
872
|
|
|
// Backward compatibility: Return desired result. |
873
|
|
|
if ( ! empty( $currencies ) ) { |
874
|
|
|
foreach ( $currencies as $currency_code => $currency_setting ) { |
875
|
|
|
if ( is_string( $currency_setting ) ) { |
876
|
|
|
$currencies[ $currency_code ] = array( |
877
|
|
|
'admin_label' => $currency_setting, |
878
|
|
|
); |
879
|
|
|
} |
880
|
|
|
|
881
|
|
|
$currencies[ $currency_code ] = wp_parse_args( |
882
|
|
|
$currencies[ $currency_code ], |
883
|
|
|
array( |
884
|
|
|
'admin_label' => '', |
885
|
|
|
'symbol' => $currency_code, |
886
|
|
|
'setting' => array(), |
887
|
|
|
) |
888
|
|
|
); |
889
|
|
|
} |
890
|
|
|
|
891
|
|
|
if ( ! empty( $info ) && is_string( $info ) && 'all' !== $info ) { |
892
|
|
|
$currencies = wp_list_pluck( $currencies, $info ); |
893
|
|
|
} |
894
|
|
|
} |
895
|
|
|
|
896
|
|
|
return $currencies; |
897
|
|
|
} |
898
|
|
|
|
899
|
|
|
|
900
|
|
|
/** |
901
|
|
|
* Get all currency symbols |
902
|
|
|
* |
903
|
|
|
* @since 1.8.14 |
904
|
|
|
* |
905
|
|
|
* @param bool $decode_currencies |
906
|
|
|
* |
907
|
|
|
* @return array |
908
|
|
|
*/ |
909
|
|
|
function give_currency_symbols( $decode_currencies = false ) { |
910
|
|
|
$currencies = give_get_currencies( 'symbol' ); |
911
|
|
|
|
912
|
|
|
if ( $decode_currencies ) { |
913
|
|
|
array_walk( $currencies, function ( &$currency_symbol ) { |
914
|
|
|
$currency_symbol = html_entity_decode( $currency_symbol, ENT_COMPAT, 'UTF-8' ); |
915
|
|
|
} ); |
916
|
|
|
} |
917
|
|
|
|
918
|
|
|
/** |
919
|
|
|
* Filter the currency symbols |
920
|
|
|
* |
921
|
|
|
* @since 1.8.14 |
922
|
|
|
* |
923
|
|
|
* @param array $currencies |
924
|
|
|
*/ |
925
|
|
|
return apply_filters( 'give_currency_symbols', $currencies ); |
926
|
|
|
} |
927
|
|
|
|
928
|
|
|
|
929
|
|
|
/** |
930
|
|
|
* Give Currency Symbol |
931
|
|
|
* |
932
|
|
|
* Given a currency determine the symbol to use. If no currency given, site default is used. If no symbol is determine, |
933
|
|
|
* the currency string is returned. |
934
|
|
|
* |
935
|
|
|
* @since 1.0 |
936
|
|
|
* |
937
|
|
|
* @param string $currency The currency string. |
938
|
|
|
* @param bool $decode_currency Option to HTML decode the currency symbol. |
939
|
|
|
* |
940
|
|
|
* @return string The symbol to use for the currency |
941
|
|
|
*/ |
942
|
|
View Code Duplication |
function give_currency_symbol( $currency = '', $decode_currency = false ) { |
|
|
|
|
943
|
|
|
|
944
|
|
|
if ( empty( $currency ) ) { |
945
|
|
|
$currency = give_get_currency(); |
946
|
|
|
} |
947
|
|
|
|
948
|
|
|
$currencies = give_currency_symbols( $decode_currency ); |
949
|
|
|
$symbol = array_key_exists( $currency, $currencies ) ? $currencies[ $currency ] : $currency; |
950
|
|
|
|
951
|
|
|
/** |
952
|
|
|
* Filter the currency symbol |
953
|
|
|
* |
954
|
|
|
* @since 1.0 |
955
|
|
|
* |
956
|
|
|
* @param string $symbol |
957
|
|
|
* @param string $currency |
958
|
|
|
*/ |
959
|
|
|
return apply_filters( 'give_currency_symbol', $symbol, $currency ); |
960
|
|
|
} |
961
|
|
|
|
962
|
|
|
|
963
|
|
|
/** |
964
|
|
|
* Get currency name. |
965
|
|
|
* |
966
|
|
|
* @since 1.8.8 |
967
|
|
|
* |
968
|
|
|
* @param string $currency_code |
969
|
|
|
* |
970
|
|
|
* @return string |
971
|
|
|
*/ |
972
|
|
|
function give_get_currency_name( $currency_code ) { |
973
|
|
|
$currency_name = ''; |
974
|
|
|
$currency_names = give_get_currencies(); |
975
|
|
|
|
976
|
|
|
if ( $currency_code && array_key_exists( $currency_code, $currency_names ) ) { |
977
|
|
|
$currency_name = explode( '(', $currency_names[ $currency_code ] ); |
978
|
|
|
$currency_name = trim( current( $currency_name ) ); |
979
|
|
|
} |
980
|
|
|
|
981
|
|
|
/** |
982
|
|
|
* Filter the currency name |
983
|
|
|
* |
984
|
|
|
* @since 1.8.8 |
985
|
|
|
* |
986
|
|
|
* @param string $currency_name |
987
|
|
|
* @param string $currency_code |
988
|
|
|
*/ |
989
|
|
|
return apply_filters( 'give_currency_name', $currency_name, $currency_code ); |
990
|
|
|
} |
991
|
|
|
|
992
|
|
|
/** |
993
|
|
|
* Formats the currency displayed. |
994
|
|
|
* |
995
|
|
|
* @since 1.0 |
996
|
|
|
* |
997
|
|
|
* @param string $price The donation amount. |
998
|
|
|
* @param array $args It accepts 'currency_code', 'decode_currency' and 'form_id'. |
999
|
|
|
* |
1000
|
|
|
* @return mixed|string |
1001
|
|
|
*/ |
1002
|
|
|
function give_currency_filter( $price = '', $args = array() ) { |
1003
|
|
|
|
1004
|
|
|
// Get functions arguments. |
1005
|
|
|
$func_args = func_get_args(); |
1006
|
|
|
|
1007
|
|
|
// Backward compatibility: modify second param to array |
1008
|
|
|
if ( isset( $func_args[1] ) && is_string( $func_args[1] ) ) { |
1009
|
|
|
$args = array( |
1010
|
|
|
'currency_code' => isset( $func_args[1] ) ? $func_args[1] : '', |
1011
|
|
|
'decode_currency' => isset( $func_args[2] ) ? $func_args[2] : false, |
1012
|
|
|
'form_id' => isset( $func_args[3] ) ? $func_args[3] : '', |
1013
|
|
|
); |
1014
|
|
|
} |
1015
|
|
|
|
1016
|
|
|
// Set default values. |
1017
|
|
|
$args = wp_parse_args( |
1018
|
|
|
$args, |
1019
|
|
|
array( |
1020
|
|
|
'currency_code' => '', |
1021
|
|
|
'decode_currency' => false, |
1022
|
|
|
'form_id' => '', |
1023
|
|
|
) |
1024
|
|
|
); |
1025
|
|
|
|
1026
|
|
|
if ( empty( $args['currency_code'] ) || ! array_key_exists( (string) $args['currency_code'], give_get_currencies() ) ) { |
1027
|
|
|
$args['currency_code'] = give_get_currency( $args['form_id'] ); |
1028
|
|
|
} |
1029
|
|
|
|
1030
|
|
|
$args['position'] = give_get_option( 'currency_position', 'before' ); |
1031
|
|
|
|
1032
|
|
|
$negative = $price < 0; |
1033
|
|
|
|
1034
|
|
|
if ( $negative ) { |
1035
|
|
|
// Remove proceeding "-". |
1036
|
|
|
$price = substr( $price, 1 ); |
1037
|
|
|
} |
1038
|
|
|
|
1039
|
|
|
$args['symbol'] = give_currency_symbol( $args['currency_code'], $args['decode_currency'] ); |
1040
|
|
|
|
1041
|
|
|
switch ( $args['currency_code'] ) : |
1042
|
|
|
case 'GBP' : |
1043
|
|
|
case 'BRL' : |
1044
|
|
|
case 'EUR' : |
1045
|
|
|
case 'USD' : |
1046
|
|
|
case 'AUD' : |
1047
|
|
|
case 'CAD' : |
1048
|
|
|
case 'HKD' : |
1049
|
|
|
case 'MXN' : |
1050
|
|
|
case 'NZD' : |
1051
|
|
|
case 'SGD' : |
1052
|
|
|
case 'JPY' : |
1053
|
|
|
case 'THB' : |
1054
|
|
|
case 'INR' : |
1055
|
|
|
case 'IDR' : |
1056
|
|
|
case 'IRR' : |
1057
|
|
|
case 'TRY' : |
1058
|
|
|
case 'RUB' : |
1059
|
|
|
case 'SEK' : |
1060
|
|
|
case 'PLN' : |
1061
|
|
|
case 'PHP' : |
1062
|
|
|
case 'TWD' : |
1063
|
|
|
case 'MYR' : |
1064
|
|
|
case 'CZK' : |
1065
|
|
|
case 'DKK' : |
1066
|
|
|
case 'HUF' : |
1067
|
|
|
case 'ILS' : |
1068
|
|
|
case 'MAD' : |
1069
|
|
|
case 'KRW' : |
1070
|
|
View Code Duplication |
case 'ZAR' : |
|
|
|
|
1071
|
|
|
$formatted = ( 'before' === $args['position'] ? $args['symbol'] . $price : $price . $args['symbol'] ); |
1072
|
|
|
break; |
1073
|
|
View Code Duplication |
case 'NOK': |
|
|
|
|
1074
|
|
|
$formatted = ( 'before' === $args['position'] ? $args['symbol'] . ' ' . $price : $price . ' ' . $args['symbol'] ); |
1075
|
|
|
break; |
1076
|
|
View Code Duplication |
default: |
|
|
|
|
1077
|
|
|
$formatted = ( 'before' === $args['position'] ? $args['symbol'] . ' ' . $price : $price . ' ' . $args['symbol'] ); |
1078
|
|
|
break; |
1079
|
|
|
endswitch; |
1080
|
|
|
|
1081
|
|
|
/** |
1082
|
|
|
* Filter formatted amount |
1083
|
|
|
* |
1084
|
|
|
* @since 1.8.17 |
1085
|
|
|
*/ |
1086
|
|
|
$formatted = apply_filters( 'give_currency_filter', $formatted, $args, $price ); |
1087
|
|
|
|
1088
|
|
|
/** |
1089
|
|
|
* Filter formatted amount with currency |
1090
|
|
|
* |
1091
|
|
|
* Filter name depends upon current value of currency and currency position. |
1092
|
|
|
* For example : |
1093
|
|
|
* if currency is USD and currency position is before then |
1094
|
|
|
* filter name will be give_usd_currency_filter_before |
1095
|
|
|
* |
1096
|
|
|
* and if currency is USD and currency position is after then |
1097
|
|
|
* filter name will be give_usd_currency_filter_after |
1098
|
|
|
*/ |
1099
|
|
|
$formatted = apply_filters( |
1100
|
|
|
'give_' . strtolower( $args['currency_code'] ) . "_currency_filter_{$args['position']}", |
1101
|
|
|
$formatted, |
1102
|
|
|
$args['currency_code'], |
1103
|
|
|
$price, |
1104
|
|
|
$args |
1105
|
|
|
); |
1106
|
|
|
|
1107
|
|
|
if ( $negative ) { |
1108
|
|
|
// Prepend the minus sign before the currency sign. |
1109
|
|
|
$formatted = '-' . $formatted; |
1110
|
|
|
} |
1111
|
|
|
|
1112
|
|
|
return $formatted; |
1113
|
|
|
} |
1114
|
|
|
|
1115
|
|
|
|
1116
|
|
|
/** |
1117
|
|
|
* Zero Decimal based Currency. |
1118
|
|
|
* |
1119
|
|
|
* @since 1.8.14 |
1120
|
|
|
* @see https://github.com/WordImpress/Give/issues/2191 |
1121
|
|
|
* |
1122
|
|
|
* @param string $currency Currency code |
1123
|
|
|
* |
1124
|
|
|
* @return bool |
1125
|
|
|
*/ |
1126
|
|
|
function give_is_zero_based_currency( $currency = '' ) { |
1127
|
|
|
$zero_based_currency = array( |
1128
|
|
|
'PYG', // Paraguayan Guarani. |
1129
|
|
|
'GNF', // Guinean Franc. |
1130
|
|
|
'RWF', // Rwandan Franc. |
1131
|
|
|
'JPY', // Japanese Yen. |
1132
|
|
|
'BIF', // Burundian Franc. |
1133
|
|
|
'KRW', // South Korean Won. |
1134
|
|
|
'MGA', // Malagasy Ariary. |
1135
|
|
|
'XAF', // Central African Cfa Franc. |
1136
|
|
|
'XPF', // Cfp Franc. |
1137
|
|
|
'CLP', // Chilean Peso. |
1138
|
|
|
'KMF', // Comorian Franc. |
1139
|
|
|
'DJF', // Djiboutian Franc. |
1140
|
|
|
'VUV', // Vanuatu Vatu. |
1141
|
|
|
'VND', // Vietnamese Dong. |
1142
|
|
|
'XOF', // West African Cfa Franc. |
1143
|
|
|
); |
1144
|
|
|
|
1145
|
|
|
// Set default currency. |
1146
|
|
|
if ( empty( $currency ) ) { |
1147
|
|
|
$currency = give_get_currency(); |
1148
|
|
|
} |
1149
|
|
|
|
1150
|
|
|
// Check for Zero Based Currency. |
1151
|
|
|
if ( in_array( $currency, $zero_based_currency ) ) { |
1152
|
|
|
return true; |
1153
|
|
|
} |
1154
|
|
|
|
1155
|
|
|
return false; |
1156
|
|
|
} |
1157
|
|
|
|
1158
|
|
|
|
1159
|
|
|
/** |
1160
|
|
|
* Check if currency support right to left direction or not. |
1161
|
|
|
* |
1162
|
|
|
* @param string $currency |
1163
|
|
|
* |
1164
|
|
|
* @return bool |
1165
|
|
|
*/ |
1166
|
|
|
function give_is_right_to_left_supported_currency( $currency = '' ) { |
1167
|
|
|
$zero_based_currency = apply_filters( |
1168
|
|
|
'give_right_to_left_supported_currency', |
1169
|
|
|
array( |
1170
|
|
|
'IRR', |
1171
|
|
|
'RIAL', |
1172
|
|
|
'MAD', |
1173
|
|
|
'AED', |
1174
|
|
|
'BHD', |
1175
|
|
|
'KWD', |
1176
|
|
|
'OMR', |
1177
|
|
|
'SAR', |
1178
|
|
|
) |
1179
|
|
|
); |
1180
|
|
|
|
1181
|
|
|
// Set default currency. |
1182
|
|
|
if ( empty( $currency ) ) { |
1183
|
|
|
$currency = give_get_currency(); |
1184
|
|
|
} |
1185
|
|
|
|
1186
|
|
|
// Check for Zero Based Currency. |
1187
|
|
|
if ( in_array( $currency, $zero_based_currency ) ) { |
1188
|
|
|
return true; |
1189
|
|
|
} |
1190
|
|
|
|
1191
|
|
|
return false; |
1192
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.