Test Failed
Push — release/2.1 ( d820cd...c669cb )
by Ravinder
05:21
created

currency-functions.php ➔ give_get_currency()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 20
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 3
nop 2
dl 0
loc 20
rs 9.2
c 0
b 0
f 0
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
		$currency = give_get_meta( $donation_or_form_id, '_give_payment_currency', true );
28
29
		if ( empty( $currency ) ) {
30
			$currency = give_get_option( 'currency', 'USD' );
31
		}
32
	} else {
33
		$currency = give_get_option( 'currency', 'USD' );
34
	}
35
36
	/**
37
	 * Filter the currency on basis of donation or form id or addtional data.
38
	 *
39
	 * @since 1.0
40
	 */
41
	return apply_filters( 'give_currency', $currency, $donation_or_form_id, $args );
42
}
43
44
/**
45
 * Get the set currency position
46
 *
47
 * @since 1.3.6
48
 *
49
 * @return string The currency code
50
 */
51
function give_get_currency_position() {
52
53
	$currency_pos = give_get_option( 'currency_position', 'before' );
54
55
	return apply_filters( 'give_currency_position', $currency_pos );
56
}
57
58
/**
59
 * Get Currencies List
60
 *
61
 * @since 1.8.17
62
 *
63
 * @return array $currencies A list of the available currencies
64
 */
