Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/wpforms-.../includes/fields
File: class-text.php
<?php
[0] Fix | Delete
[1] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[2] Fix | Delete
exit;
[3] Fix | Delete
}
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* Single line text field.
[7] Fix | Delete
*
[8] Fix | Delete
* @since 1.0.0
[9] Fix | Delete
*/
[10] Fix | Delete
class WPForms_Field_Text extends WPForms_Field {
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Primary class constructor.
[14] Fix | Delete
*
[15] Fix | Delete
* @since 1.0.0
[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__( 'Single Line Text', 'wpforms-lite' );
[21] Fix | Delete
$this->type = 'text';
[22] Fix | Delete
$this->icon = 'fa-text-width';
[23] Fix | Delete
$this->order = 30;
[24] Fix | Delete
[25] Fix | Delete
// Define additional field properties.
[26] Fix | Delete
add_filter( 'wpforms_field_properties_text', [ $this, 'field_properties' ], 5, 3 );
[27] Fix | Delete
add_action( 'wpforms_frontend_js', [ $this, 'frontend_js' ] );
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Convert mask formatted for jquery.inputmask into the format used by amp-inputmask.
[32] Fix | Delete
*
[33] Fix | Delete
* Note that amp-inputmask does not yet support all of the options that jquery.inputmask provides.
[34] Fix | Delete
* In particular, amp-inputmask doesn't provides:
[35] Fix | Delete
* - Upper-alphabetical mask.
[36] Fix | Delete
* - Upper-alphanumeric mask.
[37] Fix | Delete
* - Advanced Input Masks with arbitrary repeating groups.
[38] Fix | Delete
*
[39] Fix | Delete
* @link https://amp.dev/documentation/components/amp-inputmask
[40] Fix | Delete
* @link https://wpforms.com/docs/how-to-use-custom-input-masks/
[41] Fix | Delete
*
[42] Fix | Delete
* @param string $mask Mask formatted for jquery.inputmask.
[43] Fix | Delete
* @return array {
[44] Fix | Delete
* Mask and placeholder.
[45] Fix | Delete
*
[46] Fix | Delete
* @type string $mask Mask for amp-inputmask.
[47] Fix | Delete
* @type string $placeholder Placeholder derived from mask if one is not supplied.
[48] Fix | Delete
* }
[49] Fix | Delete
*/
[50] Fix | Delete
protected function convert_mask_to_amp_inputmask( $mask ) {
[51] Fix | Delete
$placeholder = '';
[52] Fix | Delete
[53] Fix | Delete
// Convert jquery.inputmask format into amp-inputmask format.
[54] Fix | Delete
$amp_mask = '';
[55] Fix | Delete
$req_mask_mapping = [
[56] Fix | Delete
'9' => '0', // Numeric.
[57] Fix | Delete
'a' => 'L', // Alphabetical (a-z or A-Z).
[58] Fix | Delete
'A' => 'L', // Upper-alphabetical (A-Z). Note: AMP does not have an uppercase-alphabetical mask type, so same as previous.
[59] Fix | Delete
'*' => 'A', // Alphanumeric (0-9, a-z, A-Z).
[60] Fix | Delete
'&' => 'A', // Upper-alphanumeric (A-Z, 0-9). Note: AMP does not have an uppercase-alphanumeric mask type, so same as previous.
[61] Fix | Delete
' ' => '_', // Automatically insert spaces.
[62] Fix | Delete
];
[63] Fix | Delete
$opt_mask_mapping = [
[64] Fix | Delete
'9' => '9', // The user may optionally add a numeric character.
[65] Fix | Delete
'a' => 'l', // The user may optionally add an alphabetical character.
[66] Fix | Delete
'A' => 'l', // The user may optionally add an alphabetical character.
[67] Fix | Delete
'*' => 'a', // The user may optionally add an alphanumeric character.
[68] Fix | Delete
'&' => 'a', // The user may optionally add an alphanumeric character.
[69] Fix | Delete
];
[70] Fix | Delete
$placeholder_mapping = [
[71] Fix | Delete
'9' => '0',
[72] Fix | Delete
'a' => 'a',
[73] Fix | Delete
'A' => 'a',
[74] Fix | Delete
'*' => '_',
[75] Fix | Delete
'&' => '_',
[76] Fix | Delete
];
[77] Fix | Delete
$is_inside_optional = false;
[78] Fix | Delete
$last_mask_token = null;
[79] Fix | Delete
for ( $i = 0, $len = strlen( $mask ); $i < $len; $i++ ) {
[80] Fix | Delete
if ( '[' === $mask[ $i ] ) {
[81] Fix | Delete
$is_inside_optional = true;
[82] Fix | Delete
$placeholder .= $mask[ $i ];
[83] Fix | Delete
continue;
[84] Fix | Delete
} elseif ( ']' === $mask[ $i ] ) {
[85] Fix | Delete
$is_inside_optional = false;
[86] Fix | Delete
$placeholder .= $mask[ $i ];
[87] Fix | Delete
continue;
[88] Fix | Delete
} elseif ( isset( $last_mask_token ) && preg_match( '/^\{(?P<n>\d+)(?:,(?P<m>\d+))?\}/', substr( $mask, $i ), $matches ) ) {
[89] Fix | Delete
$amp_mask .= str_repeat( $req_mask_mapping[ $last_mask_token ], $matches['n'] );
[90] Fix | Delete
$placeholder .= str_repeat( $placeholder_mapping[ $last_mask_token ], $matches['n'] );
[91] Fix | Delete
if ( isset( $matches['m'] ) ) {
[92] Fix | Delete
$amp_mask .= str_repeat( $opt_mask_mapping[ $last_mask_token ], $matches['m'] );
[93] Fix | Delete
$placeholder .= str_repeat( $placeholder_mapping[ $last_mask_token ], $matches['m'] );
[94] Fix | Delete
}
[95] Fix | Delete
$i += strlen( $matches[0] ) - 1;
[96] Fix | Delete
[97] Fix | Delete
$last_mask_token = null; // Reset.
[98] Fix | Delete
continue;
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
if ( '\\' === $mask[ $i ] ) {
[102] Fix | Delete
$amp_mask .= '\\';
[103] Fix | Delete
$i++;
[104] Fix | Delete
if ( ! isset( $mask[ $i ] ) ) {
[105] Fix | Delete
continue;
[106] Fix | Delete
}
[107] Fix | Delete
$amp_mask .= $mask[ $i ];
[108] Fix | Delete
} else {
[109] Fix | Delete
// Remember this token in case it is a mask.
[110] Fix | Delete
if ( isset( $opt_mask_mapping[ $mask[ $i ] ] ) ) {
[111] Fix | Delete
$last_mask_token = $mask[ $i ];
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
if ( $is_inside_optional && isset( $opt_mask_mapping[ $mask[ $i ] ] ) ) {
[115] Fix | Delete
$amp_mask .= $opt_mask_mapping[ $mask[ $i ] ];
[116] Fix | Delete
} elseif ( isset( $req_mask_mapping[ $mask[ $i ] ] ) ) {
[117] Fix | Delete
$amp_mask .= $req_mask_mapping[ $mask[ $i ] ];
[118] Fix | Delete
} else {
[119] Fix | Delete
$amp_mask .= '\\' . $mask[ $i ];
[120] Fix | Delete
}
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
if ( isset( $placeholder_mapping[ $mask[ $i ] ] ) ) {
[124] Fix | Delete
$placeholder .= $placeholder_mapping[ $mask[ $i ] ];
[125] Fix | Delete
} else {
[126] Fix | Delete
$placeholder .= $mask[ $i ];
[127] Fix | Delete
}
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
return [ $amp_mask, $placeholder ];
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
/**
[134] Fix | Delete
* Define additional field properties.
[135] Fix | Delete
*
[136] Fix | Delete
* @since 1.4.5
[137] Fix | Delete
*
[138] Fix | Delete
* @param array $properties Field properties.
[139] Fix | Delete
* @param array $field Field settings.
[140] Fix | Delete
* @param array $form_data Form data and settings.
[141] Fix | Delete
*
[142] Fix | Delete
* @return array
[143] Fix | Delete
*/
[144] Fix | Delete
public function field_properties( $properties, $field, $form_data ) {
[145] Fix | Delete
[146] Fix | Delete
// Input primary: Detect custom input mask.
[147] Fix | Delete
if ( empty( $field['input_mask'] ) ) {
[148] Fix | Delete
return $properties;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
// Add class that will trigger custom mask.
[152] Fix | Delete
$properties['inputs']['primary']['class'][] = 'wpforms-masked-input';
[153] Fix | Delete
[154] Fix | Delete
if ( wpforms_is_amp() ) {
[155] Fix | Delete
return $this->get_amp_input_mask_properties( $properties, $field );
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
$properties['inputs']['primary']['data']['rule-inputmask-incomplete'] = true;
[159] Fix | Delete
[160] Fix | Delete
if ( strpos( $field['input_mask'], 'alias:' ) !== false ) {
[161] Fix | Delete
$mask = str_replace( 'alias:', '', $field['input_mask'] );
[162] Fix | Delete
$properties['inputs']['primary']['data']['inputmask-alias'] = $mask;
[163] Fix | Delete
[164] Fix | Delete
return $properties;
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
if ( strpos( $field['input_mask'], 'regex:' ) !== false ) {
[168] Fix | Delete
$mask = str_replace( 'regex:', '', $field['input_mask'] );
[169] Fix | Delete
$properties['inputs']['primary']['data']['inputmask-regex'] = $mask;
[170] Fix | Delete
[171] Fix | Delete
return $properties;
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
if ( strpos( $field['input_mask'], 'date:' ) !== false ) {
[175] Fix | Delete
$mask = str_replace( 'date:', '', $field['input_mask'] );
[176] Fix | Delete
$properties['inputs']['primary']['data']['inputmask-alias'] = 'datetime';
[177] Fix | Delete
$properties['inputs']['primary']['data']['inputmask-inputformat'] = $mask;
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* Some datetime formats include letters, so we need to switch inputmode to text.
[181] Fix | Delete
* For instance:
[182] Fix | Delete
* – tt is am/pm
[183] Fix | Delete
* – TT is AM/PM
[184] Fix | Delete
*/
[185] Fix | Delete
$properties['inputs']['primary']['data']['inputmask-inputmode'] = preg_match( '/[tT]/', $mask ) ? 'text' : 'numeric';
[186] Fix | Delete
[187] Fix | Delete
return $properties;
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
$properties['inputs']['primary']['data']['inputmask-mask'] = $field['input_mask'];
[191] Fix | Delete
[192] Fix | Delete
return $properties;
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
/**
[196] Fix | Delete
* Define additional field properties for the inputmask on AMP pages.
[197] Fix | Delete
*
[198] Fix | Delete
* @since 1.7.6
[199] Fix | Delete
*
[200] Fix | Delete
* @param array $properties Field properties.
[201] Fix | Delete
* @param array $field Field settings.
[202] Fix | Delete
*
[203] Fix | Delete
* @return array
[204] Fix | Delete
*/
[205] Fix | Delete
private function get_amp_input_mask_properties( $properties, $field ) {
[206] Fix | Delete
[207] Fix | Delete
list( $amp_mask, $placeholder ) = $this->convert_mask_to_amp_inputmask( $field['input_mask'] );
[208] Fix | Delete
[209] Fix | Delete
$properties['inputs']['primary']['attr']['mask'] = $amp_mask;
[210] Fix | Delete
[211] Fix | Delete
if ( empty( $properties['inputs']['primary']['attr']['placeholder'] ) ) {
[212] Fix | Delete
$properties['inputs']['primary']['attr']['placeholder'] = $placeholder;
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
return $properties;
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Field options panel inside the builder.
[220] Fix | Delete
*
[221] Fix | Delete
* @since 1.0.0
[222] Fix | Delete
*
[223] Fix | Delete
* @param array $field Field settings.
[224] Fix | Delete
*/
[225] Fix | Delete
public function field_options( $field ) {
[226] Fix | Delete
/*
[227] Fix | Delete
* Basic field options.
[228] Fix | Delete
*/
[229] Fix | Delete
[230] Fix | Delete
// Options open markup.
[231] Fix | Delete
$this->field_option(
[232] Fix | Delete
'basic-options',
[233] Fix | Delete
$field,
[234] Fix | Delete
[
[235] Fix | Delete
'markup' => 'open',
[236] Fix | Delete
]
[237] Fix | Delete
);
[238] Fix | Delete
[239] Fix | Delete
// Label.
[240] Fix | Delete
$this->field_option( 'label', $field );
[241] Fix | Delete
[242] Fix | Delete
// Description.
[243] Fix | Delete
$this->field_option( 'description', $field );
[244] Fix | Delete
[245] Fix | Delete
// Required toggle.
[246] Fix | Delete
$this->field_option( 'required', $field );
[247] Fix | Delete
[248] Fix | Delete
// Options close markup.
[249] Fix | Delete
$this->field_option(
[250] Fix | Delete
'basic-options',
[251] Fix | Delete
$field,
[252] Fix | Delete
[
[253] Fix | Delete
'markup' => 'close',
[254] Fix | Delete
]
[255] Fix | Delete
);
[256] Fix | Delete
[257] Fix | Delete
/*
[258] Fix | Delete
* Advanced field options.
[259] Fix | Delete
*/
[260] Fix | Delete
[261] Fix | Delete
// Options open markup.
[262] Fix | Delete
$this->field_option(
[263] Fix | Delete
'advanced-options',
[264] Fix | Delete
$field,
[265] Fix | Delete
[
[266] Fix | Delete
'markup' => 'open',
[267] Fix | Delete
]
[268] Fix | Delete
);
[269] Fix | Delete
[270] Fix | Delete
// Size.
[271] Fix | Delete
$this->field_option( 'size', $field );
[272] Fix | Delete
[273] Fix | Delete
// Placeholder.
[274] Fix | Delete
$this->field_option( 'placeholder', $field );
[275] Fix | Delete
[276] Fix | Delete
// Limit length.
[277] Fix | Delete
$args = [
[278] Fix | Delete
'slug' => 'limit_enabled',
[279] Fix | Delete
'content' => $this->field_element(
[280] Fix | Delete
'toggle',
[281] Fix | Delete
$field,
[282] Fix | Delete
[
[283] Fix | Delete
'slug' => 'limit_enabled',
[284] Fix | Delete
'value' => isset( $field['limit_enabled'] ),
[285] Fix | Delete
'desc' => esc_html__( 'Limit Length', 'wpforms-lite' ),
[286] Fix | Delete
'tooltip' => esc_html__( 'Check this option to limit text length by characters or words count.', 'wpforms-lite' ),
[287] Fix | Delete
],
[288] Fix | Delete
false
[289] Fix | Delete
),
[290] Fix | Delete
];
[291] Fix | Delete
[292] Fix | Delete
$this->field_element( 'row', $field, $args );
[293] Fix | Delete
[294] Fix | Delete
$count = $this->field_element(
[295] Fix | Delete
'text',
[296] Fix | Delete
$field,
[297] Fix | Delete
[
[298] Fix | Delete
'type' => 'number',
[299] Fix | Delete
'slug' => 'limit_count',
[300] Fix | Delete
'attrs' => [
[301] Fix | Delete
'min' => 1,
[302] Fix | Delete
'step' => 1,
[303] Fix | Delete
'pattern' => '[0-9]',
[304] Fix | Delete
],
[305] Fix | Delete
'value' => ! empty( $field['limit_count'] ) ? absint( $field['limit_count'] ) : 1,
[306] Fix | Delete
],
[307] Fix | Delete
false
[308] Fix | Delete
);
[309] Fix | Delete
[310] Fix | Delete
$mode = $this->field_element(
[311] Fix | Delete
'select',
[312] Fix | Delete
$field,
[313] Fix | Delete
[
[314] Fix | Delete
'slug' => 'limit_mode',
[315] Fix | Delete
'value' => ! empty( $field['limit_mode'] ) ? esc_attr( $field['limit_mode'] ) : 'characters',
[316] Fix | Delete
'options' => [
[317] Fix | Delete
'characters' => esc_html__( 'Characters', 'wpforms-lite' ),
[318] Fix | Delete
'words' => esc_html__( 'Words', 'wpforms-lite' ),
[319] Fix | Delete
],
[320] Fix | Delete
],
[321] Fix | Delete
false
[322] Fix | Delete
);
[323] Fix | Delete
[324] Fix | Delete
$args = [
[325] Fix | Delete
'slug' => 'limit_controls',
[326] Fix | Delete
'class' => ! isset( $field['limit_enabled'] ) ? 'wpforms-hide' : '',
[327] Fix | Delete
'content' => $count . $mode,
[328] Fix | Delete
];
[329] Fix | Delete
[330] Fix | Delete
$this->field_element( 'row', $field, $args );
[331] Fix | Delete
[332] Fix | Delete
// Default value.
[333] Fix | Delete
$this->field_option( 'default_value', $field );
[334] Fix | Delete
[335] Fix | Delete
// Input Mask.
[336] Fix | Delete
$lbl = $this->field_element(
[337] Fix | Delete
'label',
[338] Fix | Delete
$field,
[339] Fix | Delete
[
[340] Fix | Delete
'slug' => 'input_mask',
[341] Fix | Delete
'value' => esc_html__( 'Input Mask', 'wpforms-lite' ),
[342] Fix | Delete
'tooltip' => esc_html__( 'Enter your custom input mask.', 'wpforms-lite' ),
[343] Fix | Delete
'after_tooltip' => '<a href="' . esc_url( wpforms_utm_link( 'https://wpforms.com/docs/how-to-use-custom-input-masks/', 'Field Options', 'Input Mask Documentation' ) ) . '" class="after-label-description" target="_blank" rel="noopener noreferrer">' . esc_html__( 'See Examples & Docs', 'wpforms-lite' ) . '</a>',
[344] Fix | Delete
],
[345] Fix | Delete
false
[346] Fix | Delete
);
[347] Fix | Delete
$fld = $this->field_element(
[348] Fix | Delete
'text',
[349] Fix | Delete
$field,
[350] Fix | Delete
[
[351] Fix | Delete
'slug' => 'input_mask',
[352] Fix | Delete
'value' => ! empty( $field['input_mask'] ) ? esc_attr( $field['input_mask'] ) : '',
[353] Fix | Delete
],
[354] Fix | Delete
false
[355] Fix | Delete
);
[356] Fix | Delete
[357] Fix | Delete
$this->field_element(
[358] Fix | Delete
'row',
[359] Fix | Delete
$field,
[360] Fix | Delete
[
[361] Fix | Delete
'slug' => 'input_mask',
[362] Fix | Delete
'content' => $lbl . $fld,
[363] Fix | Delete
]
[364] Fix | Delete
);
[365] Fix | Delete
[366] Fix | Delete
// Custom CSS classes.
[367] Fix | Delete
$this->field_option( 'css', $field );
[368] Fix | Delete
[369] Fix | Delete
// Hide label.
[370] Fix | Delete
$this->field_option( 'label_hide', $field );
[371] Fix | Delete
[372] Fix | Delete
// Options close markup.
[373] Fix | Delete
$this->field_option(
[374] Fix | Delete
'advanced-options',
[375] Fix | Delete
$field,
[376] Fix | Delete
[
[377] Fix | Delete
'markup' => 'close',
[378] Fix | Delete
]
[379] Fix | Delete
);
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
/**
[383] Fix | Delete
* Field preview inside the builder.
[384] Fix | Delete
*
[385] Fix | Delete
* @since 1.0.0
[386] Fix | Delete
*
[387] Fix | Delete
* @param array $field Field settings.
[388] Fix | Delete
*/
[389] Fix | Delete
public function field_preview( $field ) {
[390] Fix | Delete
[391] Fix | Delete
// Define data.
[392] Fix | Delete
$placeholder = ! empty( $field['placeholder'] ) ? $field['placeholder'] : '';
[393] Fix | Delete
$default_value = ! empty( $field['default_value'] ) ? $field['default_value'] : '';
[394] Fix | Delete
[395] Fix | Delete
// Label.
[396] Fix | Delete
$this->field_preview_option( 'label', $field );
[397] Fix | Delete
[398] Fix | Delete
// Primary input.
[399] Fix | Delete
echo '<input type="text" placeholder="' . esc_attr( $placeholder ) . '" value="' . esc_attr( $default_value ) . '" class="primary-input" readonly>';
[400] Fix | Delete
[401] Fix | Delete
// Description.
[402] Fix | Delete
$this->field_preview_option( 'description', $field );
[403] Fix | Delete
}
[404] Fix | Delete
[405] Fix | Delete
/**
[406] Fix | Delete
* Field display on the form front-end.
[407] Fix | Delete
*
[408] Fix | Delete
* @since 1.0.0
[409] Fix | Delete
*
[410] Fix | Delete
* @param array $field Field settings.
[411] Fix | Delete
* @param array $deprecated Deprecated.
[412] Fix | Delete
* @param array $form_data Form data and settings.
[413] Fix | Delete
*/
[414] Fix | Delete
public function field_display( $field, $deprecated, $form_data ) {
[415] Fix | Delete
[416] Fix | Delete
// Define data.
[417] Fix | Delete
$primary = $field['properties']['inputs']['primary'];
[418] Fix | Delete
[419] Fix | Delete
if ( isset( $field['limit_enabled'] ) ) {
[420] Fix | Delete
$limit_count = isset( $field['limit_count'] ) ? absint( $field['limit_count'] ) : 0;
[421] Fix | Delete
$limit_mode = isset( $field['limit_mode'] ) ? sanitize_key( $field['limit_mode'] ) : 'characters';
[422] Fix | Delete
[423] Fix | Delete
$primary['data']['form-id'] = $form_data['id'];
[424] Fix | Delete
$primary['data']['field-id'] = $field['id'];
[425] Fix | Delete
[426] Fix | Delete
if ( 'characters' === $limit_mode ) {
[427] Fix | Delete
$primary['class'][] = 'wpforms-limit-characters-enabled';
[428] Fix | Delete
$primary['attr']['maxlength'] = $limit_count;
[429] Fix | Delete
$primary['data']['text-limit'] = $limit_count;
[430] Fix | Delete
} else {
[431] Fix | Delete
$primary['class'][] = 'wpforms-limit-words-enabled';
[432] Fix | Delete
$primary['data']['text-limit'] = $limit_count;
[433] Fix | Delete
}
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
// Primary field.
[437] Fix | Delete
printf(
[438] Fix | Delete
'<input type="text" %s %s>',
[439] Fix | Delete
wpforms_html_attributes( $primary['id'], $primary['class'], $primary['data'], $primary['attr'] ),
[440] Fix | Delete
$primary['required'] // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[441] Fix | Delete
);
[442] Fix | Delete
}
[443] Fix | Delete
[444] Fix | Delete
/**
[445] Fix | Delete
* Enqueue frontend limit option js.
[446] Fix | Delete
*
[447] Fix | Delete
* @since 1.5.6
[448] Fix | Delete
*
[449] Fix | Delete
* @param array $forms Forms on the current page.
[450] Fix | Delete
*/
[451] Fix | Delete
public function frontend_js( $forms ) {
[452] Fix | Delete
[453] Fix | Delete
// Get fields.
[454] Fix | Delete
$fields = array_map(
[455] Fix | Delete
function( $form ) {
[456] Fix | Delete
return empty( $form['fields'] ) ? [] : $form['fields'];
[457] Fix | Delete
},
[458] Fix | Delete
(array) $forms
[459] Fix | Delete
);
[460] Fix | Delete
[461] Fix | Delete
// Make fields flat.
[462] Fix | Delete
$fields = array_reduce(
[463] Fix | Delete
$fields,
[464] Fix | Delete
function( $accumulator, $current ) {
[465] Fix | Delete
return array_merge( $accumulator, $current );
[466] Fix | Delete
},
[467] Fix | Delete
[]
[468] Fix | Delete
);
[469] Fix | Delete
[470] Fix | Delete
// Leave only fields with limit.
[471] Fix | Delete
$fields = array_filter(
[472] Fix | Delete
$fields,
[473] Fix | Delete
function( $field ) {
[474] Fix | Delete
return $field['type'] === $this->type && isset( $field['limit_enabled'] ) && ! empty( $field['limit_count'] );
[475] Fix | Delete
}
[476] Fix | Delete
);
[477] Fix | Delete
[478] Fix | Delete
if ( count( $fields ) ) {
[479] Fix | Delete
$min = wpforms_get_min_suffix();
[480] Fix | Delete
[481] Fix | Delete
wp_enqueue_script(
[482] Fix | Delete
'wpforms-text-limit',
[483] Fix | Delete
WPFORMS_PLUGIN_URL . "assets/js/frontend/fields/text-limit.es5{$min}.js",
[484] Fix | Delete
[],
[485] Fix | Delete
WPFORMS_VERSION,
[486] Fix | Delete
$this->load_script_in_footer()
[487] Fix | Delete
);
[488] Fix | Delete
}
[489] Fix | Delete
}
[490] Fix | Delete
[491] Fix | Delete
/**
[492] Fix | Delete
* Format and sanitize field.
[493] Fix | Delete
*
[494] Fix | Delete
* @since 1.5.6
[495] Fix | Delete
*
[496] Fix | Delete
* @param int $field_id Field ID.
[497] Fix | Delete
* @param mixed $field_submit Field value that was submitted.
[498] Fix | Delete
* @param array $form_data Form data and settings.
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function