Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../public_h.../wp-conte.../plugins/wpforms-.../includes/fields
File: class-base.php
*
[500] Fix | Delete
* @param array $form_data Form data.
[501] Fix | Delete
*
[502] Fix | Delete
* @return array
[503] Fix | Delete
*/
[504] Fix | Delete
public function field_fill_empty_choices( $form_data ) {
[505] Fix | Delete
[506] Fix | Delete
if ( empty( $form_data['fields'] ) ) {
[507] Fix | Delete
return $form_data;
[508] Fix | Delete
}
[509] Fix | Delete
[510] Fix | Delete
// Set value for choices with the image only. Conditional logic doesn't work without value.
[511] Fix | Delete
foreach ( $form_data['fields'] as $field_key => $field ) {
[512] Fix | Delete
// Payment fields have their labels set up upfront.
[513] Fix | Delete
if ( empty( $field['choices'] ) || ! in_array( $field['type'], [ 'radio', 'checkbox' ], true ) ) {
[514] Fix | Delete
continue;
[515] Fix | Delete
}
[516] Fix | Delete
[517] Fix | Delete
foreach ( $field['choices'] as $choice_id => $choice ) {
[518] Fix | Delete
if ( ( isset( $choice['value'] ) && '' !== trim( $choice['value'] ) ) || empty( $choice['image'] ) ) {
[519] Fix | Delete
continue;
[520] Fix | Delete
}
[521] Fix | Delete
[522] Fix | Delete
$form_data['fields'][ $field_key ]['choices'][ $choice_id ]['value'] = sprintf( /* translators: %d - choice number. */
[523] Fix | Delete
esc_html__( 'Choice %d', 'wpforms-lite' ),
[524] Fix | Delete
(int) $choice_id
[525] Fix | Delete
);
[526] Fix | Delete
}
[527] Fix | Delete
}
[528] Fix | Delete
[529] Fix | Delete
return $form_data;
[530] Fix | Delete
}
[531] Fix | Delete
[532] Fix | Delete
/**
[533] Fix | Delete
* Get the value, that is used to prefill via dynamic or fallback population.
[534] Fix | Delete
* Based on field data and current properties.
[535] Fix | Delete
* Normal choices section.
[536] Fix | Delete
*
[537] Fix | Delete
* @since 1.6.0
[538] Fix | Delete
*
[539] Fix | Delete
* @param string $get_value Value from a GET param, always a string, sanitized.
[540] Fix | Delete
* @param array $properties Field properties.
[541] Fix | Delete
* @param array $field Current field specific data.
[542] Fix | Delete
*
[543] Fix | Delete
* @return array Modified field properties.
[544] Fix | Delete
*/
[545] Fix | Delete
protected function get_field_populated_single_property_value_normal_choices( $get_value, $properties, $field ) {
[546] Fix | Delete
[547] Fix | Delete
$default_key = null;
[548] Fix | Delete
[549] Fix | Delete
// For fields that have normal choices we need to add extra logic.
[550] Fix | Delete
foreach ( $field['choices'] as $choice_key => $choice_arr ) {
[551] Fix | Delete
$choice_value_key = isset( $field['show_values'] ) ? 'value' : 'label';
[552] Fix | Delete
if (
[553] Fix | Delete
(
[554] Fix | Delete
isset( $choice_arr[ $choice_value_key ] ) &&
[555] Fix | Delete
strtoupper( sanitize_text_field( $choice_arr[ $choice_value_key ] ) ) === strtoupper( $get_value )
[556] Fix | Delete
) ||
[557] Fix | Delete
(
[558] Fix | Delete
empty( $choice_arr[ $choice_value_key ] ) &&
[559] Fix | Delete
$get_value === sprintf( /* translators: %d - choice number. */
[560] Fix | Delete
esc_html__( 'Choice %d', 'wpforms-lite' ),
[561] Fix | Delete
(int) $choice_key
[562] Fix | Delete
)
[563] Fix | Delete
)
[564] Fix | Delete
) {
[565] Fix | Delete
$default_key = $choice_key;
[566] Fix | Delete
// Stop iterating over choices.
[567] Fix | Delete
break;
[568] Fix | Delete
}
[569] Fix | Delete
}
[570] Fix | Delete
[571] Fix | Delete
// Redefine default choice only if population value has changed anything.
[572] Fix | Delete
if ( null !== $default_key ) {
[573] Fix | Delete
foreach ( $field['choices'] as $choice_key => $choice_arr ) {
[574] Fix | Delete
if ( $choice_key === $default_key ) {
[575] Fix | Delete
$properties['inputs'][ $choice_key ]['default'] = true;
[576] Fix | Delete
$properties['inputs'][ $choice_key ]['container']['class'][] = 'wpforms-selected';
[577] Fix | Delete
break;
[578] Fix | Delete
}
[579] Fix | Delete
}
[580] Fix | Delete
}
[581] Fix | Delete
[582] Fix | Delete
return $properties;
[583] Fix | Delete
}
[584] Fix | Delete
[585] Fix | Delete
/**
[586] Fix | Delete
* Whether current field can be populated dynamically.
[587] Fix | Delete
*
[588] Fix | Delete
* @since 1.5.0
[589] Fix | Delete
*
[590] Fix | Delete
* @param array $properties Field properties.
[591] Fix | Delete
* @param array $field Current field specific data.
[592] Fix | Delete
*
[593] Fix | Delete
* @return bool
[594] Fix | Delete
*/
[595] Fix | Delete
public function is_fallback_population_allowed( $properties, $field ) {
[596] Fix | Delete
[597] Fix | Delete
$allowed = true;
[598] Fix | Delete
[599] Fix | Delete
// Allow population on front-end only.
[600] Fix | Delete
if ( is_admin() ) {
[601] Fix | Delete
$allowed = false;
[602] Fix | Delete
}
[603] Fix | Delete
[604] Fix | Delete
/*
[605] Fix | Delete
* Commented out to allow partial fail for complex multi-inputs fields.
[606] Fix | Delete
* Example: name field with first/last format and being required, filled out only first.
[607] Fix | Delete
* On submit we will preserve those sub-inputs that are not empty and display an error for an empty.
[608] Fix | Delete
*/
[609] Fix | Delete
// Do not populate if there are errors for that field.
[610] Fix | Delete
/*
[611] Fix | Delete
$errors = wpforms()->get( 'process' )->errors;
[612] Fix | Delete
if ( ! empty( $errors[ $this->form_data['id'] ][ $field['id'] ] ) ) {
[613] Fix | Delete
$allowed = false;
[614] Fix | Delete
}
[615] Fix | Delete
*/
[616] Fix | Delete
[617] Fix | Delete
// Require form id being the same for submitted and currently rendered form.
[618] Fix | Delete
if (
[619] Fix | Delete
! empty( $_POST['wpforms']['id'] ) && // phpcs:ignore
[620] Fix | Delete
(int) $_POST['wpforms']['id'] !== (int) $this->form_data['id'] // phpcs:ignore
[621] Fix | Delete
) {
[622] Fix | Delete
$allowed = false;
[623] Fix | Delete
}
[624] Fix | Delete
[625] Fix | Delete
// Require $_POST of submitted field.
[626] Fix | Delete
if ( empty( $_POST['wpforms']['fields'] ) ) { // phpcs:ignore
[627] Fix | Delete
$allowed = false;
[628] Fix | Delete
}
[629] Fix | Delete
[630] Fix | Delete
// Require field (processed and rendered) being the same.
[631] Fix | Delete
if ( ! isset( $_POST['wpforms']['fields'][ $field['id'] ] ) ) { // phpcs:ignore
[632] Fix | Delete
$allowed = false;
[633] Fix | Delete
}
[634] Fix | Delete
[635] Fix | Delete
return apply_filters( 'wpforms_field_is_fallback_population_allowed', $allowed, $properties, $field );
[636] Fix | Delete
}
[637] Fix | Delete
[638] Fix | Delete
/**
[639] Fix | Delete
* Prefill the field value with a fallback value from form submission (in case of JS validation failed), that we get from $_POST.
[640] Fix | Delete
*
[641] Fix | Delete
* @since 1.5.0
[642] Fix | Delete
*
[643] Fix | Delete
* @param array $properties Field properties.
[644] Fix | Delete
* @param array $field Current field specific data.
[645] Fix | Delete
*
[646] Fix | Delete
* @return array Modified field properties.
[647] Fix | Delete
*/
[648] Fix | Delete
protected function field_prefill_value_property_fallback( $properties, $field ) {
[649] Fix | Delete
[650] Fix | Delete
if ( ! $this->is_fallback_population_allowed( $properties, $field ) ) {
[651] Fix | Delete
return $properties;
[652] Fix | Delete
}
[653] Fix | Delete
[654] Fix | Delete
if ( empty( $_POST['wpforms']['fields'] ) || ! is_array( $_POST['wpforms']['fields'] ) ) { // phpcs:ignore
[655] Fix | Delete
return $properties;
[656] Fix | Delete
}
[657] Fix | Delete
[658] Fix | Delete
// We got user submitted raw data (not processed, will be done later).
[659] Fix | Delete
$raw_value = $_POST['wpforms']['fields'][ $field['id'] ]; // phpcs:ignore
[660] Fix | Delete
$input = 'primary';
[661] Fix | Delete
[662] Fix | Delete
if ( ! empty( $raw_value ) ) {
[663] Fix | Delete
$this->field_prefill_remove_choices_defaults( $field, $properties );
[664] Fix | Delete
}
[665] Fix | Delete
[666] Fix | Delete
/*
[667] Fix | Delete
* For this particular field this value may be either array or a string.
[668] Fix | Delete
* In array - this is a complex field, like address.
[669] Fix | Delete
* The key in array will be a sub-input (address1, state), and its appropriate value.
[670] Fix | Delete
*/
[671] Fix | Delete
if ( is_array( $raw_value ) ) {
[672] Fix | Delete
foreach ( $raw_value as $input => $single_value ) {
[673] Fix | Delete
$properties = $this->get_field_populated_single_property_value( $single_value, sanitize_key( $input ), $properties, $field );
[674] Fix | Delete
}
[675] Fix | Delete
} else {
[676] Fix | Delete
$properties = $this->get_field_populated_single_property_value( $raw_value, sanitize_key( $input ), $properties, $field );
[677] Fix | Delete
}
[678] Fix | Delete
[679] Fix | Delete
return $properties;
[680] Fix | Delete
}
[681] Fix | Delete
[682] Fix | Delete
/**
[683] Fix | Delete
* Get field data for the field.
[684] Fix | Delete
*
[685] Fix | Delete
* @since 1.8.2
[686] Fix | Delete
*
[687] Fix | Delete
* @param array $field Current field.
[688] Fix | Delete
* @param array $form_data Form data and settings.
[689] Fix | Delete
*
[690] Fix | Delete
* @return array
[691] Fix | Delete
*/
[692] Fix | Delete
public function field_data( $field, $form_data ) {
[693] Fix | Delete
[694] Fix | Delete
// Remove field on frontend if it has no dynamic choices.
[695] Fix | Delete
if ( $this->is_dynamic_choices_empty( $field, $form_data ) ) {
[696] Fix | Delete
return [];
[697] Fix | Delete
}
[698] Fix | Delete
[699] Fix | Delete
return $field;
[700] Fix | Delete
}
[701] Fix | Delete
[702] Fix | Delete
/**
[703] Fix | Delete
* Create the button for the 'Add Fields' tab, inside the form editor.
[704] Fix | Delete
*
[705] Fix | Delete
* @since 1.0.0
[706] Fix | Delete
*
[707] Fix | Delete
* @param array $fields List of form fields with their data.
[708] Fix | Delete
*
[709] Fix | Delete
* @return array
[710] Fix | Delete
*/
[711] Fix | Delete
public function field_button( $fields ) {
[712] Fix | Delete
[713] Fix | Delete
// Add field information to fields array.
[714] Fix | Delete
$fields[ $this->group ]['fields'][] = [
[715] Fix | Delete
'order' => $this->order,
[716] Fix | Delete
'name' => $this->name,
[717] Fix | Delete
'type' => $this->type,
[718] Fix | Delete
'icon' => $this->icon,
[719] Fix | Delete
'keywords' => $this->keywords,
[720] Fix | Delete
];
[721] Fix | Delete
[722] Fix | Delete
// Wipe hands clean.
[723] Fix | Delete
return $fields;
[724] Fix | Delete
}
[725] Fix | Delete
[726] Fix | Delete
/**
[727] Fix | Delete
* Enhances template fields by adding keywords.
[728] Fix | Delete
*
[729] Fix | Delete
* @since 1.8.6
[730] Fix | Delete
*
[731] Fix | Delete
* @param array $template_fields List of template fields.
[732] Fix | Delete
*
[733] Fix | Delete
* @return array
[734] Fix | Delete
*/
[735] Fix | Delete
public function enhance_template_fields_with_keywords( array $template_fields ): array {
[736] Fix | Delete
[737] Fix | Delete
foreach ( $template_fields as $key => $field ) {
[738] Fix | Delete
if ( $field === $this->type ) {
[739] Fix | Delete
$template_fields[ $key ] = $this->name;
[740] Fix | Delete
[741] Fix | Delete
$this->add_keywords( $template_fields );
[742] Fix | Delete
}
[743] Fix | Delete
}
[744] Fix | Delete
[745] Fix | Delete
return array_unique( $template_fields );
[746] Fix | Delete
}
[747] Fix | Delete
[748] Fix | Delete
/**
[749] Fix | Delete
* Adds keywords to the provided fields.
[750] Fix | Delete
*
[751] Fix | Delete
* @since 1.8.6
[752] Fix | Delete
*
[753] Fix | Delete
* @param array $fields List of fields to which keywords will be added.
[754] Fix | Delete
*
[755] Fix | Delete
* @return void
[756] Fix | Delete
*/
[757] Fix | Delete
private function add_keywords( array &$fields ) {
[758] Fix | Delete
[759] Fix | Delete
if ( $this->keywords ) {
[760] Fix | Delete
$keywords_list = explode( ',', $this->keywords );
[761] Fix | Delete
[762] Fix | Delete
foreach ( $keywords_list as $keyword ) {
[763] Fix | Delete
$fields[] = trim( $keyword );
[764] Fix | Delete
}
[765] Fix | Delete
}
[766] Fix | Delete
}
[767] Fix | Delete
[768] Fix | Delete
/**
[769] Fix | Delete
* Create the field options panel. Used by subclasses.
[770] Fix | Delete
*
[771] Fix | Delete
* @since 1.0.0
[772] Fix | Delete
* @since 1.5.0 Converted to abstract method, as it's required for all fields.
[773] Fix | Delete
*
[774] Fix | Delete
* @param array $field Field data and settings.
[775] Fix | Delete
*/
[776] Fix | Delete
abstract public function field_options( $field );
[777] Fix | Delete
[778] Fix | Delete
/**
[779] Fix | Delete
* Create the field preview. Used by subclasses.
[780] Fix | Delete
*
[781] Fix | Delete
* @since 1.0.0
[782] Fix | Delete
* @since 1.5.0 Converted to abstract method, as it's required for all fields.
[783] Fix | Delete
*
[784] Fix | Delete
* @param array $field Field data and settings.
[785] Fix | Delete
*/
[786] Fix | Delete
abstract public function field_preview( $field );
[787] Fix | Delete
[788] Fix | Delete
/**
[789] Fix | Delete
* Helper function to create field option elements.
[790] Fix | Delete
*
[791] Fix | Delete
* Field option elements are pieces that help create a field option.
[792] Fix | Delete
* They are used to quickly build field options.
[793] Fix | Delete
*
[794] Fix | Delete
* @since 1.0.0
[795] Fix | Delete
*
[796] Fix | Delete
* @param string $option Field option to render.
[797] Fix | Delete
* @param array $field Field data and settings.
[798] Fix | Delete
* @param array $args Field preview arguments.
[799] Fix | Delete
* @param bool $echo Print or return the value. Print by default.
[800] Fix | Delete
*
[801] Fix | Delete
* @return mixed echo or return string
[802] Fix | Delete
*/
[803] Fix | Delete
public function field_element( $option, $field, $args = [], $echo = true ) {
[804] Fix | Delete
[805] Fix | Delete
$id = (int) $field['id'];
[806] Fix | Delete
$class = ! empty( $args['class'] ) ? wpforms_sanitize_classes( (array) $args['class'], true ) : '';
[807] Fix | Delete
$slug = ! empty( $args['slug'] ) ? sanitize_title( $args['slug'] ) : '';
[808] Fix | Delete
$attrs = '';
[809] Fix | Delete
$output = '';
[810] Fix | Delete
[811] Fix | Delete
if ( ! empty( $args['data'] ) ) {
[812] Fix | Delete
foreach ( $args['data'] as $arg_key => $val ) {
[813] Fix | Delete
if ( is_array( $val ) ) {
[814] Fix | Delete
$val = wp_json_encode( $val );
[815] Fix | Delete
}
[816] Fix | Delete
$attrs .= ' data-' . $arg_key . '=\'' . $val . '\'';
[817] Fix | Delete
}
[818] Fix | Delete
}
[819] Fix | Delete
if ( ! empty( $args['attrs'] ) ) {
[820] Fix | Delete
foreach ( $args['attrs'] as $arg_key => $val ) {
[821] Fix | Delete
if ( is_array( $val ) ) {
[822] Fix | Delete
$val = wp_json_encode( $val );
[823] Fix | Delete
}
[824] Fix | Delete
$attrs .= $arg_key . '=\'' . $val . '\'';
[825] Fix | Delete
}
[826] Fix | Delete
}
[827] Fix | Delete
[828] Fix | Delete
switch ( $option ) {
[829] Fix | Delete
// Row.
[830] Fix | Delete
case 'row':
[831] Fix | Delete
$output = sprintf(
[832] Fix | Delete
'<div class="wpforms-field-option-row wpforms-field-option-row-%s %s" id="wpforms-field-option-row-%d-%s" data-field-id="%s" %s>%s</div>',
[833] Fix | Delete
$slug,
[834] Fix | Delete
$class,
[835] Fix | Delete
$id,
[836] Fix | Delete
$slug,
[837] Fix | Delete
$id,
[838] Fix | Delete
$attrs,
[839] Fix | Delete
$args['content']
[840] Fix | Delete
);
[841] Fix | Delete
break;
[842] Fix | Delete
[843] Fix | Delete
// Label.
[844] Fix | Delete
case 'label':
[845] Fix | Delete
$class = ! empty( $class ) ? ' class="' . $class . '"' : '';
[846] Fix | Delete
$output = sprintf( '<label for="wpforms-field-option-%d-%s"%s>%s', $id, $slug, $class, esc_html( $args['value'] ) );
[847] Fix | Delete
[848] Fix | Delete
if ( isset( $args['tooltip'] ) && ! empty( $args['tooltip'] ) ) {
[849] Fix | Delete
$output .= sprintf( '<i class="fa fa-question-circle-o wpforms-help-tooltip" title="%s"></i>', esc_attr( $args['tooltip'] ) );
[850] Fix | Delete
}
[851] Fix | Delete
if ( isset( $args['after_tooltip'] ) && ! empty( $args['after_tooltip'] ) ) {
[852] Fix | Delete
$output .= $args['after_tooltip'];
[853] Fix | Delete
}
[854] Fix | Delete
$output .= '</label>';
[855] Fix | Delete
break;
[856] Fix | Delete
[857] Fix | Delete
// Text input.
[858] Fix | Delete
case 'text':
[859] Fix | Delete
$type = ! empty( $args['type'] ) ? esc_attr( $args['type'] ) : 'text';
[860] Fix | Delete
$placeholder = ! empty( $args['placeholder'] ) ? esc_attr( $args['placeholder'] ) : '';
[861] Fix | Delete
$before = ! empty( $args['before'] ) ? '<span class="before-input">' . esc_html( $args['before'] ) . '</span>' : '';
[862] Fix | Delete
$after = ! empty( $args['after'] ) ? '<span class="after-input sub-label">' . esc_html( $args['after'] ) . '</span>' : '';
[863] Fix | Delete
[864] Fix | Delete
if ( ! empty( $before ) ) {
[865] Fix | Delete
$class .= ' has-before';
[866] Fix | Delete
}
[867] Fix | Delete
[868] Fix | Delete
if ( ! empty( $after ) ) {
[869] Fix | Delete
$class .= ' has-after';
[870] Fix | Delete
}
[871] Fix | Delete
[872] Fix | Delete
$output = sprintf( '%s<input type="%s" class="%s" id="wpforms-field-option-%d-%s" name="fields[%d][%s]" value="%s" placeholder="%s" %s>%s', $before, $type, $class, $id, $slug, $id, $slug, esc_attr( $args['value'] ), $placeholder, $attrs, $after );
[873] Fix | Delete
break;
[874] Fix | Delete
[875] Fix | Delete
// Textarea.
[876] Fix | Delete
case 'textarea':
[877] Fix | Delete
$rows = ! empty( $args['rows'] ) ? (int) $args['rows'] : '3';
[878] Fix | Delete
$output = sprintf( '<textarea class="%s" id="wpforms-field-option-%d-%s" name="fields[%d][%s]" rows="%d" %s>%s</textarea>', $class, $id, $slug, $id, $slug, $rows, $attrs, $args['value'] );
[879] Fix | Delete
break;
[880] Fix | Delete
[881] Fix | Delete
// Checkbox.
[882] Fix | Delete
case 'checkbox':
[883] Fix | Delete
$checked = checked( '1', $args['value'], false );
[884] Fix | Delete
$output = sprintf( '<input type="checkbox" class="%s" id="wpforms-field-option-%d-%s" name="fields[%d][%s]" value="1" %s %s>', $class, $id, $slug, $id, $slug, $checked, $attrs );
[885] Fix | Delete
$output .= empty( $args['nodesc'] ) ? sprintf( '<label for="wpforms-field-option-%d-%s" class="inline">%s', $id, $slug, $args['desc'] ) : '';
[886] Fix | Delete
[887] Fix | Delete
if ( isset( $args['tooltip'] ) && ! empty( $args['tooltip'] ) ) {
[888] Fix | Delete
$output .= sprintf( '<i class="fa fa-question-circle-o wpforms-help-tooltip" title="%s"></i>', esc_attr( $args['tooltip'] ) );
[889] Fix | Delete
}
[890] Fix | Delete
$output .= empty( $args['nodesc'] ) ? '</label>' : '';
[891] Fix | Delete
break;
[892] Fix | Delete
[893] Fix | Delete
// Toggle.
[894] Fix | Delete
case 'toggle':
[895] Fix | Delete
$output = $this->field_element_toggle( $args, $id, $slug, $attrs, $class );
[896] Fix | Delete
break;
[897] Fix | Delete
[898] Fix | Delete
// Select.
[899] Fix | Delete
case 'select':
[900] Fix | Delete
$options = $args['options'];
[901] Fix | Delete
$value = isset( $args['value'] ) ? $args['value'] : '';
[902] Fix | Delete
$output = sprintf( '<select class="%s" id="wpforms-field-option-%d-%s" name="fields[%d][%s]" %s>', $class, $id, $slug, $id, $slug, $attrs );
[903] Fix | Delete
[904] Fix | Delete
foreach ( $options as $arg_key => $arg_option ) {
[905] Fix | Delete
$output .= sprintf( '<option value="%s" %s>%s</option>', esc_attr( $arg_key ), selected( $arg_key, $value, false ), $arg_option );
[906] Fix | Delete
}
[907] Fix | Delete
$output .= '</select>';
[908] Fix | Delete
break;
[909] Fix | Delete
[910] Fix | Delete
// Color.
[911] Fix | Delete
case 'color':
[912] Fix | Delete
$args['class'][] = 'wpforms-color-picker';
[913] Fix | Delete
[914] Fix | Delete
$output = $this->field_element( 'text', $field, $args, $echo );
[915] Fix | Delete
break;
[916] Fix | Delete
}
[917] Fix | Delete
[918] Fix | Delete
if ( ! $echo ) {
[919] Fix | Delete
return $output;
[920] Fix | Delete
}
[921] Fix | Delete
[922] Fix | Delete
// @todo Ideally, we should late-escape here. All data above seems to be escaped or trusted, but we should consider refactoring this method.
[923] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[924] Fix | Delete
echo $output;
[925] Fix | Delete
}
[926] Fix | Delete
[927] Fix | Delete
/**
[928] Fix | Delete
* Create field option toggle element.
[929] Fix | Delete
*
[930] Fix | Delete
* @since 1.6.8
[931] Fix | Delete
*
[932] Fix | Delete
* @param array $args Arguments.
[933] Fix | Delete
* @param integer $id Field ID.
[934] Fix | Delete
* @param string $slug Field slug.
[935] Fix | Delete
* @param string $attrs Attributes.
[936] Fix | Delete
* @param string $class Class.
[937] Fix | Delete
*
[938] Fix | Delete
* @return string
[939] Fix | Delete
*/
[940] Fix | Delete
private function field_element_toggle( $args, $id, $slug, $attrs, $class ) {
[941] Fix | Delete
[942] Fix | Delete
$input_id = sprintf(
[943] Fix | Delete
'wpforms-field-option-%d-%s',
[944] Fix | Delete
esc_attr( $id ),
[945] Fix | Delete
esc_attr( $slug )
[946] Fix | Delete
);
[947] Fix | Delete
[948] Fix | Delete
$field_name = sprintf(
[949] Fix | Delete
'fields[%d][%s]',
[950] Fix | Delete
esc_attr( $id ),
[951] Fix | Delete
esc_attr( $slug )
[952] Fix | Delete
);
[953] Fix | Delete
[954] Fix | Delete
$label = ! empty( $args['desc'] ) ? $args['desc'] : '';
[955] Fix | Delete
$value = ! empty( $args['value'] ) ? $args['value'] : '';
[956] Fix | Delete
[957] Fix | Delete
// Compatibility with the `checkbox` element.
[958] Fix | Delete
$args['label-hide'] = ! empty( $args['nodesc'] ) ? $args['nodesc'] : false;
[959] Fix | Delete
$args['input-class'] = $class;
[960] Fix | Delete
[961] Fix | Delete
return wpforms_panel_field_toggle_control( $args, $input_id, $field_name, $label, $value, $attrs );
[962] Fix | Delete
}
[963] Fix | Delete
[964] Fix | Delete
/**
[965] Fix | Delete
* Helper function to create common field options that are used frequently.
[966] Fix | Delete
*
[967] Fix | Delete
* @since 1.0.0
[968] Fix | Delete
*
[969] Fix | Delete
* @param string $option Field option to render.
[970] Fix | Delete
* @param array $field Field data and settings.
[971] Fix | Delete
* @param array $args Field preview arguments.
[972] Fix | Delete
* @param bool $echo Print or return the value. Print by default.
[973] Fix | Delete
*
[974] Fix | Delete
* @return mixed echo or return string
[975] Fix | Delete
*/
[976] Fix | Delete
public function field_option( $option, $field, $args = [], $echo = true ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded, Generic.Metrics.NestingLevel.MaxExceeded
[977] Fix | Delete
[978] Fix | Delete
$output = '';
[979] Fix | Delete
$markup = '';
[980] Fix | Delete
[981] Fix | Delete
switch ( $option ) {
[982] Fix | Delete
/**
[983] Fix | Delete
* Basic Fields.
[984] Fix | Delete
*/
[985] Fix | Delete
[986] Fix | Delete
/*
[987] Fix | Delete
* Basic Options markup.
[988] Fix | Delete
*/
[989] Fix | Delete
case 'basic-options':
[990] Fix | Delete
$markup = ! empty( $args['markup'] ) ? $args['markup'] : 'open';
[991] Fix | Delete
$class = ! empty( $args['class'] ) ? esc_html( $args['class'] ) : '';
[992] Fix | Delete
[993] Fix | Delete
if ( $markup === 'open' ) {
[994] Fix | Delete
$output = sprintf(
[995] Fix | Delete
'<div class="wpforms-field-option-field-title">%3$s <span>(ID #%1$d)</span></div>
[996] Fix | Delete
<div class="wpforms-field-option-group wpforms-field-option-group-basic active" id="wpforms-field-option-basic-%1$s">
[997] Fix | Delete
<a href="#" class="wpforms-field-option-group-toggle">%2$s</a>
[998] Fix | Delete
<div class="wpforms-field-option-group-inner %4$s">
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function