JFIF $ d d 7 * Z qn )ZP 0 !1 A "#a$2Qr D8 a Ri [f \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H ~ , l s / 9 ć: [=/#f ; ) x { ٛE Q )~ = 𘙲r*2~ a _V = ' ku m F D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq 1dđ #̩ ͑ 0 ; H ] u 搂 @:~ ו K L N s h } O I R* 8 :2 ! lD JV o ( 3 = M ( z Ȱ+i *N A r6K n S l ) ! J J Ӂ* % ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c P A\IL Nj! J ۱+ O\ ͔ ] ޒ S J ȧ c%A N ol ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0 'G=i 2N +0 e 2 ]] 9 VT P O 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P < 0 x < !1AQ "Raq 02Br #S CTb ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV YT D I 6 2 '8Y2 7'\T P.6 d &˦ @V q i |8 -O Ε ] ʔ U= T L 8= ;6c | !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U#6w + +s &r+n ڐ { @ 29gL u " T Ù M=6 (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 ! OS r D 5 7 % | ?x> L | / nD 6?/8 w # [ ) L 7 +6〼T A T g ! %5 Mm Z /c -{1_Je "| ^$ 'O & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@ u6 BԒ i YN * f 0 _ GhKW u lT <nj- 0{ M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q $ H8o Q˼EV ~ k 0 h' L Pp M -M" m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @~p # !1QAa q ? AL0L x LU 4 d ; x " 16ad0 7.\ߋ 0 = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X &Q З non]я u ג./ ; gZ$ M QР 2M ]h ni 0 P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _ 1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3 6 #Ik+ v { v i ( ވ ? a e) X xy/*@Q Ǽ Ծ ) $ IWO l c G; !i k{ gOŀ L ('x T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ) X 5 c QɎMy W ? Q *!R > 6=7)Xj 5`J ] e 8%t ! + ' ! 1Q 5 !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $ v , ,m 㵜5u bV =sY+ @d { N ! dn O < .- B; _w J t 6;Q Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш e黅X ۢ F :)[ F G X ƹ / w _c MeD ,ʡc c . W D tA $ j@ : ) - #u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P 6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L ! ~ y5 g9T̅J kbM' +s :S +B) v @ M j e C f j E 0 Y\Qn z G 1 д~ W o{T 9?` Rm yhsy3 !HAD ] m c1 ~ 2 L S u7x T ;j$ `} 4-> L# vzŏ I L S ֭ T { r jGK C ; b pU= - ` Bs K. S F w4 M q] Z dH S 0 ) tLg
<?php
namespace WPForms\Forms\Fields\PaymentCheckbox;
use WPForms_Field;
/**
* Checkbox payment field.
*
* @since 1.8.2
*/
class Field extends WPForms_Field {
/**
* Primary class constructor.
*
* @since 1.8.2
*/
public function init() {
// Define field type information.
$this->name = esc_html__( 'Checkbox Items', 'wpforms-lite' );
$this->keywords = esc_html__( 'product, store, ecommerce, pay, payment', 'wpforms-lite' );
$this->type = 'payment-checkbox';
$this->icon = 'fa-check-square-o';
$this->order = 50;
$this->group = 'payment';
$this->defaults = [
1 => [
'label' => esc_html__( 'First Item', 'wpforms-lite' ),
'value' => '10',
'image' => '',
'icon' => '',
'icon_style' => '',
'default' => '',
],
2 => [
'label' => esc_html__( 'Second Item', 'wpforms-lite' ),
'value' => '25',
'image' => '',
'icon' => '',
'icon_style' => '',
'default' => '',
],
3 => [
'label' => esc_html__( 'Third Item', 'wpforms-lite' ),
'value' => '50',
'image' => '',
'icon' => '',
'icon_style' => '',
'default' => '',
],
];
$this->default_settings = [
'choices' => $this->defaults,
];
$this->hooks();
}
/**
* Register hooks.
*
* @since 1.8.1
*/
private function hooks() {
// Customize HTML field values.
add_filter( 'wpforms_html_field_value', [ $this, 'field_html_value' ], 10, 4 );
add_filter( "wpforms_{$this->type}_field_html_value_images", [ $this, 'field_html_value_images' ], 10, 3 );
// Define additional field properties.
add_filter( "wpforms_field_properties_{$this->type}", [ $this, 'field_properties' ], 5, 3 );
// This field requires fieldset+legend instead of the field label.
add_filter( "wpforms_frontend_modern_is_field_requires_fieldset_{$this->type}", '__return_true', PHP_INT_MAX, 2 );
}
/**
* Define additional field properties.
*
* @since 1.8.2
*
* @param array $properties Field properties.
* @param array $field Field settings.
* @param array $form_data Form data and settings.
*
* @return array
*/
public function field_properties( $properties, $field, $form_data ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
// Define data.
$form_id = absint( $form_data['id'] );
$field_id = absint( $field['id'] );
$choices = $field['choices'];
// Remove primary input, unset for attribute for label.
unset( $properties['inputs']['primary'], $properties['label']['attr']['for'] );
// Set input container (ul) properties.
$properties['input_container'] = [
'class' => [],
'data' => [],
'attr' => [],
'id' => "wpforms-{$form_id}-field_{$field_id}",
];
$is_choice_limit_set = ! empty( $field['choice_limit'] ) && (int) $field['choice_limit'] > 0;
if ( $is_choice_limit_set ) {
$properties['input_container']['data']['choice-limit'] = $field['choice_limit'];
}
// Set input properties.
foreach ( $choices as $key => $choice ) {
// Choice labels should not be left blank, but if they are, we provide a basic value.
$label = $choice['label'] ?? '';
if ( $label === '' ) {
if ( 1 === count( $choices ) ) {
$label = esc_html__( 'Checked', 'wpforms-lite' );
} else {
/* translators: %s - item number. */
$label = sprintf( esc_html__( 'Item %s', 'wpforms-lite' ), $key );
}
}
$properties['inputs'][ $key ] = [
'container' => [
'attr' => [],
'class' => [ "choice-{$key}" ],
'data' => [],
'id' => '',
],
'label' => [
'attr' => [
'for' => "wpforms-{$form_id}-field_{$field_id}_{$key}",
],
'class' => [ 'wpforms-field-label-inline' ],
'data' => [],
'id' => '',
'text' => $label,
],
'attr' => [
'name' => "wpforms[fields][{$field_id}][]",
'value' => $key,
],
'class' => [ 'wpforms-payment-price' ],
'data' => [
'amount' => wpforms_format_amount( wpforms_sanitize_amount( $choice['value'] ?? '' ) ),
],
'id' => "wpforms-{$form_id}-field_{$field_id}_{$key}",
'icon' => $choice['icon'] ?? '',
'icon_style' => $choice['icon_style'] ?? '',
'image' => $choice['image'] ?? '',
'required' => ! empty( $field['required'] ) ? 'required' : '',
'default' => isset( $choice['default'] ),
];
// Rule for validator only if needed.
if ( $is_choice_limit_set ) {
$properties['inputs'][ $key ]['data']['rule-check-limit'] = 'true';
}
}
// Required class for pagebreak validation.
if ( ! empty( $field['required'] ) ) {
$properties['input_container']['class'][] = 'wpforms-field-required';
}
// Custom properties if image choices are enabled.
if ( ! empty( $field['choices_images'] ) ) {
$properties['input_container']['class'][] = 'wpforms-image-choices';
$properties['input_container']['class'][] = 'wpforms-image-choices-' . sanitize_html_class( $field['choices_images_style'] );
foreach ( $properties['inputs'] as $key => $inputs ) {
$properties['inputs'][ $key ]['container']['class'][] = 'wpforms-image-choices-item';
if ( in_array( $field['choices_images_style'], [ 'modern', 'classic' ], true ) ) {
$properties['inputs'][ $key ]['class'][] = 'wpforms-screen-reader-element';
}
}
} elseif ( ! empty( $field['choices_icons'] ) ) {
$properties = wpforms()->obj( 'icon_choices' )->field_properties( $properties, $field );
}
// Add selected class for choices with defaults.
foreach ( $properties['inputs'] as $key => $inputs ) {
if ( ! empty( $inputs['default'] ) ) {
$properties['inputs'][ $key ]['container']['class'][] = 'wpforms-selected';
}
}
return $properties;
}
/**
* Get field populated single property value.
*
* @since 1.8.2
*
* @param string $raw_value Value from a GET param, always a string.
* @param string $input Represent a subfield inside the field. May be empty.
* @param array $properties Field properties.
* @param array $field Current field specific data.
*
* @return array Modified field properties.
*/
protected function get_field_populated_single_property_value( $raw_value, $input, $properties, $field ) {
/*
* When the form is submitted, we get only choice values from the Fallback.
* As payment-checkbox (checkboxes) field doesn't support 'show_values' option -
* we should transform that into label to check against using general logic in parent method.
*/
if (
! is_string( $raw_value ) ||
empty( $field['choices'] ) ||
! is_array( $field['choices'] )
) {
return $properties;
}
// The form submits only the sum, so shortcut for Dynamic.
if ( ! is_numeric( $raw_value ) ) {
return parent::get_field_populated_single_property_value( $raw_value, $input, $properties, $field );
}
$get_value = wpforms_format_amount( wpforms_sanitize_amount( $raw_value ) );
foreach ( $field['choices'] as $choice ) {
if (
isset( $choice['label'], $choice['value'] ) &&
wpforms_format_amount( wpforms_sanitize_amount( $choice['value'] ) ) === $get_value
) {
$trans_value = $choice['label'];
// Stop iterating over choices.
break;
}
}
if ( empty( $trans_value ) ) {
return $properties;
}
return parent::get_field_populated_single_property_value( $trans_value, $input, $properties, $field );
}
/**
* Field options panel inside the builder.
*
* @since 1.8.2
*
* @param array $field Field settings.
*/
public function field_options( $field ) {
/*
* Basic field options.
*/
// Options open markup.
$this->field_option(
'basic-options',
$field,
[
'markup' => 'open',
]
);
// Label.
$this->field_option( 'label', $field );
// Choices option.
$this->field_option( 'choices_payments', $field );
// Show price after item labels.
$fld = $this->field_element(
'toggle',
$field,
[
'slug' => 'show_price_after_labels',
'value' => isset( $field['show_price_after_labels'] ) ? '1' : '0',
'desc' => esc_html__( 'Show Price After Item Labels', 'wpforms-lite' ),
'tooltip' => esc_html__( 'Check this option to show price of the item after the label.', 'wpforms-lite' ),
],
false
);
$args = [
'slug' => 'show_price_after_labels',
'content' => $fld,
];
$this->field_element( 'row', $field, $args );
// Choices Images.
$this->field_option( 'choices_images', $field );
// Hide Choices Images.
$this->field_option( 'choices_images_hide', $field );
// Choice Images Style (theme).
$this->field_option( 'choices_images_style', $field );
// Choices Icons.
$this->field_option( 'choices_icons', $field );
// Choices Icons Color.
$this->field_option( 'choices_icons_color', $field );
// Choices Icons Size.
$this->field_option( 'choices_icons_size', $field );
// Choices Icons Style.
$this->field_option( 'choices_icons_style', $field );
// Description.
$this->field_option( 'description', $field );
// Required toggle.
$this->field_option( 'required', $field );
// Options close markup.
$this->field_option(
'basic-options',
$field,
[
'markup' => 'close',
]
);
/*
* Advanced field options.
*/
// Options open markup.
$this->field_option(
'advanced-options',
$field,
[
'markup' => 'open',
]
);
// Input columns.
$this->field_option( 'input_columns', $field );
// Choice Limit.
$this->field_option( 'choice_limit', $field );
// Custom CSS classes.
$this->field_option( 'css', $field );
// Hide label.
$this->field_option( 'label_hide', $field );
// Options close markup.
$this->field_option(
'advanced-options',
$field,
[
'markup' => 'close',
]
);
}
/**
* Field preview inside the builder.
*
* @since 1.8.2
*
* @param array $field Field settings.
*/
public function field_preview( $field ) {
// Label.
$this->field_preview_option( 'label', $field );
// Choices.
$this->field_preview_option( 'choices', $field );
// Description.
$this->field_preview_option( 'description', $field );
}
/**
* Field display on the form front-end.
*
* @since 1.8.2
*
* @param array $field Field settings.
* @param array $deprecated Deprecated array.
* @param array $form_data Form data and settings.
*
* @noinspection HtmlUnknownAttribute
* @noinspection HtmlUnknownTarget
*/
public function field_display( $field, $deprecated, $form_data ) {
// Define data.
$container = $field['properties']['input_container'];
$choices = $field['properties']['inputs'];
printf(
'<ul %s>',
wpforms_html_attributes( $container['id'], $container['class'], $container['data'], $container['attr'] ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
foreach ( $choices as $key => $choice ) {
$label = $choice['label']['text'] ?? '';
/* translators: %s - item number. */
$label = $label !== '' ? $label : sprintf( esc_html__( 'Item %s', 'wpforms-lite' ), $key );
$label .= ! empty( $field['show_price_after_labels'] ) && isset( $choice['data']['amount'] ) ? $this->get_price_after_label( $choice['data']['amount'] ) : '';
printf(
'<li %s>',
wpforms_html_attributes( $choice['container']['id'], $choice['container']['class'], $choice['container']['data'], $choice['container']['attr'] ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
if ( empty( $field['dynamic_choices'] ) && ! empty( $field['choices_images'] ) ) {
// Image choices.
printf(
'<label %s>',
wpforms_html_attributes( $choice['label']['id'], $choice['label']['class'], $choice['label']['data'], $choice['label']['attr'] ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
echo '<span class="wpforms-image-choices-image">';
if ( ! empty( $choice['image'] ) ) {
printf(
'<img src="%s" alt="%s"%s>',
esc_url( $choice['image'] ),
esc_attr( $choice['label']['text'] ),
! empty( $choice['label']['text'] ) ? ' title="' . esc_attr( $choice['label']['text'] ) . '"' : ''
);
}
echo '</span>';
if ( $field['choices_images_style'] === 'none' ) {
echo '<br>';
}
printf(
'<input type="checkbox" %s %s %s>',
wpforms_html_attributes( $choice['id'], $choice['class'], $choice['data'], $choice['attr'] ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
esc_attr( $choice['required'] ),
checked( '1', $choice['default'], false )
);
echo '<span class="wpforms-image-choices-label">' . wp_kses_post( $label ) . '</span>';
echo '</label>';
} elseif ( empty( $field['dynamic_choices'] ) && ! empty( $field['choices_icons'] ) ) {
// Icon Choices.
wpforms()->obj( 'icon_choices' )->field_display( $field, $choice, 'checkbox', $label );
} else {
// Normal display.
printf(
'<input type="checkbox" %s %s %s>',
wpforms_html_attributes( $choice['id'], $choice['class'], $choice['data'], $choice['attr'] ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
esc_attr( $choice['required'] ),
checked( '1', $choice['default'], false )
);
printf(
'<label %s>%s</label>',
wpforms_html_attributes( $choice['label']['id'], $choice['label']['class'], $choice['label']['data'], $choice['label']['attr'] ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
wp_kses_post( $label )
);
}
echo '</li>';
}
echo '</ul>';
}
/**
* Validate field on submitting the form.
*
* @since 1.8.2
*
* @param int $field_id Field ID.
* @param array $field_submit Submitted field value (raw data).
* @param array $form_data Form data and settings.
*/
public function validate( $field_id, $field_submit, $form_data ) {
$field_id = (int) $field_id;
$error = '';
// Basic required check - If field is marked as required, check for entry data.
if ( ! empty( $form_data['fields'][ $field_id ]['required'] ) && empty( $field_submit ) ) {
$error = wpforms_get_required_label();
}
if ( ! empty( $field_submit ) ) {
foreach ( (array) $field_submit as $checked_choice ) {
// Validate that the option selected is real.
if ( empty( $form_data['fields'][ $field_id ]['choices'][ (int) $checked_choice ] ) ) {
$error = esc_html__( 'Invalid payment option.', 'wpforms-lite' );
break;
}
}
}
$field_submit = (array) $field_submit;
$this->validate_field_choice_limit( $field_id, $field_submit, $form_data );
if ( ! empty( $error ) ) {
wpforms()->obj( 'process' )->errors[ $form_data['id'] ][ $field_id ] = $error;
}
}
/**
* Format and sanitize field.
*
* @since 1.8.2
*
* @param int $field_id Field ID.
* @param array $field_submit Array of selected choice IDs.
* @param array $form_data Form data and settings.
*/
public function format( $field_id, $field_submit, $form_data ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh, Generic.Metrics.NestingLevel.MaxExceeded
$field_submit = array_values( (array) $field_submit );
$field = $form_data['fields'][ $field_id ];
$name = sanitize_text_field( $field['label'] );
$amount = 0;
$images = [];
$choice_values = [];
$choice_labels = [];
$choice_keys = [];
if ( ! empty( $field_submit ) ) {
foreach ( $field_submit as $choice_checked ) {
foreach ( $field['choices'] as $choice_id => $choice ) {
// Exit early.
if ( (int) $choice_checked !== (int) $choice_id ) {
continue;
}
$value = (float) wpforms_sanitize_amount( $choice['value'] ?? '' );
// Increase the total amount.
$amount += $value;
$value = wpforms_format_amount( $value, true );
$choice_label = '';
if ( ! empty( $choice['label'] ) ) {
$choice_label = sanitize_text_field( $choice['label'] );
$value = $choice_label . ' - ' . $value;
}
$choice_labels[] = $choice_label;
$choice_values[] = $value;
$choice_keys[] = $choice_id;
}
}
if ( ! empty( $choice_keys ) && ! empty( $field['choices_images'] ) ) {
foreach ( $choice_keys as $choice_key ) {
$images[] = ! empty( $field['choices'][ $choice_key ]['image'] ) ? esc_url_raw( $field['choices'][ $choice_key ]['image'] ) : '';
}
}
}
wpforms()->obj( 'process' )->fields[ $field_id ] = [
'name' => $name,
'value' => implode( "\r\n", $choice_values ),
'value_choice' => implode( "\r\n", $choice_labels ),
'value_raw' => implode( ',', array_map( 'absint', $field_submit ) ),
'amount' => wpforms_format_amount( $amount ),
'amount_raw' => $amount,
'currency' => wpforms_get_currency(),
'images' => $images,
'id' => absint( $field_id ),
'type' => sanitize_key( $this->type ),
];
}
}