65
function give_get_currencies_list() {
66
	$currencies = array(
67
		'USD' => array(
68
			'admin_label' => sprintf( __('US Dollars (%1$s)', 'give'), '&#36;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
69
			'symbol'      => '&#36;',
70
			'setting'     => array(
71
				'currency_position'   => 'before',
72
				'thousands_separator' => ',',
73
				'decimal_separator'   => '.',
74
				'number_decimals'     => 2,
75
			),
76
		),
77
		'EUR' => array(
78
			'admin_label' => sprintf( __('Euros (%1$s)', 'give'), '&euro;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
79
			'symbol'      => '&euro;',
80
			'setting'     => array(
81
				'currency_position'   => 'before',
82
				'thousands_separator' => '.',
83
				'decimal_separator'   => ',',
84
				'number_decimals'     => 2,
85
			),
86
		),
87
		'GBP' => array(
88
			'admin_label' => sprintf( __('Pounds Sterling (%1$s)', 'give'), '&pound;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
89
			'symbol'      => '&pound;',
90
			'setting'     => array(
91
				'currency_position'   => 'before',
92
				'thousands_separator' => ',',
93
				'decimal_separator'   => '.',
94
				'number_decimals'     => 2,
95
			),
96
		),
97
		'AUD' => array(
98
			'admin_label' => sprintf( __('Australian Dollars (%1$s)', 'give'), '&#36;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
99
			'symbol'      => '&#36;',
100
			'setting'     => array(
101
				'currency_position'   => 'before',
102
				'thousands_separator' => ',',
103
				'decimal_separator'   => '.',
104
				'number_decimals'     => 2,
105
			),
106
		),
107
		'BRL' => array(
108
			'admin_label' => sprintf( __('Brazilian Real (%1$s)', 'give'), '&#82;&#36;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
109
			'symbol'      => '&#82;&#36;',
110
			'setting'     => array(
111
				'currency_position'   => 'before',
112
				'thousands_separator' => ',',
113
				'decimal_separator'   => '.',
114
				'number_decimals'     => 2,
115
			),
116
		),
117
		'CAD' => array(
118
			'admin_label' => sprintf( __('Canadian Dollars (%1$s)', 'give'), '&#36;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
119
			'symbol'      => '&#36;',
120
			'setting'     => array(
121
				'currency_position'   => 'before',
122
				'thousands_separator' => ',',
123
				'decimal_separator'   => '.',
124
				'number_decimals'     => 2,
125
			),
126
		),
127
		'CZK' => array(
128
			'admin_label' => sprintf( __('Czech Koruna (%1$s)', 'give'), '&#75;&#269;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
129
			'symbol'      => '&#75;&#269;',
130
			'setting'     => array(
131
				'currency_position'   => 'after',
132
				'thousands_separator' => ',',
133
				'decimal_separator'   => '.',
134
				'number_decimals'     => 2,
135
			),
136
		),
137
		'DKK' => array(
138
			'admin_label' => sprintf( __('Danish Krone (%1$s)', 'give'), '&nbsp;kr.&nbsp;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
139
			'symbol'      => '&nbsp;kr.&nbsp;',
140
			'setting'     => array(
141
				'currency_position'   => 'before',
142
				'thousands_separator' => ',',
143
				'decimal_separator'   => '.',
144
				'number_decimals'     => 2,
145
			),
146
		),
147
		'HKD' => array(
148
			'admin_label' => sprintf( __('Hong Kong Dollar (%1$s)', 'give'), '&#36;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
149
			'symbol'      => '&#36;',
150
			'setting'     => array(
151
				'currency_position'   => 'before',
152
				'thousands_separator' => ',',
153
				'decimal_separator'   => '.',
154
				'number_decimals'     => 2,
155
			),
156
		),
157
		'HUF' => array(
158
			'admin_label' => sprintf( __('Hungarian Forint (%1$s)', 'give'), '&#70;&#116;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
159
			'symbol'      => '&#70;&#116;',
160
			'setting'     => array(
161
				'currency_position'   => 'after',
162
				'thousands_separator' => ',',
163
				'decimal_separator'   => '.',
164
				'number_decimals'     => 2,
165
			),
166
		),
167
		'ILS' => array(
168
			'admin_label' => sprintf( __('Israeli Shekel (%1$s)', 'give'), '&#8362;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
169
			'symbol'      => '&#8362;',
170
			'setting'     => array(
171
				'currency_position'   => 'after',
172
				'thousands_separator' => ',',
173
				'decimal_separator'   => '.',
174
				'number_decimals'     => 2,
175
			),
176
		),
177
		'JPY' => array(
178
			'admin_label' => sprintf( __('Japanese Yen (%1$s)', 'give'), '&yen;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
179
			'symbol'      => '&yen;',
180
			'setting'     => array(
181
				'currency_position'   => 'before',
182
				'thousands_separator' => ',',
183
				'decimal_separator'   => '.',
184
				'number_decimals'     => 0,
185
			),
186
		),
187
		'MYR' => array(
188
			'admin_label' => sprintf( __('Malaysian Ringgits (%1$s)', 'give'), '&#82;&#77;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
189
			'symbol'      => '&#82;&#77;',
190
			'setting'     => array(
191
				'currency_position'   => 'before',
192
				'thousands_separator' => ',',
193
				'decimal_separator'   => '.',
194
				'number_decimals'     => 2,
195
			),
196
		),
197
		'MXN' => array(
198
			'admin_label' => sprintf( __('Mexican Peso (%1$s)', 'give'), '&#36;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
199
			'symbol'      => '&#36;',
200
			'setting'     => array(
201
				'currency_position'   => 'before',
202
				'thousands_separator' => ',',
203
				'decimal_separator'   => '.',
204
				'number_decimals'     => 2,
205
			),
206
		),
207
		'MAD' => array(
208
			'admin_label' => sprintf( __('Moroccan Dirham (%1$s)', 'give'), '&#x2e;&#x62f;&#x2e;&#x645;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
209
			'symbol'      => '&#x2e;&#x62f;&#x2e;&#x645;',
210
			'setting'     => array(
211
				'currency_position'   => 'before',
212
				'thousands_separator' => ',',
213
				'decimal_separator'   => '.',
214
				'number_decimals'     => 2,
215
			),
216
		),
217
		'NZD' => array(
218
			'admin_label' => sprintf( __('New Zealand Dollar (%1$s)', 'give'), '&#36;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
219
			'symbol'      => '&#36;',
220
			'setting'     => array(
221
				'currency_position'   => 'before',
222
				'thousands_separator' => ',',
223
				'decimal_separator'   => '.',
224
				'number_decimals'     => 2,
225
			),
226
		),
227
		'NOK' => array(
228
			'admin_label' => sprintf( __('Norwegian Krone (%1$s)', 'give'), '&#107;&#114;.'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
229
			'symbol'      => '&#107;&#114;.',
230
			'setting'     => array(
231
				'currency_position'   => 'before',
232
				'thousands_separator' => '.',
233
				'decimal_separator'   => ',',
234
				'number_decimals'     => 2,
235
			),
236
		),
237
		'PHP' => array(
238
			'admin_label' => sprintf( __('Philippine Pesos (%1$s)', 'give'), '&#8369;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
239
			'symbol'      => '&#8369;',
240
			'setting'     => array(
241
				'currency_position'   => 'before',
242
				'thousands_separator' => ',',
243
				'decimal_separator'   => '.',
244
				'number_decimals'     => 2,
245
			),
246
		),
247
		'PLN' => array(
248
			'admin_label' => sprintf( __('Polish Zloty (%1$s)', 'give'), '&#122;&#322;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
249
			'symbol'      => '&#122;&#322;',
250
			'setting'     => array(
251
				'currency_position'   => 'after',
252
				'thousands_separator' => ' ',
253
				'decimal_separator'   => ',',
254
				'number_decimals'     => 2,
255
			),
256
		),
257
		'SGD' => array(
258
			'admin_label' => sprintf( __('Singapore Dollar (%1$s)', 'give'), '&#36;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
259
			'symbol'      => '&#36;',
260
			'setting'     => array(
261
				'currency_position'   => 'before',
262
				'thousands_separator' => ',',
263
				'decimal_separator'   => '.',
264
				'number_decimals'     => 2,
265
			),
266
		),
267
		'KRW' => array(
268
			'admin_label' => sprintf( __('South Korean Won (%1$s)', 'give'), '&#8361;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
269
			'symbol'      => '&#8361;',
270
			'setting'     => array(
271
				'currency_position'   => 'before',
272
				'thousands_separator' => ',',
273
				'decimal_separator'   => '.',
274
				'number_decimals'     => 0,
275
			),
276
		),
277
		'ZAR' => array(
278
			'admin_label' => sprintf( __('South African Rand (%1$s)', 'give'), '&#82;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
279
			'symbol'      => '&#82;',
280
			'setting'     => array(
281
				'currency_position'   => 'before',
282
				'thousands_separator' => ' ',
283
				'decimal_separator'   => '.',
284
				'number_decimals'     => 2,
285
			),
286
		),
287
		'SEK' => array(
288
			'admin_label' => sprintf( __('Swedish Krona (%1$s)', 'give'), '&nbsp;kr.&nbsp;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
289
			'symbol'      => '&nbsp;kr.&nbsp;',
290
			'setting'     => array(
291
				'currency_position'   => 'before',
292
				'thousands_separator' => ' ',
293
				'decimal_separator'   => ',',
294
				'number_decimals'     => 2,
295
			),
296
		),
297
		'CHF' => array(
298
			'admin_label' => sprintf( __('Swiss Franc (%1$s)', 'give'), '&#70;&#114;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
299
			'symbol'      => '&#70;&#114;',
300
			'setting'     => array(
301
				'currency_position'   => 'before',
302
				'thousands_separator' => ',',
303
				'decimal_separator'   => '.',
304
				'number_decimals'     => 2,
305
			),
306
		),
307
		'TWD' => array(
308
			'admin_label' => sprintf( __('Taiwan New Dollars (%1$s)', 'give'), '&#78;&#84;&#36;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
309
			'symbol'      => '&#78;&#84;&#36;',
310
			'setting'     => array(
311
				'currency_position'   => 'before',
312
				'thousands_separator' => '\'',
313
				'decimal_separator'   => '.',
314
				'number_decimals'     => 2,
315
			),
316
		),
317
		'THB' => array(
318
			'admin_label' => sprintf( __('Thai Baht (%1$s)', 'give'), '&#3647;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
319
			'symbol'      => '&#3647;',
320
			'setting'     => array(
321
				'currency_position'   => 'before',
322
				'thousands_separator' => ',',
323
				'decimal_separator'   => '.',
324
				'number_decimals'     => 2,
325
			),
326
		),
327
		'INR' => array(
328
			'admin_label' => sprintf( __('Indian Rupee (%1$s)', 'give'), '&#8377;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
329
			'symbol'      => '&#8377;',
330
			'setting'     => array(
331
				'currency_position'   => 'before',
332
				'thousands_separator' => ',',
333
				'decimal_separator'   => '.',
334
				'number_decimals'     => 2,
335
			),
336
		),
337
		'TRY' => array(
338
			'admin_label' => sprintf( __('Turkish Lira (%1$s)', 'give'), '&#8378;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
339
			'symbol'      => '&#8378;',
340
			'setting'     => array(
341
				'currency_position'   => 'after',
342
				'thousands_separator' => ',',
343
				'decimal_separator'   => '.',
344
				'number_decimals'     => 2,
345
			),
346
		),
347
		'IRR' => array(
348
			'admin_label' => sprintf( __('Iranian Rial (%1$s)', 'give'), '&#xfdfc;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
349
			'symbol'      => '&#xfdfc;',
350
			'setting'     => array(
351
				'currency_position'   => 'after',
352
				'thousands_separator' => ',',
353
				'decimal_separator'   => '.',
354
				'number_decimals'     => 2,
355
			),
356
		),
357
		'RUB' => array(
358
			'admin_label' => sprintf( __('Russian Rubles (%1$s)', 'give'), '&#8381;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
359
			'symbol'      => '&#8381;',
360
			'setting'     => array(
361
				'currency_position'   => 'before',
362
				'thousands_separator' => '.',
363
				'decimal_separator'   => ',',
364
				'number_decimals'     => 2,
365
			),
366
		),
367
		'AED' => array(
368
			'admin_label' => sprintf( __('United Arab Emirates dirham (%1$s)', 'give'), '&#x62f;.&#x625;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
369
			'symbol'      => '&#x62f;.&#x625;',
370
			'setting'     => array(
371
				'currency_position'   => 'before',
372
				'thousands_separator' => ',',
373
				'decimal_separator'   => '.',
374
				'number_decimals'     => 2,
375
			),
376
		),
377
		'AMD' => array(
378
			'admin_label' => sprintf( __('Armenian dram (%1$s)', 'give'), 'AMD'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
379
			'symbol'      => 'AMD', // Add backward compatibility. Using AMD in place of &#1423;
380
			'setting'     => array(
381
				'currency_position'   => 'before',
382
				'thousands_separator' => ',',
383
				'decimal_separator'   => '.',
384
				'number_decimals'     => 2,
385
			),
386
		),
387
		'ANG' => array(
388
			'admin_label' => sprintf( __('Netherlands Antillean guilder (%1$s)', 'give'), '&#402;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
389
			'symbol'      => '&#402;',
390
			'setting'     => array(
391
				'currency_position'   => 'before',
392
				'thousands_separator' => '.',
393
				'decimal_separator'   => ',',
394
				'number_decimals'     => 2,
395
			),
396
		),
397
		'ARS' => array(
398
			'admin_label' => sprintf( __('Argentine peso (%1$s)', 'give'), '&#36;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
399
			'symbol'      => '&#36;',
400
			'setting'     => array(
401
				'currency_position'   => 'before',
402
				'thousands_separator' => '.',
403
				'decimal_separator'   => ',',
404
				'number_decimals'     => 2,
405
			),
406
		),
407
		'AWG' => array(
408
			'admin_label' => sprintf( __( 'Aruban florin (%1$s)', 'give' ), '&#402;' ),
409
			'symbol'      => '&#402;',
410
			'setting'     => array(
411
				'currency_position'   => 'before',
412
				'thousands_separator' => ',',
413
				'decimal_separator'   => '.',
414
				'number_decimals'     => 2,
415
			),
416
		),
417
		'BAM' => array(
418
			'admin_label' => sprintf( __( 'Bosnia and Herzegovina convertible mark (%1$s)', 'give' ), '&#75;&#77;' ),
419
			'symbol'      => '&#75;&#77;',
420
			'setting'     => array(
421
				'currency_position'   => 'before',
422
				'thousands_separator' => ',',
423
				'decimal_separator'   => '.',
424
				'number_decimals'     => 2,
425
			),
426
		),
427
		'BDT' => array(
428
			'admin_label' => sprintf( __( 'Bangladeshi taka (%1$s)', 'give' ), '&#2547;' ),
429
			'symbol'      => '&#2547;',
430
			'setting'     => array(
431
				'currency_position'   => 'before',
432
				'thousands_separator' => ',',
433
				'decimal_separator'   => '.',
434
				'number_decimals'     => 2,
435
			),
436
		),
437
		'BHD' => array(
438
			'admin_label' => sprintf( __( 'Bahraini dinar (%1$s)', 'give' ), '.&#x62f;.&#x628;' ),
439
			'symbol'      => '.&#x62f;.&#x628;',
440
			'setting'     => array(
441
				'currency_position'   => 'before',
442
				'thousands_separator' => ',',
443
				'decimal_separator'   => '.',
444
				'number_decimals'     => 3,
445
			),
446
		),
447
		'BMD' => array(
448
			'admin_label' => sprintf( __( 'Bermudian dollar (%1$s)', 'give' ), '&#66;&#68;&#36;' ),
449
			'symbol'      => '&#66;&#68;&#36;',
450
			'setting'     => array(
451
				'currency_position'   => 'before',
452
				'thousands_separator' => ',',
453
				'decimal_separator'   => '.',
454
				'number_decimals'     => 2,
455
			),
456
		),
457
		'BND' => array(
458
			'admin_label' => sprintf( __( 'Brunei dollar (%1$s)', 'give' ), '&#66;&#36;' ),
459
			'symbol'      => '&#66;&#36;',
460
			'setting'     => array(
461
				'currency_position'   => 'before',
462
				'thousands_separator' => ',',
463
				'decimal_separator'   => '.',
464
				'number_decimals'     => 2,
465
			),
466
		),
467
		'BOB' => array(
468
			'admin_label' => sprintf( __( 'Bolivian boliviano (%1$s)', 'give' ), '&#66;&#115;&#46;' ),
469
			'symbol'      => '&#66;&#115;&#46;',
470
			'setting'     => array(
471
				'currency_position'   => 'before',
472
				'thousands_separator' => ',',
473
				'decimal_separator'   => '.',
474
				'number_decimals'     => 2,
475
			),
476
		),
477
		'BSD' => array(
478
			'admin_label' => sprintf( __( 'Bahamian dollar (%1$s)', 'give' ), '&#66;&#36;' ),
479
			'symbol'      => '&#66;&#36;',
480
			'setting'     => array(
481
				'currency_position'   => 'before',
482
				'thousands_separator' => ',',
483
				'decimal_separator'   => '.',
484
				'number_decimals'     => 2,
485
			),
486
		),
487
		'BWP' => array(
488
			'admin_label' => sprintf( __( 'Botswana pula (%1$s)', 'give' ), '&#80;' ),
489
			'symbol'      => '&#80;',
490
			'setting'     => array(
491
				'currency_position'   => 'before',
492
				'thousands_separator' => ',',
493
				'decimal_separator'   => '.',
494
				'number_decimals'     => 2,
495
			),
496
		),
497
		'BZD' => array(
498
			'admin_label' => sprintf( __( 'Belizean dollar (%1$s)', 'give' ), '&#66;&#90;&#36;' ),
499
			'symbol'      => '&#66;&#90;&#36;',
500
			'setting'     => array(
501
				'currency_position'   => 'before',
502
				'thousands_separator' => ',',
503
				'decimal_separator'   => '.',
504
				'number_decimals'     => 2,
505
			),
506
		),
507
		'CLP' => array(
508
			'admin_label' => sprintf( __( 'Chilean peso (%1$s)', 'give' ), '&#36;' ),
509
			'symbol'      => '&#36;',
510
			'setting'     => array(
511
				'currency_position'   => 'before',
512
				'thousands_separator' => '.',
513
				'decimal_separator'   => '',
514
				'number_decimals'     => 0,
515
			),
516
		),
517
		'CNY' => array(
518
			'admin_label' => sprintf( __( 'Chinese yuan (%1$s)', 'give' ), '&yen;' ),
519
			'symbol'      => '&yen;',
520
			'setting'     => array(
521
				'currency_position'   => 'before',
522
				'thousands_separator' => ',',
523
				'decimal_separator'   => '.',
524
				'number_decimals'     => 2,
525
			),
526
		),
527
		'COP' => array(
528
			'admin_label' => sprintf( __( 'Colombian peso (%1$s)', 'give' ), '&#36;' ),
529
			'symbol'      => '&#36;',
530
			'setting'     => array(
531
				'currency_position'   => 'before',
532
				'thousands_separator' => '.',
533
				'decimal_separator'   => ',',
534
				'number_decimals'     => 2,
535
			),
536
		),
537
		'CRC' => array(
538
			'admin_label' => sprintf( __( 'Costa Rican colón (%1$s)', 'give' ), '&#8353;' ),
539
			'symbol'      => '&#8353;',
540
			'setting'     => array(
541
				'currency_position'   => 'before',
542
				'thousands_separator' => '.',
543
				'decimal_separator'   => ',',
544
				'number_decimals'     => 2,
545
			),
546
		),
547
		'CUC' => array(
548
			'admin_label' => sprintf( __( 'Cuban convertible peso (%1$s)', 'give' ), '&#8369;' ),
549
			'symbol'      => '&#8369;',
550
			'setting'     => array(
551
				'currency_position'   => 'before',
552
				'thousands_separator' => ',',
553
				'decimal_separator'   => '.',
554
				'number_decimals'     => 2,
555
			),
556
		),
557
		'CUP' => array(
558
			'admin_label' => sprintf( __( 'Cuban convertible peso (%1$s)', 'give' ), '&#8369;' ),
559
			'symbol'      => '&#8369;',
560
			'setting'     => array(
561
				'currency_position'   => 'before',
562
				'thousands_separator' => ',',
563
				'decimal_separator'   => '.',
564
				'number_decimals'     => 2,
565
			),
566
		),
567
		'DOP' => array(
568
			'admin_label' => sprintf( __( 'Dominican peso (%1$s)', 'give' ), '&#82;&#68;&#36;' ),
569
			'symbol'      => '&#82;&#68;&#36;',
570
			'setting'     => array(
571
				'currency_position'   => 'before',
572
				'thousands_separator' => ',',
573
				'decimal_separator'   => '.',
574
				'number_decimals'     => 2,
575
			),
576
		),
577
		'EGP' => array(
578
			'admin_label' => sprintf( __( 'Egyptian pound (%1$s)', 'give' ), '&#69;&pound;' ),
579
			'symbol'      => '&#69;&pound;',
580
			'setting'     => array(
581
				'currency_position'   => 'before',
582
				'thousands_separator' => ',',
583
				'decimal_separator'   => '.',
584
				'number_decimals'     => 2,
585
			),
586
		),
587
		'GIP' => array(
588
			'admin_label' => sprintf( __( 'Gibraltar pound (%1$s)', 'give' ), '&pound;' ),
589
			'symbol'      => '&pound;',
590
			'setting'     => array(
591
				'currency_position'   => 'before',
592
				'thousands_separator' => ',',
593
				'decimal_separator'   => '.',
594
				'number_decimals'     => 2,
595
			),
596
		),
597
		'GTQ' => array(
598
			'admin_label' => sprintf( __( 'Guatemalan quetzal (%1$s)', 'give' ), '&#81;' ),
599
			'symbol'      => '&#81;',
600
			'setting'     => array(
601
				'currency_position'   => 'before',
602
				'thousands_separator' => ',',
603
				'decimal_separator'   => '.',
604
				'number_decimals'     => 2,
605
			),
606
		),
607
		'HNL' => array(
608
			'admin_label' => sprintf( __( 'Honduran lempira (%1$s)', 'give' ), '&#76;' ),
609
			'symbol'      => '&#76;',
610
			'setting'     => array(
611
				'currency_position'   => 'before',
612
				'thousands_separator' => ',',
613
				'decimal_separator'   => '.',
614
				'number_decimals'     => 2,
615
			),
616
		),
617
		'HRK' => array(
618
			'admin_label' => sprintf( __( 'Croatian kuna (%1$s)', 'give' ), '&#107;&#110;' ),
619
			'symbol'      => '&#107;&#110;',
620
			'setting'     => array(
621
				'currency_position'   => 'after',
622
				'thousands_separator' => '.',
623
				'decimal_separator'   => ',',
624
				'number_decimals'     => 2,
625
			),
626
		),
627
		'IDR' => array(
628
			'admin_label' => sprintf( __( 'Indonesian rupiah (%1$s)', 'give' ), '&#82;&#112;' ),
629
			'symbol'      => '&#82;&#112;',
630
			'setting'     => array(
631
				'currency_position'   => 'before',
632
				'thousands_separator' => '.',
633
				'decimal_separator'   => ',',
634
				'number_decimals'     => 2,
635
			),
636
		),
637
		'ISK' => array(
638
			'admin_label' => sprintf( __( 'Icelandic króna (%1$s)', 'give' ), '&#107;&#114;' ),
639
			'symbol'      => '&#107;&#114;',
640
			'setting'     => array(
641
				'currency_position'   => 'after',
642
				'thousands_separator' => '.',
643
				'decimal_separator'   => '',
644
				'number_decimals'     => 0,
645
			),
646
		),
647
		'JMD' => array(
648
			'admin_label' => sprintf( __( 'Jamaican dollar (%1$s)', 'give' ), '&#106;&#36;' ),
649
			'symbol'      => '&#106;&#36;',
650
			'setting'     => array(
651
				'currency_position'   => 'before',
652
				'thousands_separator' => ',',
653
				'decimal_separator'   => '.',
654
				'number_decimals'     => 2,
655
			),
656
		),
657
		'JOD' => array(
658
			'admin_label' => sprintf( __( 'Jordanian dinar (%1$s)', 'give' ), '&#x62f;.&#x627;' ),
659
			'symbol'      => '&#x62f;.&#x627;',
660
			'setting'     => array(
661
				'currency_position'   => 'before',
662
				'thousands_separator' => ',',
663
				'decimal_separator'   => '.',
664
				'number_decimals'     => 3,
665
			),
666
		),
667
		'KES' => array(
668
			'admin_label' => sprintf( __( 'Kenyan shilling (%1$s)', 'give' ), '&#75;&#83;&#104;' ),
669
			'symbol'      => '&#75;&#83;&#104;',
670
			'setting'     => array(
671
				'currency_position'   => 'before',
672
				'thousands_separator' => ',',
673
				'decimal_separator'   => '.',
674
				'number_decimals'     => 2,
675
			),
676
		),
677
		'KWD' => array(
678
			'admin_label' => sprintf( __( 'Kuwaiti dinar (%1$s)', 'give' ), '&#x62f;.&#x643;' ),
679
			'symbol'      => '&#x62f;.&#x643;',
680
			'setting'     => array(
681
				'currency_position'   => 'before',
682
				'thousands_separator' => ',',
683
				'decimal_separator'   => '.',
684
				'number_decimals'     => 3,
685
			),
686
		),
687
		'KYD' => array(
688
			'admin_label' => sprintf( __( 'Cayman Islands dollar (%1$s)', 'give' ), '&#75;&#89;&#36;' ),
689
			'symbol'      => '&#75;&#89;&#36;',
690
			'setting'     => array(
691
				'currency_position'   => 'before',
692
				'thousands_separator' => ',',
693
				'decimal_separator'   => '.',
694
				'number_decimals'     => 2,
695
			),
696
		),
697
		'MKD' => array(
698
			'admin_label' => sprintf( __( 'Macedonian denar (%1$s)', 'give' ), '&#x434;&#x435;&#x43d;' ),
699
			'symbol'      => '&#x434;&#x435;&#x43d;',
700
			'setting'     => array(
701
				'currency_position'   => 'before',
702
				'thousands_separator' => ',',
703
				'decimal_separator'   => '.',
704
				'number_decimals'     => 2,
705
			),
706
		),
707
		'NPR' => array(
708
			'admin_label' => sprintf( __( 'Nepalese rupee (%1$s)', 'give' ), '&#8360;' ),
709
			'symbol'      => '&#8360;',
710
			'setting'     => array(
711
				'currency_position'   => 'before',
712
				'thousands_separator' => ',',
713
				'decimal_separator'   => '.',
714
				'number_decimals'     => 2,
715
			),
716
		),
717
		'OMR' => array(
718
			'admin_label' => sprintf( __( 'Omani rial (%1$s)', 'give' ), '&#x631;.&#x639;&#46;' ),
719
			'symbol'      => '&#x631;.&#x639;&#46;',
720
			'setting'     => array(
721
				'currency_position'   => 'before',
722
				'thousands_separator' => ',',
723
				'decimal_separator'   => '.',
724
				'number_decimals'     => 3,
725
			),
726
		),
727
		'PEN' => array(
728
			'admin_label' => sprintf( __( 'Peruvian nuevo sol (%1$s)', 'give' ), 'S/.' ),
729
			'symbol'      => 'S/.',
730
			'setting'     => array(
731
				'currency_position'   => 'before',
732
				'thousands_separator' => ',',
733
				'decimal_separator'   => '.',
734
				'number_decimals'     => 2,
735
			),
736
		),
737
		'PKR' => array(
738
			'admin_label' => sprintf( __( 'Pakistani rupee (%1$s)', 'give' ), '&#8360;' ),
739
			'symbol'      => '&#8360;',
740
			'setting'     => array(
741
				'currency_position'   => 'before',
742
				'thousands_separator' => ',',
743
				'decimal_separator'   => '.',
744
				'number_decimals'     => 2,
745
			),
746
		),
747
		'RON' => array(
748
			'admin_label' => sprintf( __( 'Romanian leu (%1$s)', 'give' ), '&#76;' ),
749
			'symbol'      => '&#76;',
750
			'setting'     => array(
751
				'currency_position'   => 'after',
752
				'thousands_separator' => '.',
753
				'decimal_separator'   => ',',
754
				'number_decimals'     => 2,
755
			),
756
		),
757
		'SAR' => array(
758
			'admin_label' => sprintf( __( 'Saudi riyal (%1$s)', 'give' ), '&#x631;.&#x633;' ),
759
			'symbol'      => '&#x631;.&#x633;',
760
			'setting'     => array(
761
				'currency_position'   => 'before',
762
				'thousands_separator' => ',',
763
				'decimal_separator'   => '.',
764
				'number_decimals'     => 2,
765
			),
766
		),
767
		'SZL' => array(
768
			'admin_label' => sprintf( __( 'Swazi lilangeni (%1$s)', 'give' ), '&#76;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
769
			'symbol'      => '&#76;',
770
			'setting'     => array(
771
				'currency_position'   => 'before',
772
				'thousands_separator' => ',',
773
				'decimal_separator'   => '.',
774
				'number_decimals'     => 2,
775
			),
776
		),
777
		'TOP' => array(
778
			'admin_label' => sprintf( __( 'Tongan paʻanga (%1$s)', 'give' ), '&#84;&#36;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
779
			'symbol'      => '&#84;&#36;',
780
			'setting'     => array(
781
				'currency_position'   => 'before',
782
				'thousands_separator' => ',',
783
				'decimal_separator'   => '.',
784
				'number_decimals'     => 2,
785
			),
786
		),
787
		'TZS' => array(
788
			'admin_label' => sprintf( __( 'Tanzanian shilling (%1$s)', 'give' ), '&#84;&#83;&#104;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
789
			'symbol'      => '&#84;&#83;&#104;',
790
			'setting'     => array(
791
				'currency_position'   => 'before',
792
				'thousands_separator' => ',',
793
				'decimal_separator'   => '.',
794
				'number_decimals'     => 2,
795
			),
796
		),
797
		'UAH' => array(
798
			'admin_label' => sprintf( __( 'Ukrainian hryvnia (%1$s)', 'give' ), '&#8372;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
799
			'symbol'      => '&#8372;',
800
			'setting'     => array(
801
				'currency_position'   => 'before',
802
				'thousands_separator' => ' ',
803
				'decimal_separator'   => ',',
804
				'number_decimals'     => 2,
805
			),
806
		),
807
		'UYU' => array(
808
			'admin_label' => sprintf( __( 'Uruguayan peso (%1$s)', 'give' ), '&#36;&#85;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
809
			'symbol'      => '&#36;&#85;',
810
			'setting'     => array(
811
				'currency_position'   => 'before',
812
				'thousands_separator' => '.',
813
				'decimal_separator'   => ',',
814
				'number_decimals'     => 2,
815
			),
816
		),
817
		'VEF' => array(
818
			'admin_label' => sprintf( __( 'Venezuelan bolívar (%1$s)', 'give' ), '&#66;&#115;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
819
			'symbol'      => '&#66;&#115;',
820
			'setting'     => array(
821
				'currency_position'   => 'before',
822
				'thousands_separator' => '.',
823
				'decimal_separator'   => ',',
824
				'number_decimals'     => 2,
825
			),
826
		),
827
		'XCD' => array(
828
			'admin_label' => sprintf( __( 'East Caribbean dollar (%1$s)', 'give' ), '&#69;&#67;&#36;'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
829
			'symbol'      => '&#69;&#67;&#36;',
830
			'setting'     => array(
831
				'currency_position'   => 'before',
832
				'thousands_separator' => ',',
833
				'decimal_separator'   => '.',
834
				'number_decimals'     => 2,
835
			),
836
		),
837
	);
838
839
	/**
840
	 * Filter the currencies
841
	 * Note: you can register new currency by using this filter
842
	 * array(
843
	 *     'admin_label' => '',  // required
844
	 *     'symbol'      => '',  // required
845
	 *     'setting'     => ''   // required
846
	 *     ....
847
	 * )
848
	 *
849
	 * @since 1.8.15
850
	 *
851
	 * @param array $currencies
852
	 */
853
	return (array) apply_filters( 'give_currencies', $currencies );
854
}
855
856
/**
857
 * Get Currencies
858
 *
859
 * @since 1.0
860
 *
861
 * @param string $info Specify currency info
862
 *
863
 * @return array $currencies A list of the available currencies
864
 */
865
function give_get_currencies( $info = 'admin_label' ) {
866
867
	$currencies = give_get_currencies_list();
868
869
	// Backward compatibility: handle old way of currency registration.
870
	// Backward compatibility: Return desired result.
871
	if ( ! empty( $currencies ) ) {
872
		foreach ( $currencies as $currency_code => $currency_setting ) {
873
			if ( is_string( $currency_setting ) ) {
874
				$currencies[ $currency_code ] = array(
875
					'admin_label' => $currency_setting,
876
				);
877
			}
878
879
			$currencies[ $currency_code ] = wp_parse_args(
880
				$currencies[ $currency_code ],
881
				array(
882
					'admin_label' => '',
883
					'symbol'      => $currency_code,
884
					'setting'     => array(),
885
				)
886
			);
887
		}
888
889
		if ( ! empty( $info ) && is_string( $info ) && 'all' !== $info ) {
890
			$currencies = wp_list_pluck( $currencies, $info );
891
		}
892
	}
893
894
	return $currencies;
895
}
896
897
898
/**
899
 * Get all currency symbols
900
 *
901
 * @since 1.8.14
902
 *
903
 * @param bool $decode_currencies
904
 *
905
 * @return array
906
 */
907
function give_currency_symbols( $decode_currencies = false ) {
908
	$currencies = give_get_currencies( 'symbol' );
909
910
	if ( $decode_currencies ) {
911
		array_walk( $currencies, function ( &$currency_symbol ) {
912
			$currency_symbol = html_entity_decode( $currency_symbol, ENT_COMPAT, 'UTF-8' );
913
		} );
914
	}
915
916
	/**
917
	 * Filter the currency symbols
918
	 *
919
	 * @since 1.8.14
920
	 *
921
	 * @param array $currencies
922
	 */
923
	return apply_filters( 'give_currency_symbols', $currencies );
924
}
925
926
927
/**
928
 * Give Currency Symbol
929
 *
930
 * Given a currency determine the symbol to use. If no currency given, site default is used. If no symbol is determine,
931
 * the currency string is returned.
932
 *
933
 * @since      1.0
934
 *
935
 * @param  string $currency        The currency string.
936
 * @param  bool   $decode_currency Option to HTML decode the currency symbol.
937
 *
938
 * @return string           The symbol to use for the currency
939
 */
940 View Code Duplication
function give_currency_symbol( $currency = '', $decode_currency = false ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

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.

Loading history...
941
942
	if ( empty( $currency ) ) {
943
		$currency = give_get_currency();
944
	}
945
946
	$currencies = give_currency_symbols( $decode_currency );
947
	$symbol     = array_key_exists( $currency, $currencies ) ? $currencies[ $currency ] : $currency;
948
949
	/**
950
	 * Filter the currency symbol
951
	 *
952
	 * @since 1.0
953
	 *
954
	 * @param string $symbol
955
	 * @param string $currency
956
	 */
957
	return apply_filters( 'give_currency_symbol', $symbol, $currency );
958
}
959
960
961
/**
962
 * Get currency name.
963
 *
964
 * @since 1.8.8
965
 *
966
 * @param string $currency_code
967
 *
968
 * @return string
969
 */
970
function give_get_currency_name( $currency_code ) {
971
	$currency_name  = '';
972
	$currency_names = give_get_currencies();
973
974
	if ( $currency_code && array_key_exists( $currency_code, $currency_names ) ) {
975
		$currency_name = explode( '(', $currency_names[ $currency_code ] );
976
		$currency_name = trim( current( $currency_name ) );
977
	}
978
979
	/**
980
	 * Filter the currency name
981
	 *
982
	 * @since 1.8.8
983
	 *
984
	 * @param string $currency_name
985
	 * @param string $currency_code
986
	 */
987
	return apply_filters( 'give_currency_name', $currency_name, $currency_code );
988
}
989
990
/**
991
 * Formats the currency displayed.
992
 *
993
 * @since 1.0
994
 *
995
 * @param string $price The donation amount.
996
 * @param array  $args  It accepts 'currency_code', 'decode_currency' and 'form_id'.
997
 *
998
 * @return mixed|string
999
 */
1000
function give_currency_filter( $price = '', $args = array() ) {
1001
1002
	// Get functions arguments.
1003
	$func_args = func_get_args();
1004
1005
	// Backward compatibility: modify second param to array
1006
	if ( isset( $func_args[1] ) && is_string( $func_args[1] ) ) {
1007
		$args = array(
1008
			'currency_code'   => isset( $func_args[1] ) ? $func_args[1] : '',
1009
			'decode_currency' => isset( $func_args[2] ) ? $func_args[2] : false,
1010
			'form_id'         => isset( $func_args[3] ) ? $func_args[3] : '',
1011
		);
1012
1013
		give_doing_it_wrong( __FUNCTION__, 'Pass second argument as Array.', GIVE_VERSION );
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' :
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
1071
			$formatted = ( 'before' === $args['position'] ? $args['symbol'] . $price : $price . $args['symbol'] );
1072
			break;
1073 View Code Duplication
		case 'NOK':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
1074
			$formatted = ( 'before' === $args['position'] ? $args['symbol'] . ' ' . $price : $price . ' ' . $args['symbol'] );
1075
			break;
1076 View Code Duplication
		default:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
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
}