Completed
Push — master ( 5c06e9...0975de )
by Devin
13s
created
includes/admin/forms/metabox.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 					'row_classes'  => 'give-subfield',
76 76
 					'render_row_cb' 	=> 'give_cmb_amount_field_render_row_cb',
77 77
 					'sanitization_cb'   => 'give_sanitize_price_field_value',
78
-                    'attributes'   => array(
78
+					'attributes'   => array(
79 79
 						'placeholder' => give_format_decimal( '1.00' ),
80 80
 						'value'       => give_format_decimal( $price ),
81 81
 						'class'       => 'cmb-type-text-small give-money-field',
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 							'before_field'      => give_get_option( 'currency_position' ) == 'before' ? '<span class="give-money-symbol  give-money-symbol-before">' . give_currency_symbol() . '</span>' : '',
111 111
 							'after_field'       => give_get_option( 'currency_position' ) == 'after' ? '<span class="give-money-symbol  give-money-symbol-after">' . give_currency_symbol() . '</span>' : '',
112 112
 							'sanitization_cb'   => 'give_sanitize_price_field_value',
113
-                            'attributes'        => array(
113
+							'attributes'        => array(
114 114
 								'placeholder' => give_format_decimal( '1.00' ),
115 115
 								'class'       => 'cmb-type-text-small give-money-field',
116 116
 							),
Please login to merge, or discard this patch.
includes/formatting.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  * @return mixed
24 24
  */
25 25
 function give_get_price_decimals() {
26
-    return apply_filters( 'give_sanitize_amount_decimals', give_get_option( 'number_decimals', 0 ) );
26
+	return apply_filters( 'give_sanitize_amount_decimals', give_get_option( 'number_decimals', 0 ) );
27 27
 }
28 28
 
29 29
 /**
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
  * @return mixed
35 35
  */
36 36
 function give_get_price_thousand_separator() {
37
-    return give_get_option( 'thousands_separator', ',' );
37
+	return give_get_option( 'thousands_separator', ',' );
38 38
 }
39 39
 
40 40
 /**
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
  * @return mixed
46 46
  */
47 47
 function give_get_price_decimal_separator() {
48
-    return give_get_option( 'decimal_separator', '.' );
48
+	return give_get_option( 'decimal_separator', '.' );
49 49
 }
50 50
 
51 51
 /**
@@ -64,65 +64,65 @@  discard block
 block discarded – undo
64 64
  */
65 65
 function give_sanitize_amount( $number, $dp = false, $trim_zeros = false ) {
66 66
 
67
-    // Bailout.
68
-    if( empty( $number ) ) {
69
-        return $number;
70
-    }
67
+	// Bailout.
68
+	if( empty( $number ) ) {
69
+		return $number;
70
+	}
71 71
 
72 72
 	// Remove slash from amount.
73 73
 	// If thousand or decimal separator is set to ' then in $_POST or $_GET param we will get an escaped number.
74 74
 	// To prevent notices and warning remove slash from amount/number.
75 75
 	$number = wp_unslash( $number );
76 76
 
77
-    $thousand_separator = give_get_price_thousand_separator();
77
+	$thousand_separator = give_get_price_thousand_separator();
78 78
 
79
-    $locale   = localeconv();
80
-    $decimals = array( give_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'] );
79
+	$locale   = localeconv();
80
+	$decimals = array( give_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'] );
81 81
 
82
-    // Remove locale from string
83
-    if ( ! is_float( $number ) ) {
84
-        $number = str_replace( $decimals, '.', $number );
85
-    }
82
+	// Remove locale from string
83
+	if ( ! is_float( $number ) ) {
84
+		$number = str_replace( $decimals, '.', $number );
85
+	}
86 86
 
87
-    // Remove thousand amount formatting if amount has.
88
-    // This condition use to add backward compatibility to version before 1.6, because before version 1.6 we were saving formatted amount to db.
89
-    // Do not replace thousand separator from price if it is same as decimal separator, because it will be already replace by above code.
90
-    if(  ! in_array( $thousand_separator, $decimals ) && ( false !== strpos( $number, $thousand_separator ) ) ) {
91
-        $number = str_replace( $thousand_separator, '', $number );
92
-    } elseif ( in_array( $thousand_separator, $decimals ) ) {
87
+	// Remove thousand amount formatting if amount has.
88
+	// This condition use to add backward compatibility to version before 1.6, because before version 1.6 we were saving formatted amount to db.
89
+	// Do not replace thousand separator from price if it is same as decimal separator, because it will be already replace by above code.
90
+	if(  ! in_array( $thousand_separator, $decimals ) && ( false !== strpos( $number, $thousand_separator ) ) ) {
91
+		$number = str_replace( $thousand_separator, '', $number );
92
+	} elseif ( in_array( $thousand_separator, $decimals ) ) {
93 93
 		$number = preg_replace( '/\.(?=.*\.)/', '', $number );
94 94
 	}
95 95
 
96
-    // Remove non numeric entity before decimal separator.
97
-    $number     = preg_replace( '/[^0-9\.]/', '', $number );
98
-    $default_dp = give_get_price_decimals();
96
+	// Remove non numeric entity before decimal separator.
97
+	$number     = preg_replace( '/[^0-9\.]/', '', $number );
98
+	$default_dp = give_get_price_decimals();
99 99
 
100
-    // Format number of decimals in number.
101
-    if( false !== $dp ) {
102
-        $dp     = intval(  empty( $dp ) ? $default_dp : $dp );
103
-        $dp     = apply_filters( 'give_sanitize_amount_decimals', $dp, $number );
104
-        $number = number_format( floatval( $number ), $dp, '.', '' );
105
-    }
100
+	// Format number of decimals in number.
101
+	if( false !== $dp ) {
102
+		$dp     = intval(  empty( $dp ) ? $default_dp : $dp );
103
+		$dp     = apply_filters( 'give_sanitize_amount_decimals', $dp, $number );
104
+		$number = number_format( floatval( $number ), $dp, '.', '' );
105
+	}
106 106
 
107
-    // Reset negative amount to zero.
107
+	// Reset negative amount to zero.
108 108
 	if ( 0 > $number ) {
109 109
 		$number = number_format( 0, $default_dp, '.' );
110 110
 	}
111 111
 
112
-    // If number does not have decimal then add number of decimals to it.
113
-    if(
114
-        false === strpos( $number, '.' )
115
-        || ( $default_dp > strlen( substr( $number, strpos( $number , '.' ) + 1 ) ) )
116
-    ) {
117
-        $number = number_format( $number, $default_dp, '.', '' );
118
-    }
112
+	// If number does not have decimal then add number of decimals to it.
113
+	if(
114
+		false === strpos( $number, '.' )
115
+		|| ( $default_dp > strlen( substr( $number, strpos( $number , '.' ) + 1 ) ) )
116
+	) {
117
+		$number = number_format( $number, $default_dp, '.', '' );
118
+	}
119 119
 
120
-    // Trim zeros.
121
-    if ( $trim_zeros && strstr( $number, '.' ) ) {
122
-        $number = rtrim( rtrim( $number, '0' ), '.' );
123
-    }
120
+	// Trim zeros.
121
+	if ( $trim_zeros && strstr( $number, '.' ) ) {
122
+		$number = rtrim( rtrim( $number, '0' ), '.' );
123
+	}
124 124
 
125
-    return apply_filters( 'give_sanitize_amount', $number );
125
+	return apply_filters( 'give_sanitize_amount', $number );
126 126
 }
127 127
 
128 128
 /**
@@ -168,31 +168,31 @@  discard block
 block discarded – undo
168 168
  */
169 169
 function give_human_format_large_amount( $amount ) {
170 170
 
171
-    // Get thousand separator.
172
-    $thousands_sep = give_get_price_thousand_separator();
171
+	// Get thousand separator.
172
+	$thousands_sep = give_get_price_thousand_separator();
173 173
 
174
-    // Sanitize amount.
175
-    $sanitize_amount = give_sanitize_amount( $amount );
174
+	// Sanitize amount.
175
+	$sanitize_amount = give_sanitize_amount( $amount );
176 176
 
177
-    // Explode amount to calculate name of large numbers.
177
+	// Explode amount to calculate name of large numbers.
178 178
 	$amount_array = explode( $thousands_sep, $amount );
179 179
 
180
-    // Calculate amount parts count.
181
-    $amount_count_parts = count( $amount_array );
180
+	// Calculate amount parts count.
181
+	$amount_count_parts = count( $amount_array );
182 182
 
183 183
 	// Human format amount (default).
184 184
 	$human_format_amount = $amount;
185 185
 
186
-    // Calculate large number formatted amount.
187
-    if ( 4 < $amount_count_parts ){
188
-        $human_format_amount =  sprintf( esc_html__( '%s trillion', 'give' ), round( ( $sanitize_amount / 1000000000000 ), 2 ) );
189
-    } elseif ( 3 < $amount_count_parts ){
190
-        $human_format_amount =  sprintf( esc_html__( '%s billion', 'give' ), round( ( $sanitize_amount / 1000000000 ), 2 ));
191
-    } elseif ( 2 < $amount_count_parts  ) {
192
-        $human_format_amount =  sprintf( esc_html__( '%s million', 'give' ), round( ( $sanitize_amount / 1000000), 2 ) );
193
-    }
186
+	// Calculate large number formatted amount.
187
+	if ( 4 < $amount_count_parts ){
188
+		$human_format_amount =  sprintf( esc_html__( '%s trillion', 'give' ), round( ( $sanitize_amount / 1000000000000 ), 2 ) );
189
+	} elseif ( 3 < $amount_count_parts ){
190
+		$human_format_amount =  sprintf( esc_html__( '%s billion', 'give' ), round( ( $sanitize_amount / 1000000000 ), 2 ));
191
+	} elseif ( 2 < $amount_count_parts  ) {
192
+		$human_format_amount =  sprintf( esc_html__( '%s million', 'give' ), round( ( $sanitize_amount / 1000000), 2 ) );
193
+	}
194 194
 
195
-    return apply_filters( 'give_human_format_large_amount', $human_format_amount, $amount, $sanitize_amount );
195
+	return apply_filters( 'give_human_format_large_amount', $human_format_amount, $amount, $sanitize_amount );
196 196
 }
197 197
 
198 198
 /**
@@ -206,14 +206,14 @@  discard block
 block discarded – undo
206 206
  * @return string $amount Newly formatted amount or Price Not Available
207 207
  */
208 208
 function give_format_decimal( $amount, $dp = false ){
209
-    $decimal_separator = give_get_price_decimal_separator();
210
-    $formatted_amount  = give_sanitize_amount( $amount, $dp );
209
+	$decimal_separator = give_get_price_decimal_separator();
210
+	$formatted_amount  = give_sanitize_amount( $amount, $dp );
211 211
 
212
-    if( false !== strpos( $formatted_amount, '.' ) ) {
213
-        $formatted_amount = str_replace( '.', $decimal_separator, $formatted_amount );
214
-    }
212
+	if( false !== strpos( $formatted_amount, '.' ) ) {
213
+		$formatted_amount = str_replace( '.', $decimal_separator, $formatted_amount );
214
+	}
215 215
 
216
-    return apply_filters( 'give_format_decimal', $formatted_amount, $amount, $decimal_separator );
216
+	return apply_filters( 'give_format_decimal', $formatted_amount, $amount, $decimal_separator );
217 217
 }
218 218
 
219 219
 
@@ -257,66 +257,66 @@  discard block
 block discarded – undo
257 257
 	$negative = $price < 0;
258 258
 
259 259
 	if ( $negative ) {
260
-        // Remove proceeding "-".
260
+		// Remove proceeding "-".
261 261
 		$price = substr( $price, 1 );
262 262
 	}
263 263
 
264 264
 	$symbol = give_currency_symbol( $currency );
265 265
 
266
-    switch ( $currency ):
267
-        case 'GBP' :
268
-        case 'BRL' :
269
-        case 'EUR' :
270
-        case 'USD' :
271
-        case 'AUD' :
272
-        case 'CAD' :
273
-        case 'HKD' :
274
-        case 'MXN' :
275
-        case 'NZD' :
276
-        case 'SGD' :
277
-        case 'JPY' :
278
-        case 'THB' :
279
-        case 'INR' :
280
-        case 'RIAL' :
281
-        case 'TRY' :
282
-        case 'RUB' :
283
-        case 'SEK' :
284
-        case 'PLN' :
285
-        case 'PHP' :
286
-        case 'TWD' :
287
-        case 'MYR' :
288
-        case 'CZK' :
289
-        case 'DKK' :
290
-        case 'HUF' :
291
-        case 'ILS' :
292
-        case 'MAD' :
293
-        case 'KRW' :
294
-        case 'ZAR' :
295
-            $formatted = ( 'before' === $position ? $symbol . $price : $price . $symbol );
296
-            break;
297
-        case 'NOK' :
298
-            $formatted = ( 'before' === $position ? $symbol . ' ' . $price : $price . ' ' . $symbol );
299
-            break;
300
-        default :
301
-            $formatted = ( 'before' === $position ? $currency . ' ' . $price : $price . ' ' . $currency );
302
-            break;
303
-    endswitch;
304
-
305
-    /**
306
-     * Filter formatted amount with currency
307
-     *
308
-     * Filter name depends upon current value of currency and currency position.
309
-     * For example :
310
-     *           if currency is USD and currency position is before then
311
-     *           filter name will be give_usd_currency_filter_before
312
-     *
313
-     *           and if currency is USD and currency position is after then
314
-     *           filter name will be give_usd_currency_filter_after
315
-     *
316
-     */
317
-    $formatted = apply_filters( 'give_' . strtolower( $currency ) . "_currency_filter_{$position}", $formatted, $currency, $price );
318
-
319
-    if ( $negative ) {
266
+	switch ( $currency ):
267
+		case 'GBP' :
268
+		case 'BRL' :
269
+		case 'EUR' :
270
+		case 'USD' :
271
+		case 'AUD' :
272
+		case 'CAD' :
273
+		case 'HKD' :
274
+		case 'MXN' :
275
+		case 'NZD' :
276
+		case 'SGD' :
277
+		case 'JPY' :
278
+		case 'THB' :
279
+		case 'INR' :
280
+		case 'RIAL' :
281
+		case 'TRY' :
282
+		case 'RUB' :
283
+		case 'SEK' :
284
+		case 'PLN' :
285
+		case 'PHP' :
286
+		case 'TWD' :
287
+		case 'MYR' :
288
+		case 'CZK' :
289
+		case 'DKK' :
290
+		case 'HUF' :
291
+		case 'ILS' :
292
+		case 'MAD' :
293
+		case 'KRW' :
294
+		case 'ZAR' :
295
+			$formatted = ( 'before' === $position ? $symbol . $price : $price . $symbol );
296
+			break;
297
+		case 'NOK' :
298
+			$formatted = ( 'before' === $position ? $symbol . ' ' . $price : $price . ' ' . $symbol );
299
+			break;
300
+		default :
301
+			$formatted = ( 'before' === $position ? $currency . ' ' . $price : $price . ' ' . $currency );
302
+			break;
303
+	endswitch;
304
+
305
+	/**
306
+	 * Filter formatted amount with currency
307
+	 *
308
+	 * Filter name depends upon current value of currency and currency position.
309
+	 * For example :
310
+	 *           if currency is USD and currency position is before then
311
+	 *           filter name will be give_usd_currency_filter_before
312
+	 *
313
+	 *           and if currency is USD and currency position is after then
314
+	 *           filter name will be give_usd_currency_filter_after
315
+	 *
316
+	 */
317
+	$formatted = apply_filters( 'give_' . strtolower( $currency ) . "_currency_filter_{$position}", $formatted, $currency, $price );
318
+
319
+	if ( $negative ) {
320 320
 		// Prepend the minus sign before the currency sign.
321 321
 		$formatted = '-' . $formatted;
322 322
 	}
@@ -334,18 +334,18 @@  discard block
 block discarded – undo
334 334
  */
335 335
 function give_currency_decimal_filter() {
336 336
 
337
-    remove_filter( 'give_sanitize_amount_decimals', 'give_currency_decimal_filter' );
337
+	remove_filter( 'give_sanitize_amount_decimals', 'give_currency_decimal_filter' );
338 338
 
339
-    // Set default number of decimals.
340
-    $decimals = give_get_price_decimals();
339
+	// Set default number of decimals.
340
+	$decimals = give_get_price_decimals();
341 341
 
342
-    add_filter( 'give_sanitize_amount_decimals', 'give_currency_decimal_filter' );
342
+	add_filter( 'give_sanitize_amount_decimals', 'give_currency_decimal_filter' );
343 343
 
344 344
 
345
-    // Get number of decimals with backward compatibility ( version < 1.6 )
346
-    if( 1 <= func_num_args() ){
347
-        $decimals = ( false === func_get_arg( 0 ) ? $decimals : absint( func_get_arg( 0 ) ) );
348
-    }
345
+	// Get number of decimals with backward compatibility ( version < 1.6 )
346
+	if( 1 <= func_num_args() ){
347
+		$decimals = ( false === func_get_arg( 0 ) ? $decimals : absint( func_get_arg( 0 ) ) );
348
+	}
349 349
 
350 350
 	$currency = give_get_currency();
351 351
 
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
  * @return mixed
378 378
  */
379 379
 function give_sanitize_thousand_separator( $value, $field_args, $field ){
380
-    return stripslashes( $value );
380
+	return stripslashes( $value );
381 381
 }
382 382
 
383 383
 
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
  * @return mixed
409 409
  */
410 410
 function give_sanitize_price_field_value( $value, $field_args, $field ){
411
-    return give_sanitize_amount( $value );
411
+	return give_sanitize_amount( $value );
412 412
 }
413 413
 
414 414
 
Please login to merge, or discard this patch.