| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'ABSPATH' ) || die(); |
| 4 |
|
| 5 |
class Sellkit_Elementor_Optin_Field_Tel extends Sellkit_Elementor_Optin_Field_Text { |
| 6 |
|
| 7 |
public static function get_field_type() { |
| 8 |
return 'tel'; |
| 9 |
} |
| 10 |
|
| 11 |
public function get_input_type() { |
| 12 |
return 'tel'; |
| 13 |
} |
| 14 |
|
| 15 |
public function add_field_render_attribute() { |
| 16 |
parent::add_field_render_attribute(); |
| 17 |
|
| 18 |
$this->widget->add_render_attribute( 'field-' . $this->get_id(), [ |
| 19 |
'title' => esc_html__( 'The value should only consist numbers and phone characters (-, +, (), etc.)', 'sellkit' ), |
| 20 |
'pattern' => '^[0-9\-\+\s\(\)]*$', |
| 21 |
] ); |
| 22 |
|
| 23 |
// Intelligent tel attributes. |
| 24 |
$iti_switcher_options = [ |
| 25 |
'iti_tel' => 'data-iti-tel', |
| 26 |
'iti_tel_ip_detect' => 'data-iti-ip-detect', |
| 27 |
'iti_tel_require_area' => 'data-iti-area-required', |
| 28 |
'iti_tel_internationalize' => 'data-iti-internationalize', |
| 29 |
'iti_tel_allow_dropdown' => 'data-iti-allow-dropdown', |
| 30 |
]; |
| 31 |
|
| 32 |
foreach ( $iti_switcher_options as $id => $attr ) { |
| 33 |
if ( isset( $this->field[ $id ] ) && 'yes' === $this->field[ $id ] ) { |
| 34 |
$this->widget->add_render_attribute( 'field-' . $this->get_id(), $attr ); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
$iti_select_options = [ |
| 39 |
'iti_tel_country_include' => 'data-iti-country-include', |
| 40 |
'iti_tel_tel_type' => 'data-iti-tel-type', |
| 41 |
]; |
| 42 |
|
| 43 |
foreach ( $iti_select_options as $id => $attr ) { |
| 44 |
if ( ! empty( $this->field[ $id ] ) || '0' === $this->field[ $id ] ) { |
| 45 |
$this->widget->add_render_attribute( 'field-' . $this->get_id(), $attr, $this->field[ $id ] ); |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
public static function get_additional_controls() { |
| 51 |
$commons = parent::get_common_controls(); |
| 52 |
|
| 53 |
$iti_enabled = [ |
| 54 |
'name' => 'iti_tel', |
| 55 |
'operator' => '===', |
| 56 |
'value' => 'yes', |
| 57 |
]; |
| 58 |
|
| 59 |
return [ |
| 60 |
'label' => $commons['label'], |
| 61 |
'field_value' => $commons['field_value'], |
| 62 |
'placeholder' => $commons['placeholder'], |
| 63 |
'required' => $commons['required'], |
| 64 |
'iti_tel' => [ |
| 65 |
'label' => esc_html__( 'Intelligent', 'sellkit' ), |
| 66 |
'type' => 'popover_toggle', |
| 67 |
'conditions' => [ |
| 68 |
'terms' => [ |
| 69 |
parent::get_type_condition(), |
| 70 |
[ |
| 71 |
'name' => 'required', |
| 72 |
'operator' => '===', |
| 73 |
'value' => 'true', |
| 74 |
], |
| 75 |
], |
| 76 |
], |
| 77 |
], |
| 78 |
'iti_tel_tel_type' => [ |
| 79 |
'label' => esc_html__( 'Type', 'sellkit' ), |
| 80 |
'type' => 'select', |
| 81 |
'default' => 'all', |
| 82 |
'options' => [ |
| 83 |
'all' => esc_html__( 'All', 'sellkit' ), |
| 84 |
'0' => esc_html__( 'Fixed Line', 'sellkit' ), |
| 85 |
'1' => esc_html__( 'Mobile', 'sellkit' ), |
| 86 |
'2' => esc_html__( 'Fixed Line or Mobile', 'sellkit' ), |
| 87 |
'3' => esc_html__( 'Toll Free', 'sellkit' ), |
| 88 |
'4' => esc_html__( 'Premium Rate', 'sellkit' ), |
| 89 |
'5' => esc_html__( 'Shared Cost', 'sellkit' ), |
| 90 |
'6' => esc_html__( 'VOIP', 'sellkit' ), |
| 91 |
'7' => esc_html__( 'Personal Number', 'sellkit' ), |
| 92 |
'8' => esc_html__( 'Pager', 'sellkit' ), |
| 93 |
'9' => esc_html__( 'UAN', 'sellkit' ), |
| 94 |
'10' => esc_html__( 'Voicemail', 'sellkit' ), |
| 95 |
], |
| 96 |
'popover' => [ 'start' => true ], |
| 97 |
'render_type' => 'template', |
| 98 |
'conditions' => [ |
| 99 |
'terms' => [ $iti_enabled ], |
| 100 |
], |
| 101 |
], |
| 102 |
'iti_tel_require_area' => [ |
| 103 |
'label' => esc_html__( 'Require Area Code', 'sellkit' ), |
| 104 |
'type' => 'switcher', |
| 105 |
'default' => 'yes', |
| 106 |
'conditions' => [ |
| 107 |
'terms' => [ $iti_enabled ], |
| 108 |
], |
| 109 |
], |
| 110 |
'iti_tel_allow_dropdown' => [ |
| 111 |
'label' => esc_html__( 'Allow Dropdown', 'sellkit' ), |
| 112 |
'type' => 'switcher', |
| 113 |
'default' => 'yes', |
| 114 |
'render_type' => 'template', |
| 115 |
'conditions' => [ |
| 116 |
'terms' => [ $iti_enabled ], |
| 117 |
], |
| 118 |
], |
| 119 |
'iti_tel_country_include' => [ |
| 120 |
'label' => esc_html__( 'Only Include Countries', 'sellkit' ), |
| 121 |
'type' => 'select2', |
| 122 |
'options' => [], |
| 123 |
'description' => esc_html__( 'Leave empty to include all countries.', 'sellkit' ), |
| 124 |
'label_block' => true, |
| 125 |
'multiple' => true, |
| 126 |
'render_type' => 'template', |
| 127 |
'conditions' => [ |
| 128 |
'terms' => [ $iti_enabled ], |
| 129 |
], |
| 130 |
], |
| 131 |
'iti_tel_ip_detect' => [ |
| 132 |
'label' => esc_html__( 'Auto Detect by IP', 'sellkit' ), |
| 133 |
'type' => 'switcher', |
| 134 |
'default' => 'yes', |
| 135 |
'render_type' => 'template', |
| 136 |
'conditions' => [ |
| 137 |
'terms' => [ |
| 138 |
$iti_enabled, |
| 139 |
[ |
| 140 |
'name' => 'iti_tel_allow_dropdown', |
| 141 |
'operator' => '===', |
| 142 |
'value' => 'yes', |
| 143 |
], |
| 144 |
], |
| 145 |
], |
| 146 |
], |
| 147 |
'iti_tel_internationalize' => [ |
| 148 |
'label' => esc_html__( 'Internationalize', 'sellkit' ), |
| 149 |
'type' => 'switcher', |
| 150 |
'popover' => [ 'end' => true ], |
| 151 |
'render_type' => 'template', |
| 152 |
'description' => esc_html__( 'Convert entered national numbers to international format on form submit.', 'sellkit' ), |
| 153 |
'conditions' => [ |
| 154 |
'terms' => [ $iti_enabled ], |
| 155 |
], |
| 156 |
], |
| 157 |
'width_responsive' => $commons['width_responsive'], |
| 158 |
]; |
| 159 |
} |
| 160 |
} |
| 161 |
|