PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.5.2
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.5.2
3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / fields / payment-amount-helpers.php
everest-forms / includes / fields Last commit date
class-evf-field-address.php 1 year ago class-evf-field-ai.php 1 year ago class-evf-field-captcha.php 3 weeks ago class-evf-field-checkbox.php 2 months ago class-evf-field-color.php 3 weeks ago class-evf-field-country.php 2 months ago class-evf-field-credit-card.php 3 weeks ago class-evf-field-date-time.php 3 weeks ago class-evf-field-divider.php 2 years ago class-evf-field-email.php 1 year ago class-evf-field-file-upload.php 1 year ago class-evf-field-first-name.php 1 year ago class-evf-field-hcaptcha.php 4 months ago class-evf-field-hidden.php 1 year ago class-evf-field-html.php 9 months ago class-evf-field-image-upload.php 1 year ago class-evf-field-last-name.php 1 year ago class-evf-field-likert.php 1 year ago class-evf-field-lookup.php 3 weeks ago class-evf-field-number.php 1 year ago class-evf-field-password.php 3 weeks ago class-evf-field-payment-authorize-net.php 3 weeks ago class-evf-field-payment-checkbox.php 3 weeks ago class-evf-field-payment-coupon.php 3 weeks ago class-evf-field-payment-gateway-selector.php 3 weeks ago class-evf-field-payment-quantity.php 3 weeks ago class-evf-field-payment-radio.php 3 weeks ago class-evf-field-payment-single.php 3 weeks ago class-evf-field-payment-square.php 1 year ago class-evf-field-payment-subscription-plan.php 3 weeks ago class-evf-field-payment-subtotal.php 3 weeks ago class-evf-field-payment-total.php 3 weeks ago class-evf-field-phone.php 1 year ago class-evf-field-privacy-policy.php 2 months ago class-evf-field-private-note.php 1 year ago class-evf-field-progress.php 3 weeks ago class-evf-field-radio.php 2 months ago class-evf-field-range-slider.php 3 weeks ago class-evf-field-rating.php 2 months ago class-evf-field-recaptcha.php 4 months ago class-evf-field-repeater.php 3 weeks ago class-evf-field-reset.php 3 weeks ago class-evf-field-scale-rating.php 1 year ago class-evf-field-select.php 1 year ago class-evf-field-signature.php 3 weeks ago class-evf-field-text.php 1 year ago class-evf-field-textarea.php 1 year ago class-evf-field-title.php 2 years ago class-evf-field-turnstile.php 4 months ago class-evf-field-url.php 1 year ago class-evf-field-wysiwyg.php 2 months ago class-evf-field-yes-no.php 1 year ago payment-amount-helpers.php 3 weeks ago
payment-amount-helpers.php
148 lines
1 <?php
2 /**
3 * Builder-scope payment amount helpers.
4 *
5 * Currency-aware fallbacks for evf_sanitize_amount() / evf_format_amount() so the
6 * free plugin can render LOCKED payment fields' previews IDENTICALLY to Everest
7 * Forms Pro (e.g. "$ 0.00"). The real helpers ship in Pro
8 * (includes/payments/functions.php, unguarded); these are only ever loaded from
9 * a free payment-field class file, which is itself only autoloaded when the Pro
10 * class is absent — so there is never a redeclaration conflict.
11 *
12 * Logic mirrors Pro's evf_format_amount()/evf_sanitize_amount() and reads the
13 * same `everest_forms_currency` option, so the rendered amount matches Pro.
14 *
15 * @package EverestForms\Fields
16 */
17
18 defined( 'ABSPATH' ) || exit;
19
20 if ( ! function_exists( 'evf_get_currencies' ) ) {
21 /**
22 * Currency definitions (subset mirroring Everest Forms Pro values). Falls back
23 * to USD for any currency not listed.
24 *
25 * @return array
26 */
27 function evf_get_currencies() {
28 return array(
29 'USD' => array( 'symbol' => '&#36;', 'symbol_pos' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'decimals' => 2 ),
30 'GBP' => array( 'symbol' => '&pound;', 'symbol_pos' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'decimals' => 2 ),
31 'EUR' => array( 'symbol' => '&euro;', 'symbol_pos' => 'right', 'thousands_separator' => '.', 'decimal_separator' => ',', 'decimals' => 2 ),
32 'AUD' => array( 'symbol' => '&#36;', 'symbol_pos' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'decimals' => 2 ),
33 'BRL' => array( 'symbol' => 'R$', 'symbol_pos' => 'left', 'thousands_separator' => '.', 'decimal_separator' => ',', 'decimals' => 2 ),
34 'CAD' => array( 'symbol' => '&#36;', 'symbol_pos' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'decimals' => 2 ),
35 'CHF' => array( 'symbol' => 'CHF', 'symbol_pos' => 'left', 'thousands_separator' => "'", 'decimal_separator' => '.', 'decimals' => 2 ),
36 'CZK' => array( 'symbol' => '&#75;&#269;', 'symbol_pos' => 'right', 'thousands_separator' => '.', 'decimal_separator' => ',', 'decimals' => 2 ),
37 'DKK' => array( 'symbol' => 'kr.', 'symbol_pos' => 'left', 'thousands_separator' => '.', 'decimal_separator' => ',', 'decimals' => 2 ),
38 'HKD' => array( 'symbol' => '&#36;', 'symbol_pos' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'decimals' => 2 ),
39 'HUF' => array( 'symbol' => '&#70;&#116;', 'symbol_pos' => 'right', 'thousands_separator' => '.', 'decimal_separator' => ',', 'decimals' => 2 ),
40 'ILS' => array( 'symbol' => '&#8362;', 'symbol_pos' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'decimals' => 2 ),
41 'INR' => array( 'symbol' => '&#8377;', 'symbol_pos' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'decimals' => 2 ),
42 'JPY' => array( 'symbol' => '&yen;', 'symbol_pos' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'decimals' => 0 ),
43 'MXN' => array( 'symbol' => '&#36;', 'symbol_pos' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'decimals' => 2 ),
44 'MYR' => array( 'symbol' => '&#82;&#77;', 'symbol_pos' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'decimals' => 2 ),
45 'NOK' => array( 'symbol' => 'kr', 'symbol_pos' => 'left', 'thousands_separator' => '.', 'decimal_separator' => ',', 'decimals' => 2 ),
46 'NZD' => array( 'symbol' => '&#36;', 'symbol_pos' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'decimals' => 2 ),
47 'PHP' => array( 'symbol' => '&#8369;', 'symbol_pos' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'decimals' => 2 ),
48 'PLN' => array( 'symbol' => '&#122;&#322;', 'symbol_pos' => 'right', 'thousands_separator' => '.', 'decimal_separator' => ',', 'decimals' => 2 ),
49 'SEK' => array( 'symbol' => 'kr', 'symbol_pos' => 'left', 'thousands_separator' => '.', 'decimal_separator' => ',', 'decimals' => 2 ),
50 'SGD' => array( 'symbol' => '&#36;', 'symbol_pos' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'decimals' => 2 ),
51 'THB' => array( 'symbol' => '&#3647;', 'symbol_pos' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'decimals' => 2 ),
52 'ZAR' => array( 'symbol' => '&#82;', 'symbol_pos' => 'left', 'thousands_separator' => ',', 'decimal_separator' => '.', 'decimals' => 2 ),
53 );
54 }
55 }
56
57 if ( ! function_exists( 'evf_sanitize_amount' ) ) {
58 /**
59 * Sanitize a price amount (builder-scope mirror of the Pro helper).
60 *
61 * @param string $amount Amount value.
62 * @param string $currency Currency code.
63 * @return string
64 */
65 function evf_sanitize_amount( $amount, $currency = '' ) {
66 if ( empty( $currency ) ) {
67 $currency = get_option( 'everest_forms_currency', 'USD' );
68 }
69
70 $currency = strtoupper( $currency );
71 $currencies = evf_get_currencies();
72 $thousands_sep = isset( $currencies[ $currency ]['thousands_separator'] ) ? $currencies[ $currency ]['thousands_separator'] : ',';
73 $decimal_sep = isset( $currencies[ $currency ]['decimal_separator'] ) ? $currencies[ $currency ]['decimal_separator'] : '.';
74
75 if ( is_string( $amount ) ) {
76 if ( ',' === $decimal_sep && false !== strpos( $amount, $decimal_sep ) ) {
77 if ( ( '.' === $thousands_sep || ' ' === $thousands_sep ) && false !== strpos( $amount, $thousands_sep ) ) {
78 $amount = str_replace( $thousands_sep, '', $amount );
79 } elseif ( empty( $thousands_sep ) && false !== strpos( $amount, '.' ) ) {
80 $amount = str_replace( '.', '', $amount );
81 }
82 $amount = str_replace( $decimal_sep, '.', $amount );
83 } elseif ( ',' === $thousands_sep && false !== strpos( $amount, $thousands_sep ) ) {
84 $amount = str_replace( $thousands_sep, '', $amount );
85 }
86 }
87
88 $amount = preg_replace( '/[^0-9\.]/', '', (string) $amount );
89 $decimals = apply_filters( 'evf_sanitize_amount_decimals', 2, $amount );
90
91 return number_format( (float) $amount, $decimals, '.', '' );
92 }
93 }
94
95 if ( ! function_exists( 'evf_format_amount' ) ) {
96 /**
97 * Format a price amount (builder-scope mirror of the Pro helper).
98 *
99 * @param string $amount Amount.
100 * @param boolean $symbol Whether to prepend/append the currency symbol.
101 * @param string $currency Currency code.
102 * @return string
103 */
104 function evf_format_amount( $amount, $symbol = false, $currency = '' ) {
105 if ( empty( $currency ) ) {
106 $currency = get_option( 'everest_forms_currency', 'USD' );
107 }
108
109 $currency = strtoupper( $currency );
110 $currencies = evf_get_currencies();
111 $thousands_sep = isset( $currencies[ $currency ]['thousands_separator'] ) ? $currencies[ $currency ]['thousands_separator'] : ',';
112 $decimal_sep = isset( $currencies[ $currency ]['decimal_separator'] ) ? $currencies[ $currency ]['decimal_separator'] : '.';
113 $sep_found = ! empty( $decimal_sep ) ? strpos( $amount, $decimal_sep ) : false;
114
115 if ( ',' === $decimal_sep && false !== $sep_found ) {
116 $whole = substr( $amount, 0, $sep_found );
117 $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
118 $amount = $whole . '.' . $part;
119 }
120
121 if ( ',' === $thousands_sep && false !== strpos( (string) $amount, $thousands_sep ) ) {
122 $amount = (float) floatval( str_replace( ',', '', $amount ) );
123 }
124
125 if ( empty( $amount ) ) {
126 $amount = 0;
127 }
128
129 $decimals = apply_filters( 'evf_sanitize_amount_decimals', 2, $amount );
130 $number = number_format( (float) $amount, $decimals, $decimal_sep, $thousands_sep );
131
132 if ( $symbol && isset( $currencies[ $currency ]['symbol'], $currencies[ $currency ]['symbol_pos'] ) ) {
133 $symbol_padding = apply_filters( 'evf_currency_symbol_padding', ' ' );
134 if ( 'right' === $currencies[ $currency ]['symbol_pos'] ) {
135 $number .= $symbol_padding . $currencies[ $currency ]['symbol'];
136 } else {
137 $number = $currencies[ $currency ]['symbol'] . $symbol_padding . $number;
138 }
139 }
140
141 if ( 'EUR' === $currency ) {
142 $number = str_replace( '.', '', $number );
143 }
144
145 return $number;
146 }
147 }
148