Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/wpforms-.../src/Forms/Fields/PaymentM...
File: Field.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Forms\Fields\PaymentMultiple;
[2] Fix | Delete
[3] Fix | Delete
use WPForms_Field;
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* Radio payment field.
[7] Fix | Delete
*
[8] Fix | Delete
* @since 1.8.2
[9] Fix | Delete
*/
[10] Fix | Delete
class Field extends WPForms_Field {
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Primary class constructor.
[14] Fix | Delete
*
[15] Fix | Delete
* @since 1.8.2
[16] Fix | Delete
*/
[17] Fix | Delete
public function init() {
[18] Fix | Delete
[19] Fix | Delete
// Define field type information.
[20] Fix | Delete
$this->name = esc_html__( 'Multiple Items', 'wpforms-lite' );
[21] Fix | Delete
$this->keywords = esc_html__( 'product, store, ecommerce, pay, payment', 'wpforms-lite' );
[22] Fix | Delete
$this->type = 'payment-multiple';
[23] Fix | Delete
$this->icon = 'fa-list-ul';
[24] Fix | Delete
$this->order = 50;
[25] Fix | Delete
$this->group = 'payment';
[26] Fix | Delete
$this->defaults = [
[27] Fix | Delete
1 => [
[28] Fix | Delete
'label' => esc_html__( 'First Item', 'wpforms-lite' ),
[29] Fix | Delete
'value' => '10',
[30] Fix | Delete
'icon' => '',
[31] Fix | Delete
'icon_style' => '',
[32] Fix | Delete
'image' => '',
[33] Fix | Delete
'default' => '',
[34] Fix | Delete
],
[35] Fix | Delete
2 => [
[36] Fix | Delete
'label' => esc_html__( 'Second Item', 'wpforms-lite' ),
[37] Fix | Delete
'value' => '25',
[38] Fix | Delete
'icon' => '',
[39] Fix | Delete
'icon_style' => '',
[40] Fix | Delete
'image' => '',
[41] Fix | Delete
'default' => '',
[42] Fix | Delete
],
[43] Fix | Delete
3 => [
[44] Fix | Delete
'label' => esc_html__( 'Third Item', 'wpforms-lite' ),
[45] Fix | Delete
'value' => '50',
[46] Fix | Delete
'icon' => '',
[47] Fix | Delete
'icon_style' => '',
[48] Fix | Delete
'image' => '',
[49] Fix | Delete
'default' => '',
[50] Fix | Delete
],
[51] Fix | Delete
];
[52] Fix | Delete
[53] Fix | Delete
$this->default_settings = [
[54] Fix | Delete
'choices' => $this->defaults,
[55] Fix | Delete
];
[56] Fix | Delete
[57] Fix | Delete
$this->hooks();
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* Register hooks.
[62] Fix | Delete
*
[63] Fix | Delete
* @since 1.8.1
[64] Fix | Delete
*/
[65] Fix | Delete
private function hooks() {
[66] Fix | Delete
[67] Fix | Delete
// Customize HTML field values.
[68] Fix | Delete
add_filter( 'wpforms_html_field_value', [ $this, 'field_html_value' ], 10, 4 );
[69] Fix | Delete
add_filter( "wpforms_{$this->type}_field_html_value_images", [ $this, 'field_html_value_images' ], 10, 3 );
[70] Fix | Delete
[71] Fix | Delete
// Define additional field properties.
[72] Fix | Delete
add_filter( "wpforms_field_properties_{$this->type}", [ $this, 'field_properties' ], 5, 3 );
[73] Fix | Delete
[74] Fix | Delete
// This field requires fieldset+legend instead of the field label.
[75] Fix | Delete
add_filter( "wpforms_frontend_modern_is_field_requires_fieldset_{$this->type}", '__return_true', PHP_INT_MAX, 2 );
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* Define additional field properties.
[80] Fix | Delete
*
[81] Fix | Delete
* @since 1.8.2
[82] Fix | Delete
*
[83] Fix | Delete
* @param array $properties Field properties.
[84] Fix | Delete
* @param array $field Field settings.
[85] Fix | Delete
* @param array $form_data Form data and settings.
[86] Fix | Delete
*
[87] Fix | Delete
* @return array
[88] Fix | Delete
*/
[89] Fix | Delete
public function field_properties( $properties, $field, $form_data ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
[90] Fix | Delete
[91] Fix | Delete
// Define data.
[92] Fix | Delete
$form_id = absint( $form_data['id'] );
[93] Fix | Delete
$field_id = absint( $field['id'] );
[94] Fix | Delete
$choices = $field['choices'];
[95] Fix | Delete
[96] Fix | Delete
// Remove primary input, unset for attribute for label.
[97] Fix | Delete
unset( $properties['inputs']['primary'], $properties['label']['attr']['for'] );
[98] Fix | Delete
[99] Fix | Delete
// Set input container (ul) properties.
[100] Fix | Delete
$properties['input_container'] = [
[101] Fix | Delete
'class' => [],
[102] Fix | Delete
'data' => [],
[103] Fix | Delete
'attr' => [],
[104] Fix | Delete
'id' => "wpforms-{$form_id}-field_{$field_id}",
[105] Fix | Delete
];
[106] Fix | Delete
[107] Fix | Delete
// Set input properties.
[108] Fix | Delete
foreach ( $choices as $key => $choice ) {
[109] Fix | Delete
[110] Fix | Delete
$properties['inputs'][ $key ] = [
[111] Fix | Delete
'container' => [
[112] Fix | Delete
'attr' => [],
[113] Fix | Delete
'class' => [ "choice-{$key}" ],
[114] Fix | Delete
'data' => [],
[115] Fix | Delete
'id' => '',
[116] Fix | Delete
],
[117] Fix | Delete
'label' => [
[118] Fix | Delete
'attr' => [
[119] Fix | Delete
'for' => "wpforms-{$form_id}-field_{$field_id}_{$key}",
[120] Fix | Delete
],
[121] Fix | Delete
'class' => [ 'wpforms-field-label-inline' ],
[122] Fix | Delete
'data' => [],
[123] Fix | Delete
'id' => '',
[124] Fix | Delete
'text' => $choice['label'],
[125] Fix | Delete
],
[126] Fix | Delete
'attr' => [
[127] Fix | Delete
'name' => "wpforms[fields][{$field_id}]",
[128] Fix | Delete
'value' => $key,
[129] Fix | Delete
],
[130] Fix | Delete
'class' => [ 'wpforms-payment-price' ],
[131] Fix | Delete
'data' => [
[132] Fix | Delete
'amount' => wpforms_format_amount( wpforms_sanitize_amount( $choice['value'] ) ),
[133] Fix | Delete
],
[134] Fix | Delete
'id' => "wpforms-{$form_id}-field_{$field_id}_{$key}",
[135] Fix | Delete
'icon' => $choice['icon'] ?? '',
[136] Fix | Delete
'icon_style' => $choice['icon_style'] ?? '',
[137] Fix | Delete
'image' => $choice['image'] ?? '',
[138] Fix | Delete
'required' => ! empty( $field['required'] ) ? 'required' : '',
[139] Fix | Delete
'default' => isset( $choice['default'] ),
[140] Fix | Delete
];
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
// Required class for pagebreak validation.
[144] Fix | Delete
if ( ! empty( $field['required'] ) ) {
[145] Fix | Delete
$properties['input_container']['class'][] = 'wpforms-field-required';
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
// Custom properties if image choices are enabled.
[149] Fix | Delete
if ( ! empty( $field['choices_images'] ) ) {
[150] Fix | Delete
[151] Fix | Delete
$properties['input_container']['class'][] = 'wpforms-image-choices';
[152] Fix | Delete
$properties['input_container']['class'][] = 'wpforms-image-choices-' . sanitize_html_class( $field['choices_images_style'] );
[153] Fix | Delete
[154] Fix | Delete
foreach ( $properties['inputs'] as $key => $inputs ) {
[155] Fix | Delete
$properties['inputs'][ $key ]['container']['class'][] = 'wpforms-image-choices-item';
[156] Fix | Delete
[157] Fix | Delete
if ( in_array( $field['choices_images_style'], [ 'modern', 'classic' ], true ) ) {
[158] Fix | Delete
$properties['inputs'][ $key ]['class'][] = 'wpforms-screen-reader-element';
[159] Fix | Delete
}
[160] Fix | Delete
}
[161] Fix | Delete
} elseif ( ! empty( $field['choices_icons'] ) ) {
[162] Fix | Delete
$properties = wpforms()->obj( 'icon_choices' )->field_properties( $properties, $field );
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
// Add selected class for choices with defaults.
[166] Fix | Delete
foreach ( $properties['inputs'] as $key => $inputs ) {
[167] Fix | Delete
if ( ! empty( $inputs['default'] ) ) {
[168] Fix | Delete
$properties['inputs'][ $key ]['container']['class'][] = 'wpforms-selected';
[169] Fix | Delete
}
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
return $properties;
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
/**
[176] Fix | Delete
* Get field populated single property value.
[177] Fix | Delete
*
[178] Fix | Delete
* @since 1.8.2
[179] Fix | Delete
*
[180] Fix | Delete
* @param string $raw_value Value from a GET param, always a string.
[181] Fix | Delete
* @param string $input Represent a subfield inside the field. May be empty.
[182] Fix | Delete
* @param array $properties Field properties.
[183] Fix | Delete
* @param array $field Current field specific data.
[184] Fix | Delete
*
[185] Fix | Delete
* @return array Modified field properties.
[186] Fix | Delete
*/
[187] Fix | Delete
protected function get_field_populated_single_property_value( $raw_value, $input, $properties, $field ) {
[188] Fix | Delete
/*
[189] Fix | Delete
* When the form is submitted, we get only values (prices) from the Fallback.
[190] Fix | Delete
* As payment-multiple (radio) field doesn't support 'show_values' option -
[191] Fix | Delete
* we should transform value into label to check against using general logic in parent method.
[192] Fix | Delete
*/
[193] Fix | Delete
[194] Fix | Delete
if (
[195] Fix | Delete
! is_string( $raw_value ) ||
[196] Fix | Delete
empty( $field['choices'] ) ||
[197] Fix | Delete
! is_array( $field['choices'] )
[198] Fix | Delete
) {
[199] Fix | Delete
return $properties;
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
// The form submits only the sum, so shortcut for Dynamic.
[203] Fix | Delete
if ( ! is_numeric( $raw_value ) ) {
[204] Fix | Delete
return parent::get_field_populated_single_property_value( $raw_value, $input, $properties, $field );
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
$get_value = wpforms_format_amount( wpforms_sanitize_amount( $raw_value ) );
[208] Fix | Delete
[209] Fix | Delete
foreach ( $field['choices'] as $choice ) {
[210] Fix | Delete
if (
[211] Fix | Delete
isset( $choice['label'], $choice['value'] ) &&
[212] Fix | Delete
wpforms_format_amount( wpforms_sanitize_amount( $choice['value'] ) ) === $get_value
[213] Fix | Delete
) {
[214] Fix | Delete
$trans_value = $choice['label'];
[215] Fix | Delete
// Stop iterating over choices.
[216] Fix | Delete
break;
[217] Fix | Delete
}
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
if ( empty( $trans_value ) ) {
[221] Fix | Delete
return $properties;
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
return parent::get_field_populated_single_property_value( $trans_value, $input, $properties, $field );
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
/**
[228] Fix | Delete
* Field options panel inside the builder.
[229] Fix | Delete
*
[230] Fix | Delete
* @since 1.8.2
[231] Fix | Delete
*
[232] Fix | Delete
* @param array $field Field settings.
[233] Fix | Delete
*/
[234] Fix | Delete
public function field_options( $field ) {
[235] Fix | Delete
/*
[236] Fix | Delete
* Basic field options.
[237] Fix | Delete
*/
[238] Fix | Delete
[239] Fix | Delete
// Options open markup.
[240] Fix | Delete
$this->field_option(
[241] Fix | Delete
'basic-options',
[242] Fix | Delete
$field,
[243] Fix | Delete
[
[244] Fix | Delete
'markup' => 'open',
[245] Fix | Delete
]
[246] Fix | Delete
);
[247] Fix | Delete
[248] Fix | Delete
// Label.
[249] Fix | Delete
$this->field_option( 'label', $field );
[250] Fix | Delete
[251] Fix | Delete
// Choices option.
[252] Fix | Delete
$this->field_option( 'choices_payments', $field );
[253] Fix | Delete
[254] Fix | Delete
// Show price after item labels.
[255] Fix | Delete
$fld = $this->field_element(
[256] Fix | Delete
'toggle',
[257] Fix | Delete
$field,
[258] Fix | Delete
[
[259] Fix | Delete
'slug' => 'show_price_after_labels',
[260] Fix | Delete
'value' => isset( $field['show_price_after_labels'] ) ? '1' : '0',
[261] Fix | Delete
'desc' => esc_html__( 'Show Price After Item Labels', 'wpforms-lite' ),
[262] Fix | Delete
'tooltip' => esc_html__( 'Check this option to show price of the item after the label.', 'wpforms-lite' ),
[263] Fix | Delete
],
[264] Fix | Delete
false
[265] Fix | Delete
);
[266] Fix | Delete
$args = [
[267] Fix | Delete
'slug' => 'show_price_after_labels',
[268] Fix | Delete
'content' => $fld,
[269] Fix | Delete
];
[270] Fix | Delete
[271] Fix | Delete
$this->field_element( 'row', $field, $args );
[272] Fix | Delete
[273] Fix | Delete
// Choices Images.
[274] Fix | Delete
$this->field_option( 'choices_images', $field );
[275] Fix | Delete
[276] Fix | Delete
// Hide Choices Images.
[277] Fix | Delete
$this->field_option( 'choices_images_hide', $field );
[278] Fix | Delete
[279] Fix | Delete
// Choice Images Style (theme).
[280] Fix | Delete
$this->field_option( 'choices_images_style', $field );
[281] Fix | Delete
[282] Fix | Delete
// Choices Icons.
[283] Fix | Delete
$this->field_option( 'choices_icons', $field );
[284] Fix | Delete
[285] Fix | Delete
// Choices Icons Color.
[286] Fix | Delete
$this->field_option( 'choices_icons_color', $field );
[287] Fix | Delete
[288] Fix | Delete
// Choices Icons Size.
[289] Fix | Delete
$this->field_option( 'choices_icons_size', $field );
[290] Fix | Delete
[291] Fix | Delete
// Choices Icons Style.
[292] Fix | Delete
$this->field_option( 'choices_icons_style', $field );
[293] Fix | Delete
[294] Fix | Delete
// Description.
[295] Fix | Delete
$this->field_option( 'description', $field );
[296] Fix | Delete
[297] Fix | Delete
// Required toggle.
[298] Fix | Delete
$this->field_option( 'required', $field );
[299] Fix | Delete
[300] Fix | Delete
// Options close markup.
[301] Fix | Delete
$this->field_option(
[302] Fix | Delete
'basic-options',
[303] Fix | Delete
$field,
[304] Fix | Delete
[
[305] Fix | Delete
'markup' => 'close',
[306] Fix | Delete
]
[307] Fix | Delete
);
[308] Fix | Delete
[309] Fix | Delete
/*
[310] Fix | Delete
* Advanced field options.
[311] Fix | Delete
*/
[312] Fix | Delete
[313] Fix | Delete
// Options open markup.
[314] Fix | Delete
$this->field_option(
[315] Fix | Delete
'advanced-options',
[316] Fix | Delete
$field,
[317] Fix | Delete
[
[318] Fix | Delete
'markup' => 'open',
[319] Fix | Delete
]
[320] Fix | Delete
);
[321] Fix | Delete
[322] Fix | Delete
// Input columns.
[323] Fix | Delete
$this->field_option( 'input_columns', $field );
[324] Fix | Delete
[325] Fix | Delete
// Custom CSS classes.
[326] Fix | Delete
$this->field_option( 'css', $field );
[327] Fix | Delete
[328] Fix | Delete
// Hide label.
[329] Fix | Delete
$this->field_option( 'label_hide', $field );
[330] Fix | Delete
[331] Fix | Delete
// Options close markup.
[332] Fix | Delete
$this->field_option(
[333] Fix | Delete
'advanced-options',
[334] Fix | Delete
$field,
[335] Fix | Delete
[
[336] Fix | Delete
'markup' => 'close',
[337] Fix | Delete
]
[338] Fix | Delete
);
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
/**
[342] Fix | Delete
* Field preview inside the builder.
[343] Fix | Delete
*
[344] Fix | Delete
* @since 1.8.2
[345] Fix | Delete
*
[346] Fix | Delete
* @param array $field Field settings.
[347] Fix | Delete
*/
[348] Fix | Delete
public function field_preview( $field ) {
[349] Fix | Delete
[350] Fix | Delete
// Label.
[351] Fix | Delete
$this->field_preview_option( 'label', $field );
[352] Fix | Delete
[353] Fix | Delete
// Choices.
[354] Fix | Delete
$this->field_preview_option( 'choices', $field );
[355] Fix | Delete
[356] Fix | Delete
// Description.
[357] Fix | Delete
$this->field_preview_option( 'description', $field );
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
/**
[361] Fix | Delete
* Field display on the form front-end.
[362] Fix | Delete
*
[363] Fix | Delete
* @since 1.8.2
[364] Fix | Delete
*
[365] Fix | Delete
* @param array $field Field settings.
[366] Fix | Delete
* @param array $deprecated Deprecated array.
[367] Fix | Delete
* @param array $form_data Form data and settings.
[368] Fix | Delete
*
[369] Fix | Delete
* @noinspection HtmlUnknownAttribute
[370] Fix | Delete
* @noinspection HtmlUnknownTarget
[371] Fix | Delete
*/
[372] Fix | Delete
public function field_display( $field, $deprecated, $form_data ) {
[373] Fix | Delete
[374] Fix | Delete
// Define data.
[375] Fix | Delete
$container = $field['properties']['input_container'];
[376] Fix | Delete
$choices = $field['properties']['inputs'];
[377] Fix | Delete
[378] Fix | Delete
printf(
[379] Fix | Delete
'<ul %s>',
[380] Fix | Delete
wpforms_html_attributes( $container['id'], $container['class'], $container['data'], $container['attr'] ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[381] Fix | Delete
);
[382] Fix | Delete
[383] Fix | Delete
foreach ( $choices as $key => $choice ) {
[384] Fix | Delete
[385] Fix | Delete
$label = $choice['label']['text'] ?? '';
[386] Fix | Delete
[387] Fix | Delete
/* translators: %s - item number. */
[388] Fix | Delete
$label = $label !== '' ? $label : sprintf( esc_html__( 'Item %s', 'wpforms-lite' ), $key );
[389] Fix | Delete
[390] Fix | Delete
$label .= ! empty( $field['show_price_after_labels'] ) && isset( $choice['data']['amount'] ) ? $this->get_price_after_label( $choice['data']['amount'] ) : '';
[391] Fix | Delete
[392] Fix | Delete
printf(
[393] Fix | Delete
'<li %s>',
[394] Fix | Delete
wpforms_html_attributes( $choice['container']['id'], $choice['container']['class'], $choice['container']['data'], $choice['container']['attr'] ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[395] Fix | Delete
);
[396] Fix | Delete
[397] Fix | Delete
if ( empty( $field['dynamic_choices'] ) && ! empty( $field['choices_images'] ) ) {
[398] Fix | Delete
[399] Fix | Delete
// Image choices.
[400] Fix | Delete
printf(
[401] Fix | Delete
'<label %s>',
[402] Fix | Delete
wpforms_html_attributes( $choice['label']['id'], $choice['label']['class'], $choice['label']['data'], $choice['label']['attr'] ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[403] Fix | Delete
);
[404] Fix | Delete
[405] Fix | Delete
echo '<span class="wpforms-image-choices-image">';
[406] Fix | Delete
[407] Fix | Delete
if ( ! empty( $choice['image'] ) ) {
[408] Fix | Delete
printf(
[409] Fix | Delete
'<img src="%s" alt="%s"%s>',
[410] Fix | Delete
esc_url( $choice['image'] ),
[411] Fix | Delete
esc_attr( $choice['label']['text'] ),
[412] Fix | Delete
! empty( $choice['label']['text'] ) ? ' title="' . esc_attr( $choice['label']['text'] ) . '"' : ''
[413] Fix | Delete
);
[414] Fix | Delete
}
[415] Fix | Delete
[416] Fix | Delete
echo '</span>';
[417] Fix | Delete
[418] Fix | Delete
if ( $field['choices_images_style'] === 'none' ) {
[419] Fix | Delete
echo '<br>';
[420] Fix | Delete
}
[421] Fix | Delete
[422] Fix | Delete
printf(
[423] Fix | Delete
'<input type="radio" %s %s %s>',
[424] Fix | Delete
wpforms_html_attributes( $choice['id'], $choice['class'], $choice['data'], $choice['attr'] ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[425] Fix | Delete
esc_attr( $choice['required'] ),
[426] Fix | Delete
checked( '1', $choice['default'], false )
[427] Fix | Delete
);
[428] Fix | Delete
[429] Fix | Delete
echo '<span class="wpforms-image-choices-label">' . wp_kses_post( $label ) . '</span>';
[430] Fix | Delete
[431] Fix | Delete
echo '</label>';
[432] Fix | Delete
[433] Fix | Delete
} elseif ( empty( $field['dynamic_choices'] ) && ! empty( $field['choices_icons'] ) ) {
[434] Fix | Delete
// Icon Choices.
[435] Fix | Delete
wpforms()->obj( 'icon_choices' )->field_display( $field, $choice, 'radio', $label );
[436] Fix | Delete
[437] Fix | Delete
} else {
[438] Fix | Delete
[439] Fix | Delete
// Normal display.
[440] Fix | Delete
printf(
[441] Fix | Delete
'<input type="radio" %s %s %s>',
[442] Fix | Delete
wpforms_html_attributes( $choice['id'], $choice['class'], $choice['data'], $choice['attr'] ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[443] Fix | Delete
esc_attr( $choice['required'] ),
[444] Fix | Delete
checked( '1', $choice['default'], false )
[445] Fix | Delete
);
[446] Fix | Delete
[447] Fix | Delete
printf(
[448] Fix | Delete
'<label %s>%s</label>',
[449] Fix | Delete
wpforms_html_attributes( $choice['label']['id'], $choice['label']['class'], $choice['label']['data'], $choice['label']['attr'] ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[450] Fix | Delete
wp_kses_post( $label )
[451] Fix | Delete
);
[452] Fix | Delete
}
[453] Fix | Delete
[454] Fix | Delete
echo '</li>';
[455] Fix | Delete
}
[456] Fix | Delete
[457] Fix | Delete
echo '</ul>';
[458] Fix | Delete
}
[459] Fix | Delete
[460] Fix | Delete
/**
[461] Fix | Delete
* Validate field on submitting the form.
[462] Fix | Delete
*
[463] Fix | Delete
* @since 1.8.2
[464] Fix | Delete
*
[465] Fix | Delete
* @param int $field_id Field ID.
[466] Fix | Delete
* @param mixed $field_submit Submitted field value (raw data).
[467] Fix | Delete
* @param array $form_data Form data and settings.
[468] Fix | Delete
*/
[469] Fix | Delete
public function validate( $field_id, $field_submit, $form_data ) {
[470] Fix | Delete
[471] Fix | Delete
// Basic required check - If field is marked as required, check for entry data.
[472] Fix | Delete
if ( ! empty( $form_data['fields'][ $field_id ]['required'] ) && empty( $field_submit ) ) {
[473] Fix | Delete
[474] Fix | Delete
wpforms()->obj( 'process' )->errors[ $form_data['id'] ][ $field_id ] = wpforms_get_required_label();
[475] Fix | Delete
}
[476] Fix | Delete
[477] Fix | Delete
// Validate that the option selected is real.
[478] Fix | Delete
if (
[479] Fix | Delete
is_string( $field_submit ) &&
[480] Fix | Delete
! empty( $field_submit )
[481] Fix | Delete
&& empty( $form_data['fields'][ $field_id ]['choices'][ $field_submit ] )
[482] Fix | Delete
) {
[483] Fix | Delete
wpforms()->obj( 'process' )->errors[ $form_data['id'] ][ $field_id ] =
[484] Fix | Delete
esc_html__( 'Invalid payment option.', 'wpforms-lite' );
[485] Fix | Delete
}
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
/**
[489] Fix | Delete
* Format and sanitize field.
[490] Fix | Delete
*
[491] Fix | Delete
* @since 1.8.2
[492] Fix | Delete
*
[493] Fix | Delete
* @param int $field_id Field ID.
[494] Fix | Delete
* @param string $field_submit Submitted form data.
[495] Fix | Delete
* @param array $form_data Form data and settings.
[496] Fix | Delete
*/
[497] Fix | Delete
public function format( $field_id, $field_submit, $form_data ) {
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function