Test Failed
Push — master ( 9726e4...da6cd0 )
by Ravinder
07:07
created
includes/formatting.php 1 patch
Spacing   +185 added lines, -189 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  */
11 11
 
12 12
 // Exit if accessed directly.
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -23,37 +23,37 @@  discard block
 block discarded – undo
23 23
  *
24 24
  * @return mixed
25 25
  */
26
-function give_get_currency_formatting_settings( $id_or_currency_code = null ) {
26
+function give_get_currency_formatting_settings($id_or_currency_code = null) {
27 27
 	$give_options = give_get_settings();
28 28
 	$setting      = array();
29 29
 
30
-	if ( ! empty( $id_or_currency_code ) ) {
31
-		$currencies = give_get_currencies( 'all' );
30
+	if ( ! empty($id_or_currency_code)) {
31
+		$currencies = give_get_currencies('all');
32 32
 
33 33
 		// Set default formatting setting only if currency not set as global currency.
34 34
 		if (
35
-			is_string( $id_or_currency_code ) &&
36
-			! empty( $give_options['currency'] ) &&
35
+			is_string($id_or_currency_code) &&
36
+			! empty($give_options['currency']) &&
37 37
 			$id_or_currency_code !== $give_options['currency'] &&
38
-			array_key_exists( $id_or_currency_code, $currencies )
38
+			array_key_exists($id_or_currency_code, $currencies)
39 39
 		) {
40
-			$setting = $currencies[ $id_or_currency_code ]['setting'];
41
-		} elseif ( is_numeric( $id_or_currency_code ) && 'give_payment' === get_post_type( $id_or_currency_code ) ) {
42
-			$currency = give_get_meta( $id_or_currency_code, '_give_payment_currency', true );
40
+			$setting = $currencies[$id_or_currency_code]['setting'];
41
+		} elseif (is_numeric($id_or_currency_code) && 'give_payment' === get_post_type($id_or_currency_code)) {
42
+			$currency = give_get_meta($id_or_currency_code, '_give_payment_currency', true);
43 43
 
44 44
 			if (
45
-				! empty( $currency) &&
45
+				! empty($currency) &&
46 46
 				$give_options['currency'] !== $currency
47 47
 			) {
48
-				$setting = $currencies[ $currency ]['setting'];
48
+				$setting = $currencies[$currency]['setting'];
49 49
 			}
50 50
 		}
51 51
 	}
52 52
 
53
-	if ( empty( $setting ) ) {
53
+	if (empty($setting)) {
54 54
 		// Set thousand separator.
55
-		$thousand_separator = isset( $give_options['thousands_separator'] ) ? $give_options['thousands_separator'] : ',';
56
-		$thousand_separator = empty( $thousand_separator ) ? ' ' : $thousand_separator;
55
+		$thousand_separator = isset($give_options['thousands_separator']) ? $give_options['thousands_separator'] : ',';
56
+		$thousand_separator = empty($thousand_separator) ? ' ' : $thousand_separator;
57 57
 
58 58
 		// Set decimal separator.
59 59
 		$default_decimal_separators = array(
@@ -61,17 +61,16 @@  discard block
 block discarded – undo
61 61
 			',' => '.',
62 62
 		);
63 63
 
64
-		$default_decimal_separator = in_array( $thousand_separator, $default_decimal_separators ) ?
65
-			$default_decimal_separators[ $thousand_separator ] :
66
-			'.';
64
+		$default_decimal_separator = in_array($thousand_separator, $default_decimal_separators) ?
65
+			$default_decimal_separators[$thousand_separator] : '.';
67 66
 
68
-		$decimal_separator = ! empty( $give_options['decimal_separator'] ) ? $give_options['decimal_separator'] : $default_decimal_separator;
67
+		$decimal_separator = ! empty($give_options['decimal_separator']) ? $give_options['decimal_separator'] : $default_decimal_separator;
69 68
 
70 69
 		$setting = array(
71
-			'currency_position'   => give_get_option( 'currency_position', 'before' ),
70
+			'currency_position'   => give_get_option('currency_position', 'before'),
72 71
 			'thousands_separator' => $thousand_separator,
73 72
 			'decimal_separator'   => $decimal_separator,
74
-			'number_decimals'     => give_get_option( 'number_decimals', 0 ),
73
+			'number_decimals'     => give_get_option('number_decimals', 0),
75 74
 		);
76 75
 	}
77 76
 
@@ -80,7 +79,7 @@  discard block
 block discarded – undo
80 79
 	 *
81 80
 	 * @since 1.8.15
82 81
 	 */
83
-	return apply_filters( 'give_get_currency_formatting_settings', $setting, $id_or_currency_code );
82
+	return apply_filters('give_get_currency_formatting_settings', $setting, $id_or_currency_code);
84 83
 }
85 84
 
86 85
 /**
@@ -92,16 +91,16 @@  discard block
 block discarded – undo
92 91
  *
93 92
  * @return mixed
94 93
  */
95
-function give_get_price_decimals( $id_or_currency_code = null ) {
94
+function give_get_price_decimals($id_or_currency_code = null) {
96 95
 	// Set currency on basis of donation id.
97
-	if ( empty( $id_or_currency_code ) ) {
96
+	if (empty($id_or_currency_code)) {
98 97
 		$id_or_currency_code = give_get_currency();
99 98
 	}
100 99
 
101 100
 	$number_of_decimals = 0;
102 101
 
103
-	if ( ! give_is_zero_based_currency( $id_or_currency_code ) ) {
104
-		$setting            = give_get_currency_formatting_settings( $id_or_currency_code );
102
+	if ( ! give_is_zero_based_currency($id_or_currency_code)) {
103
+		$setting            = give_get_currency_formatting_settings($id_or_currency_code);
105 104
 		$number_of_decimals = $setting['number_decimals'];
106 105
 	}
107 106
 
@@ -110,7 +109,7 @@  discard block
 block discarded – undo
110 109
 	 *
111 110
 	 * @since 1.6
112 111
 	 */
113
-	return apply_filters( 'give_sanitize_amount_decimals', $number_of_decimals, $id_or_currency_code );
112
+	return apply_filters('give_sanitize_amount_decimals', $number_of_decimals, $id_or_currency_code);
114 113
 }
115 114
 
116 115
 /**
@@ -122,15 +121,15 @@  discard block
 block discarded – undo
122 121
  *
123 122
  * @return mixed
124 123
  */
125
-function give_get_price_thousand_separator( $id_or_currency_code = null ) {
126
-	$setting = give_get_currency_formatting_settings( $id_or_currency_code );
124
+function give_get_price_thousand_separator($id_or_currency_code = null) {
125
+	$setting = give_get_currency_formatting_settings($id_or_currency_code);
127 126
 
128 127
 	/**
129 128
 	 * Filter the thousand separator
130 129
 	 *
131 130
 	 * @since 1.6
132 131
 	 */
133
-	return apply_filters( 'give_get_price_thousand_separator', $setting['thousands_separator'], $id_or_currency_code );
132
+	return apply_filters('give_get_price_thousand_separator', $setting['thousands_separator'], $id_or_currency_code);
134 133
 }
135 134
 
136 135
 /**
@@ -142,15 +141,15 @@  discard block
 block discarded – undo
142 141
  *
143 142
  * @return mixed
144 143
  */
145
-function give_get_price_decimal_separator( $id_or_currency_code = null ) {
146
-	$setting = give_get_currency_formatting_settings( $id_or_currency_code );
144
+function give_get_price_decimal_separator($id_or_currency_code = null) {
145
+	$setting = give_get_currency_formatting_settings($id_or_currency_code);
147 146
 
148 147
 	/**
149 148
 	 * Filter the thousand separator
150 149
 	 *
151 150
 	 * @since 1.6
152 151
 	 */
153
-	return apply_filters( 'give_get_price_decimal_separator', $setting['decimal_separator'], $id_or_currency_code );
152
+	return apply_filters('give_get_price_decimal_separator', $setting['decimal_separator'], $id_or_currency_code);
154 153
 }
155 154
 
156 155
 
@@ -164,10 +163,10 @@  discard block
 block discarded – undo
164 163
  *
165 164
  * @return string $amount Newly sanitized amount
166 165
  */
167
-function give_sanitize_amount_for_db( $number, $args = array() ) {
166
+function give_sanitize_amount_for_db($number, $args = array()) {
168 167
 	$args['number_decimals'] = 6;
169 168
 
170
-	return give_maybe_sanitize_amount( $number, $args );
169
+	return give_maybe_sanitize_amount($number, $args);
171 170
 }
172 171
 
173 172
 /**
@@ -180,19 +179,19 @@  discard block
 block discarded – undo
180 179
  *
181 180
  * @return string $amount Newly sanitized amount
182 181
  */
183
-function give_maybe_sanitize_amount( $number, $args = array() ) {
182
+function give_maybe_sanitize_amount($number, $args = array()) {
184 183
 	// Bailout.
185
-	if ( empty( $number ) || ( ! is_numeric( $number ) && ! is_string( $number ) ) ) {
184
+	if (empty($number) || ( ! is_numeric($number) && ! is_string($number))) {
186 185
 		return $number;
187 186
 	}
188 187
 
189 188
 	$func_args = func_get_args();
190 189
 
191 190
 	// Backward compatibility.
192
-	if ( isset( $func_args[1] ) && ( is_bool( $func_args[1] ) || is_numeric( $func_args[1] ) ) ) {
191
+	if (isset($func_args[1]) && (is_bool($func_args[1]) || is_numeric($func_args[1]))) {
193 192
 		$args = array(
194 193
 			'number_decimals' => $func_args[1],
195
-			'trim_zeros'      => isset( $func_args[2] ) ? $func_args[2] : false,
194
+			'trim_zeros'      => isset($func_args[2]) ? $func_args[2] : false,
196 195
 		);
197 196
 	}
198 197
 
@@ -205,24 +204,23 @@  discard block
 block discarded – undo
205 204
 		)
206 205
 	);
207 206
 
208
-	$thousand_separator = give_get_price_thousand_separator( $args['currency'] );
209
-	$decimal_separator  = give_get_price_decimal_separator( $args['currency'] );
210
-	$number_decimals    = is_bool( $args['number_decimals'] ) ?
211
-		give_get_price_decimals() :
212
-		$args['number_decimals'];
207
+	$thousand_separator = give_get_price_thousand_separator($args['currency']);
208
+	$decimal_separator  = give_get_price_decimal_separator($args['currency']);
209
+	$number_decimals    = is_bool($args['number_decimals']) ?
210
+		give_get_price_decimals() : $args['number_decimals'];
213 211
 
214 212
 	// Explode number by . decimal separator.
215
-	$number_parts = explode( '.', $number );
213
+	$number_parts = explode('.', $number);
216 214
 
217 215
 	// Remove currency symbols from number if any.
218
-	$number = trim( str_replace( give_currency_symbols( true ), '', $number ) );
216
+	$number = trim(str_replace(give_currency_symbols(true), '', $number));
219 217
 
220 218
 	if (
221 219
 		// Non formatted number.
222
-		false === strpos( $number, $thousand_separator )
223
-		&& false === strpos( $number, $decimal_separator )
220
+		false === strpos($number, $thousand_separator)
221
+		&& false === strpos($number, $decimal_separator)
224 222
 	) {
225
-		return number_format( $number, $number_decimals, '.', '' );
223
+		return number_format($number, $number_decimals, '.', '');
226 224
 	} elseif (
227 225
 		// Decimal formatted number.
228 226
 		// If number of decimal place set to non zero and
@@ -230,34 +228,34 @@  discard block
 block discarded – undo
230 228
 		// then number will be consider as decimal formatted which means number is already sanitized.
231 229
 		$number_decimals
232 230
 		&& '.' === $thousand_separator
233
-		&& false !== strpos( $number, $thousand_separator )
234
-		&& false === strpos( $number, $decimal_separator )
235
-		&& 2 === count( $number_parts )
236
-		&& ( $number_decimals >= strlen( $number_parts[1] ) )
237
-	){
238
-		return number_format( $number, $number_decimals, '.', '' );
231
+		&& false !== strpos($number, $thousand_separator)
232
+		&& false === strpos($number, $decimal_separator)
233
+		&& 2 === count($number_parts)
234
+		&& ($number_decimals >= strlen($number_parts[1]))
235
+	) {
236
+		return number_format($number, $number_decimals, '.', '');
239 237
 	}
240 238
 
241 239
 	// Handle thousand separator as '.'
242 240
 	// Handle sanitize database values.
243
-	$is_db_sanitize_val = ( 2 === count( $number_parts ) &&
244
-							is_numeric( $number_parts[0] ) &&
245
-							is_numeric( $number_parts[1] ) &&
246
-							( 6 === strlen( $number_parts[1] ) ) );
241
+	$is_db_sanitize_val = (2 === count($number_parts) &&
242
+							is_numeric($number_parts[0]) &&
243
+							is_numeric($number_parts[1]) &&
244
+							(6 === strlen($number_parts[1])));
247 245
 
248
-	if ( $is_db_sanitize_val ) {
246
+	if ($is_db_sanitize_val) {
249 247
 		// Sanitize database value.
250
-		return number_format( $number, $number_decimals, '.', '' );
248
+		return number_format($number, $number_decimals, '.', '');
251 249
 
252 250
 	} elseif (
253 251
 		'.' === $thousand_separator &&
254
-		false !== strpos( $number, $thousand_separator )
252
+		false !== strpos($number, $thousand_separator)
255 253
 	) {
256 254
 		// Fix point thousand separator value.
257
-		$number = str_replace( '.', '', $number );
255
+		$number = str_replace('.', '', $number);
258 256
 	}
259 257
 
260
-	return give_sanitize_amount( $number, $args );
258
+	return give_sanitize_amount($number, $args);
261 259
 }
262 260
 
263 261
 /**
@@ -274,10 +272,10 @@  discard block
 block discarded – undo
274 272
  *
275 273
  * @return string $amount Newly sanitized amount
276 274
  */
277
-function give_sanitize_amount( $number, $args = array() ) {
275
+function give_sanitize_amount($number, $args = array()) {
278 276
 
279 277
 	// Bailout.
280
-	if ( empty( $number ) || ( ! is_numeric( $number ) && ! is_string( $number ) ) ) {
278
+	if (empty($number) || ( ! is_numeric($number) && ! is_string($number))) {
281 279
 		return $number;
282 280
 	}
283 281
 
@@ -285,10 +283,10 @@  discard block
 block discarded – undo
285 283
 	$func_args = func_get_args();
286 284
 
287 285
 	// Backward compatibility.
288
-	if ( isset( $func_args[1] ) && ( is_bool( $func_args[1] ) || is_numeric( $func_args[1] ) ) ) {
286
+	if (isset($func_args[1]) && (is_bool($func_args[1]) || is_numeric($func_args[1]))) {
289 287
 		$args = array(
290 288
 			'number_decimals' => $func_args[1],
291
-			'trim_zeros'      => isset( $func_args[2] ) ? $func_args[2] : false,
289
+			'trim_zeros'      => isset($func_args[2]) ? $func_args[2] : false,
292 290
 		);
293 291
 	}
294 292
 
@@ -304,58 +302,58 @@  discard block
 block discarded – undo
304 302
 	// Remove slash from amount.
305 303
 	// If thousand or decimal separator is set to ' then in $_POST or $_GET param we will get an escaped number.
306 304
 	// To prevent notices and warning remove slash from amount/number.
307
-	$number = wp_unslash( $number );
305
+	$number = wp_unslash($number);
308 306
 
309
-	$thousand_separator = give_get_price_thousand_separator( $args['currency'] );
307
+	$thousand_separator = give_get_price_thousand_separator($args['currency']);
310 308
 
311 309
 	$locale   = localeconv();
312 310
 	$decimals = array(
313
-		give_get_price_decimal_separator( $args['currency'] ),
311
+		give_get_price_decimal_separator($args['currency']),
314 312
 		$locale['decimal_point'],
315 313
 		$locale['mon_decimal_point'],
316 314
 	);
317 315
 
318 316
 	// Remove locale from string
319
-	if ( ! is_float( $number ) ) {
320
-		$number = str_replace( $decimals, '.', $number );
317
+	if ( ! is_float($number)) {
318
+		$number = str_replace($decimals, '.', $number);
321 319
 	}
322 320
 
323 321
 	// Remove thousand amount formatting if amount has.
324 322
 	// This condition use to add backward compatibility to version before 1.6, because before version 1.6 we were saving formatted amount to db.
325 323
 	// Do not replace thousand separator from price if it is same as decimal separator, because it will be already replace by above code.
326
-	if ( ! in_array( $thousand_separator, $decimals ) && ( false !== strpos( $number, $thousand_separator ) ) ) {
327
-		$number = str_replace( $thousand_separator, '', $number );
328
-	} elseif ( in_array( $thousand_separator, $decimals ) ) {
329
-		$number = preg_replace( '/\.(?=.*\.)/', '', $number );
324
+	if ( ! in_array($thousand_separator, $decimals) && (false !== strpos($number, $thousand_separator))) {
325
+		$number = str_replace($thousand_separator, '', $number);
326
+	} elseif (in_array($thousand_separator, $decimals)) {
327
+		$number = preg_replace('/\.(?=.*\.)/', '', $number);
330 328
 	}
331 329
 
332 330
 	// Remove non numeric entity before decimal separator.
333
-	$number     = preg_replace( '/[^0-9\.]/', '', $number );
334
-	$default_dp = give_get_price_decimals( $args['currency'] );
331
+	$number     = preg_replace('/[^0-9\.]/', '', $number);
332
+	$default_dp = give_get_price_decimals($args['currency']);
335 333
 
336 334
 	// Reset negative amount to zero.
337
-	if ( 0 > $number ) {
338
-		$number = number_format( 0, $default_dp, '.' );
335
+	if (0 > $number) {
336
+		$number = number_format(0, $default_dp, '.');
339 337
 	}
340 338
 
341 339
 	// If number does not have decimal then add number of decimals to it.
342 340
 	if (
343
-		false === strpos( $number, '.' )
344
-		|| ( $default_dp > strlen( substr( $number, strpos( $number, '.' ) + 1 ) ) )
341
+		false === strpos($number, '.')
342
+		|| ($default_dp > strlen(substr($number, strpos($number, '.') + 1)))
345 343
 	) {
346
-		$number = number_format( $number, $default_dp, '.', '' );
344
+		$number = number_format($number, $default_dp, '.', '');
347 345
 	}
348 346
 
349 347
 	// Format number by custom number of decimals.
350
-	if ( false !== $args['number_decimals'] ) {
351
-		$dp     = intval( is_bool( $args['number_decimals'] ) ? $default_dp : $args['number_decimals'] );
352
-		$dp     = apply_filters( 'give_sanitize_amount_decimals', $dp, $number );
353
-		$number = number_format( floatval( $number ), $dp, '.', '' );
348
+	if (false !== $args['number_decimals']) {
349
+		$dp     = intval(is_bool($args['number_decimals']) ? $default_dp : $args['number_decimals']);
350
+		$dp     = apply_filters('give_sanitize_amount_decimals', $dp, $number);
351
+		$number = number_format(floatval($number), $dp, '.', '');
354 352
 	}
355 353
 
356 354
 	// Trim zeros.
357
-	if ( $args['trim_zeros'] && strstr( $number, '.' ) ) {
358
-		$number = rtrim( rtrim( $number, '0' ), '.' );
355
+	if ($args['trim_zeros'] && strstr($number, '.')) {
356
+		$number = rtrim(rtrim($number, '0'), '.');
359 357
 	}
360 358
 
361 359
 	/**
@@ -363,7 +361,7 @@  discard block
 block discarded – undo
363 361
 	 *
364 362
 	 * @since 1.0
365 363
 	 */
366
-	return apply_filters( 'give_sanitize_amount', $number );
364
+	return apply_filters('give_sanitize_amount', $number);
367 365
 }
368 366
 
369 367
 /**
@@ -376,9 +374,9 @@  discard block
 block discarded – undo
376 374
  *
377 375
  * @return string $amount   Newly formatted amount or Price Not Available
378 376
  */
379
-function give_format_amount( $amount, $args = array() ) {
377
+function give_format_amount($amount, $args = array()) {
380 378
 	// Backward compatibility.
381
-	if ( is_bool( $args ) ) {
379
+	if (is_bool($args)) {
382 380
 		$args = array(
383 381
 			'decimal' => $args,
384 382
 		);
@@ -391,60 +389,59 @@  discard block
 block discarded – undo
391 389
 		'currency'    => '',
392 390
 	);
393 391
 
394
-	$args = wp_parse_args( $args, $default_args );
392
+	$args = wp_parse_args($args, $default_args);
395 393
 
396 394
 	// Set Currency based on donation id, if required.
397
-	if ( $args['donation_id'] && empty( $args['currency'] ) ) {
398
-		$args['currency'] = give_get_meta( $args['donation_id'], '_give_payment_currency', true );
395
+	if ($args['donation_id'] && empty($args['currency'])) {
396
+		$args['currency'] = give_get_meta($args['donation_id'], '_give_payment_currency', true);
399 397
 	}
400 398
 
401 399
 	$formatted     = 0;
402
-	$currency      = ! empty( $args['currency'] ) ? $args['currency'] : give_get_currency( $args['donation_id'] );
403
-	$thousands_sep = give_get_price_thousand_separator( $currency );
404
-	$decimal_sep   = give_get_price_decimal_separator( $currency );
405
-	$decimals      = ! empty( $args['decimal'] ) ? give_get_price_decimals( $currency ) : 0;
400
+	$currency      = ! empty($args['currency']) ? $args['currency'] : give_get_currency($args['donation_id']);
401
+	$thousands_sep = give_get_price_thousand_separator($currency);
402
+	$decimal_sep   = give_get_price_decimal_separator($currency);
403
+	$decimals      = ! empty($args['decimal']) ? give_get_price_decimals($currency) : 0;
406 404
 
407
-	if ( ! empty( $amount ) ) {
405
+	if ( ! empty($amount)) {
408 406
 		// Sanitize amount before formatting.
409
-		$amount = ! empty( $args['sanitize'] ) ?
410
-			give_maybe_sanitize_amount( $amount, array( 'number_decimals' => $decimals, 'currency' => $currency ) ) :
411
-			number_format( $amount, $decimals, '.', '' );
407
+		$amount = ! empty($args['sanitize']) ?
408
+			give_maybe_sanitize_amount($amount, array('number_decimals' => $decimals, 'currency' => $currency)) : number_format($amount, $decimals, '.', '');
412 409
 
413
-		switch ( $currency ) {
410
+		switch ($currency) {
414 411
 			case 'INR':
415 412
 				$decimal_amount = '';
416 413
 
417 414
 				// Extract decimals from amount
418
-				if ( ( $pos = strpos( $amount, '.' ) ) !== false ) {
419
-					if ( ! empty( $decimals ) ) {
420
-						$decimal_amount = substr( round( substr( $amount, $pos ), $decimals ), 1 );
421
-						$amount         = substr( $amount, 0, $pos );
422
-
423
-						if ( ! $decimal_amount ) {
424
-							$decimal_amount = substr( "{$decimal_sep}0000000000", 0, ( $decimals + 1 ) );
425
-						} elseif ( ( $decimals + 1 ) > strlen( $decimal_amount ) ) {
426
-							$decimal_amount = substr( "{$decimal_amount}000000000", 0, ( $decimals + 1 ) );
415
+				if (($pos = strpos($amount, '.')) !== false) {
416
+					if ( ! empty($decimals)) {
417
+						$decimal_amount = substr(round(substr($amount, $pos), $decimals), 1);
418
+						$amount         = substr($amount, 0, $pos);
419
+
420
+						if ( ! $decimal_amount) {
421
+							$decimal_amount = substr("{$decimal_sep}0000000000", 0, ($decimals + 1));
422
+						} elseif (($decimals + 1) > strlen($decimal_amount)) {
423
+							$decimal_amount = substr("{$decimal_amount}000000000", 0, ($decimals + 1));
427 424
 						}
428 425
 					} else {
429
-						$amount = number_format( $amount, $decimals, $decimal_sep, '' );
426
+						$amount = number_format($amount, $decimals, $decimal_sep, '');
430 427
 					}
431 428
 				}
432 429
 
433 430
 				// Extract last 3 from amount
434
-				$result = substr( $amount, - 3 );
435
-				$amount = substr( $amount, 0, - 3 );
431
+				$result = substr($amount, - 3);
432
+				$amount = substr($amount, 0, - 3);
436 433
 
437 434
 				// Apply digits 2 by 2
438
-				while ( strlen( $amount ) > 0 ) {
439
-					$result = substr( $amount, - 2 ) . $thousands_sep . $result;
440
-					$amount = substr( $amount, 0, - 2 );
435
+				while (strlen($amount) > 0) {
436
+					$result = substr($amount, - 2).$thousands_sep.$result;
437
+					$amount = substr($amount, 0, - 2);
441 438
 				}
442 439
 
443
-				$formatted = $result . $decimal_amount;
440
+				$formatted = $result.$decimal_amount;
444 441
 				break;
445 442
 
446 443
 			default:
447
-				$formatted = number_format( $amount, $decimals, $decimal_sep, $thousands_sep );
444
+				$formatted = number_format($amount, $decimals, $decimal_sep, $thousands_sep);
448 445
 		}
449 446
 	}
450 447
 
@@ -453,7 +450,7 @@  discard block
 block discarded – undo
453 450
 	 *
454 451
 	 * @since 1.0
455 452
 	 */
456
-	return apply_filters( 'give_format_amount', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $currency, $args );
453
+	return apply_filters('give_format_amount', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $currency, $args);
457 454
 }
458 455
 
459 456
 
@@ -471,17 +468,17 @@  discard block
 block discarded – undo
471 468
  *
472 469
  * @return string  formatted amount number with large number names.
473 470
  */
474
-function give_human_format_large_amount( $amount, $args = array() ) {
471
+function give_human_format_large_amount($amount, $args = array()) {
475 472
 	// Sanitize amount.
476
-	$sanitize_amount = give_maybe_sanitize_amount( $amount );
473
+	$sanitize_amount = give_maybe_sanitize_amount($amount);
477 474
 
478 475
 	// Bailout.
479
-	if ( ! floatval( $sanitize_amount ) ) {
476
+	if ( ! floatval($sanitize_amount)) {
480 477
 		return '0';
481 478
 	};
482 479
 
483 480
 	// Set default currency;
484
-	if ( empty( $args['currency'] ) ) {
481
+	if (empty($args['currency'])) {
485 482
 		$args['currency'] = give_get_currency();
486 483
 	}
487 484
 
@@ -489,37 +486,37 @@  discard block
 block discarded – undo
489 486
 	$thousands_sep = give_get_price_thousand_separator();
490 487
 
491 488
 	// Explode amount to calculate name of large numbers.
492
-	$amount_array = explode( $thousands_sep, $amount );
489
+	$amount_array = explode($thousands_sep, $amount);
493 490
 
494 491
 	// Calculate amount parts count.
495
-	$amount_count_parts = count( $amount_array );
492
+	$amount_count_parts = count($amount_array);
496 493
 
497 494
 	// Human format amount (default).
498 495
 	$human_format_amount = $amount;
499 496
 
500
-	switch ( $args['currency'] ) {
497
+	switch ($args['currency']) {
501 498
 		case 'INR':
502 499
 			// Calculate large number formatted amount.
503
-			if ( 4 < $amount_count_parts ) {
504
-				$human_format_amount = sprintf( esc_html__( '%s arab', 'give' ), round( ( $sanitize_amount / 1000000000 ), 2 ) );
505
-			} elseif ( 3 < $amount_count_parts ) {
506
-				$human_format_amount = sprintf( esc_html__( '%s crore', 'give' ), round( ( $sanitize_amount / 10000000 ), 2 ) );
507
-			} elseif ( 2 < $amount_count_parts ) {
508
-				$human_format_amount = sprintf( esc_html__( '%s lakh', 'give' ), round( ( $sanitize_amount / 100000 ), 2 ) );
500
+			if (4 < $amount_count_parts) {
501
+				$human_format_amount = sprintf(esc_html__('%s arab', 'give'), round(($sanitize_amount / 1000000000), 2));
502
+			} elseif (3 < $amount_count_parts) {
503
+				$human_format_amount = sprintf(esc_html__('%s crore', 'give'), round(($sanitize_amount / 10000000), 2));
504
+			} elseif (2 < $amount_count_parts) {
505
+				$human_format_amount = sprintf(esc_html__('%s lakh', 'give'), round(($sanitize_amount / 100000), 2));
509 506
 			}
510 507
 			break;
511 508
 		default:
512 509
 			// Calculate large number formatted amount.
513
-			if ( 4 < $amount_count_parts ) {
514
-				$human_format_amount = sprintf( esc_html__( '%s trillion', 'give' ), round( ( $sanitize_amount / 1000000000000 ), 2 ) );
515
-			} elseif ( 3 < $amount_count_parts ) {
516
-				$human_format_amount = sprintf( esc_html__( '%s billion', 'give' ), round( ( $sanitize_amount / 1000000000 ), 2 ) );
517
-			} elseif ( 2 < $amount_count_parts ) {
518
-				$human_format_amount = sprintf( esc_html__( '%s million', 'give' ), round( ( $sanitize_amount / 1000000 ), 2 ) );
510
+			if (4 < $amount_count_parts) {
511
+				$human_format_amount = sprintf(esc_html__('%s trillion', 'give'), round(($sanitize_amount / 1000000000000), 2));
512
+			} elseif (3 < $amount_count_parts) {
513
+				$human_format_amount = sprintf(esc_html__('%s billion', 'give'), round(($sanitize_amount / 1000000000), 2));
514
+			} elseif (2 < $amount_count_parts) {
515
+				$human_format_amount = sprintf(esc_html__('%s million', 'give'), round(($sanitize_amount / 1000000), 2));
519 516
 			}
520 517
 	}
521 518
 
522
-	return apply_filters( 'give_human_format_large_amount', $human_format_amount, $amount, $sanitize_amount );
519
+	return apply_filters('give_human_format_large_amount', $human_format_amount, $amount, $sanitize_amount);
523 520
 }
524 521
 
525 522
 /**
@@ -533,17 +530,16 @@  discard block
 block discarded – undo
533 530
  *
534 531
  * @return string $amount Newly formatted amount or Price Not Available
535 532
  */
536
-function give_format_decimal( $amount, $dp = false, $sanitize = true ) {
533
+function give_format_decimal($amount, $dp = false, $sanitize = true) {
537 534
 	$decimal_separator = give_get_price_decimal_separator();
538 535
 	$formatted_amount  = $sanitize ?
539
-		give_maybe_sanitize_amount( $amount, array( 'number_decimals' => $dp ) ) :
540
-		number_format( $amount, ( is_bool( $dp ) ? give_get_price_decimals() : $dp ), '.', '' );
536
+		give_maybe_sanitize_amount($amount, array('number_decimals' => $dp)) : number_format($amount, (is_bool($dp) ? give_get_price_decimals() : $dp), '.', '');
541 537
 
542
-	if ( false !== strpos( $formatted_amount, '.' ) ) {
543
-		$formatted_amount = str_replace( '.', $decimal_separator, $formatted_amount );
538
+	if (false !== strpos($formatted_amount, '.')) {
539
+		$formatted_amount = str_replace('.', $decimal_separator, $formatted_amount);
544 540
 	}
545 541
 
546
-	return apply_filters( 'give_format_decimal', $formatted_amount, $amount, $decimal_separator );
542
+	return apply_filters('give_format_decimal', $formatted_amount, $amount, $decimal_separator);
547 543
 }
548 544
 
549 545
 /**
@@ -555,7 +551,7 @@  discard block
 block discarded – undo
555 551
  *
556 552
  * @return string                  Date format string
557 553
  */
558
-function give_date_format( $date_context = '' ) {
554
+function give_date_format($date_context = '') {
559 555
 	/**
560 556
 	 * Filter the date context
561 557
 	 *
@@ -576,19 +572,19 @@  discard block
 block discarded – undo
576 572
 	 *
577 573
 	 *    }
578 574
 	 */
579
-	$date_format_contexts = apply_filters( 'give_date_format_contexts', array() );
575
+	$date_format_contexts = apply_filters('give_date_format_contexts', array());
580 576
 
581 577
 	// Set date format to default date format.
582
-	$date_format = get_option( 'date_format' );
578
+	$date_format = get_option('date_format');
583 579
 
584 580
 	// Update date format if we have non empty date format context array and non empty date format string for that context.
585
-	if ( $date_context && ! empty( $date_format_contexts ) && array_key_exists( $date_context, $date_format_contexts ) ) {
586
-		$date_format = ! empty( $date_format_contexts[ $date_context ] )
587
-			? $date_format_contexts[ $date_context ]
581
+	if ($date_context && ! empty($date_format_contexts) && array_key_exists($date_context, $date_format_contexts)) {
582
+		$date_format = ! empty($date_format_contexts[$date_context])
583
+			? $date_format_contexts[$date_context]
588 584
 			: $date_format;
589 585
 	}
590 586
 
591
-	return apply_filters( 'give_date_format', $date_format );
587
+	return apply_filters('give_date_format', $date_format);
592 588
 }
593 589
 
594 590
 /**
@@ -602,8 +598,8 @@  discard block
 block discarded – undo
602 598
  *
603 599
  * @return string
604 600
  */
605
-function give_get_cache_key( $action, $query_args ) {
606
-	return Give_Cache::get_key( $action, $query_args );
601
+function give_get_cache_key($action, $query_args) {
602
+	return Give_Cache::get_key($action, $query_args);
607 603
 }
608 604
 
609 605
 /**
@@ -616,11 +612,11 @@  discard block
 block discarded – undo
616 612
  *
617 613
  * @return string|array
618 614
  */
619
-function give_clean( $var ) {
620
-	if ( is_array( $var ) ) {
621
-		return array_map( 'give_clean', $var );
615
+function give_clean($var) {
616
+	if (is_array($var)) {
617
+		return array_map('give_clean', $var);
622 618
 	} else {
623
-		return is_scalar( $var ) ? sanitize_text_field( wp_unslash( $var ) ) : $var;
619
+		return is_scalar($var) ? sanitize_text_field(wp_unslash($var)) : $var;
624 620
 	}
625 621
 }
626 622
 
@@ -633,10 +629,10 @@  discard block
 block discarded – undo
633 629
  *
634 630
  * @return int
635 631
  */
636
-function give_let_to_num( $size ) {
637
-	$l   = substr( $size, - 1 );
638
-	$ret = substr( $size, 0, - 1 );
639
-	switch ( strtoupper( $l ) ) {
632
+function give_let_to_num($size) {
633
+	$l   = substr($size, - 1);
634
+	$ret = substr($size, 0, - 1);
635
+	switch (strtoupper($l)) {
640 636
 		case 'P':
641 637
 			$ret *= 1024;
642 638
 		case 'T':
@@ -663,22 +659,22 @@  discard block
 block discarded – undo
663 659
  *
664 660
  * @return bool
665 661
  */
666
-function give_validate_nonce( $nonce, $action = - 1, $wp_die_args = array() ) {
662
+function give_validate_nonce($nonce, $action = - 1, $wp_die_args = array()) {
667 663
 
668 664
 	// Verify nonce.
669
-	$verify_nonce = wp_verify_nonce( $nonce, $action );
665
+	$verify_nonce = wp_verify_nonce($nonce, $action);
670 666
 
671 667
 	// On ajax request send nonce verification status.
672
-	if ( wp_doing_ajax() ) {
668
+	if (wp_doing_ajax()) {
673 669
 		return $verify_nonce;
674 670
 	}
675 671
 
676
-	if ( ! $verify_nonce ) {
672
+	if ( ! $verify_nonce) {
677 673
 		$wp_die_args = wp_parse_args(
678 674
 			$wp_die_args,
679 675
 			array(
680
-				'message' => __( 'Nonce verification has failed.', 'give' ),
681
-				'title'   => __( 'Error', 'give' ),
676
+				'message' => __('Nonce verification has failed.', 'give'),
677
+				'title'   => __('Error', 'give'),
682 678
 				'args'    => array(
683 679
 					'response' => 403,
684 680
 				),
@@ -705,16 +701,16 @@  discard block
 block discarded – undo
705 701
  *
706 702
  * @return bool
707 703
  */
708
-function give_verify_donation_form_nonce( $nonce = '', $form_id ) {
704
+function give_verify_donation_form_nonce($nonce = '', $form_id) {
709 705
 
710 706
 	// Form nonce action.
711 707
 	$nonce_action = "give_donation_form_nonce_{$form_id}";
712 708
 
713 709
 	// Nonce validation.
714
-	$verify_nonce = give_validate_nonce( $nonce, $nonce_action );
710
+	$verify_nonce = give_validate_nonce($nonce, $nonce_action);
715 711
 
716
-	if ( ! $verify_nonce ) {
717
-		give_set_error( 'donation_form_nonce', __( 'Nonce verification has failed.', 'give' ) );
712
+	if ( ! $verify_nonce) {
713
+		give_set_error('donation_form_nonce', __('Nonce verification has failed.', 'give'));
718 714
 	}
719 715
 
720 716
 	return $verify_nonce;
@@ -734,43 +730,43 @@  discard block
 block discarded – undo
734 730
  *
735 731
  * @return mixed
736 732
  */
737
-function give_check_variable( $variable, $conditional = '', $default = false, $array_key_name = '' ) {
733
+function give_check_variable($variable, $conditional = '', $default = false, $array_key_name = '') {
738 734
 	// Get value from array if array key non empty.
739
-	if( empty( $array_key_name ) ) {
740
-		switch ( $conditional ) {
735
+	if (empty($array_key_name)) {
736
+		switch ($conditional) {
741 737
 			case 'isset_empty':
742
-				$variable = ( isset( $variable ) && ! empty( $variable ) ) ? $variable : $default;
738
+				$variable = (isset($variable) && ! empty($variable)) ? $variable : $default;
743 739
 				break;
744 740
 
745 741
 			case 'empty':
746
-				$variable = ! empty( $variable ) ? $variable : $default;
742
+				$variable = ! empty($variable) ? $variable : $default;
747 743
 				break;
748 744
 
749 745
 			case 'null':
750
-				$variable = ! is_null( $variable ) ? $variable : $default;
746
+				$variable = ! is_null($variable) ? $variable : $default;
751 747
 				break;
752 748
 
753 749
 			default:
754
-				$variable = isset( $variable ) ? $variable : $default;
750
+				$variable = isset($variable) ? $variable : $default;
755 751
 		}
756 752
 	} else {
757
-		$isset = array_key_exists( $array_key_name, $variable );
753
+		$isset = array_key_exists($array_key_name, $variable);
758 754
 
759
-		switch ( $conditional ) {
755
+		switch ($conditional) {
760 756
 			case 'isset_empty':
761
-				$variable = ( $isset && ! empty( $variable[ $array_key_name ] ) ) ? $variable[ $array_key_name ] : $default;
757
+				$variable = ($isset && ! empty($variable[$array_key_name])) ? $variable[$array_key_name] : $default;
762 758
 				break;
763 759
 
764 760
 			case 'empty':
765
-				$variable = ! empty( $variable[ $array_key_name ] ) ? $variable[ $array_key_name ] : $default;
761
+				$variable = ! empty($variable[$array_key_name]) ? $variable[$array_key_name] : $default;
766 762
 				break;
767 763
 
768 764
 			case 'null':
769
-				$variable = $isset && ! is_null( $variable[ $array_key_name ] ) ? $variable[ $array_key_name ] : $default;
765
+				$variable = $isset && ! is_null($variable[$array_key_name]) ? $variable[$array_key_name] : $default;
770 766
 				break;
771 767
 
772 768
 			default:
773
-				$variable = $isset && isset( $variable[ $array_key_name ] ) ? $variable[ $array_key_name ] : $default;
769
+				$variable = $isset && isset($variable[$array_key_name]) ? $variable[$array_key_name] : $default;
774 770
 		}
775 771
 	}
776 772
 
Please login to merge, or discard this patch.