PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.3.6
Pods – Custom Content Types and Fields v3.3.6
trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / ui / fields / currency.php
pods / ui / fields Last commit date
_comment.php 4 months ago _db.php 4 months ago _hidden.php 4 months ago _label.php 4 months ago _row.php 4 months ago attachment.php 4 months ago checkbox.php 4 months ago cleditor.php 4 months ago codemirror.php 4 months ago color.php 4 months ago currency.php 4 months ago date.php 4 months ago datetime.php 4 months ago email.php 4 months ago link.php 4 months ago number.php 4 months ago oembed.php 4 months ago password.php 4 months ago phone.php 4 months ago radio.php 4 months ago select.php 4 months ago slider.php 4 months ago slug.php 4 months ago text.php 4 months ago textarea.php 4 months ago time.php 4 months ago tinymce.php 4 months ago website.php 4 months ago
currency.php
90 lines
1 <?php
2
3 // Don't load directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 die( '-1' );
6 }
7
8 // phpcs:ignoreFile WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
9
10 $field_number = PodsForm::field_loader( 'currency' );
11
12 $value = $field_number->format( $value, $name, $options, $pod, $id );
13
14 $attributes = array();
15 $attributes['type'] = 'text';
16 $attributes['value'] = $value;
17 $attributes['tabindex'] = 2;
18 $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options );
19
20 global $wp_locale;
21
22 if ( '9999.99' === pods_v( 'currency_format', $options ) ) {
23 $thousands = '';
24 $dot = '.';
25 } elseif ( '9999,99' === pods_v( 'currency_format', $options ) ) {
26 $thousands = '';
27 $dot = ',';
28 } elseif ( '9.999,99' === pods_v( 'currency_format', $options ) ) {
29 $thousands = '.';
30 $dot = ',';
31 } else {
32 $thousands = $wp_locale->number_format['thousands_sep'];
33 $dot = $wp_locale->number_format['decimal_point'];
34 }
35
36 $currency = 'usd';
37
38 $currency_format_sign = pods_v( 'currency_format_sign', $options, $currency );
39
40 $currencies = PodsField_Currency::data_currencies();
41
42 if ( isset( $currencies[ $currency_format_sign ] ) ) {
43 $currency = $currency_format_sign;
44 }
45
46 $currency_sign = $currencies[ $currency ]['sign'];
47 ?>
48 <div class="pods-currency-container">
49 <code class="pods-currency-sign pods-hidden"><?php echo wp_kses_post( $currency_sign ); ?></code>
50 <input<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?>/>
51 </div>
52 <script>
53 jQuery( function ( $ ) {
54 var input = $( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ),
55 currency_sign = input.siblings( 'code.pods-currency-sign' );
56
57 input.on( 'blur', function () {
58 if ( !/^[0-9\<?php
59 echo esc_js( implode( '\\', array_filter( array( $dot, $thousands ) ) ) );
60 ?>]$/.test( $( this ).val() ) ) {
61 var newval = $( this )
62 .val()
63 .replace( /[^0-9-\<?php
64 echo esc_js( implode( '\\', array_filter( array( $dot, $thousands ) ) ) );
65 ?>]/g, '' );
66 $( this ).val( newval );
67 }
68 } );
69
70 if ( currency_sign.length ) {
71 currency_sign.removeClass( 'pods-hidden' );
72
73 function resize_currency_sign() {
74 if ( currency_sign.width() < 1 ) {
75 return;
76 }
77
78 input.css( 'padding-left', currency_sign.width() + 12 );
79 currency_sign.css( 'line-height', parseInt( input.innerHeight(), 10 ) + 'px' );
80 }
81
82 // Cover most events we need.
83 $(window).on( 'resize load visibilitychange postbox-toggled postbox-columnchange postboxes-columnchange', resize_currency_sign );
84
85 // Gutenberg show/hide panels do not trigger any known events, this is one final hackaround for that.
86 input.on( 'hover focus', resize_currency_sign );
87 }
88 } );
89 </script>
90