$properties['container']['class'][] = ' wpforms-payment-quantities-enabled'; } return $properties; } /** * Get the value, that is used to prefill via dynamic or fallback population. * Based on field data and current properties. * * @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 from Fallback only values (choice ID). * As payment-dropdown field doesn't support 'show_values' option - * we should transform value 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 choice ID, so shortcut for Dynamic when we have a label there. if ( ! is_numeric( $raw_value ) ) { return parent::get_field_populated_single_property_value( $raw_value, $input, $properties, $field ); } if ( ! empty( $field['choices'][ $raw_value ]['label'] ) && ! empty( $field['choices'][ $raw_value ]['value'] ) ) { return parent::get_field_populated_single_property_value( $field['choices'][ $raw_value ]['label'], $input, $properties, $field ); } return $properties; } /** * 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 ); // Quantity. $this->field_option( 'quantity', $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' ] ); // Style. $lbl = $this->field_element( 'label', $field, [ 'slug' => 'style', 'value' => esc_html__( 'Style', 'wpforms-lite' ), 'tooltip' => esc_html__( 'Classic style is the default one generated by your browser. Modern has a fresh look and displays all selected options in a single row.', 'wpforms-lite' ), ], false ); $fld = $this->field_element( 'select', $field, [ 'slug' => 'style', 'value' => ! empty( $field['style'] ) ? $field['style'] : self::STYLE_CLASSIC, 'options' => [ self::STYLE_CLASSIC => esc_html__( 'Classic', 'wpforms-lite' ), self::STYLE_MODERN => esc_html__( 'Modern', 'wpforms-lite' ), ], ], false ); $this->field_element( 'row', $field, [ 'slug' => 'style', 'content' => $lbl . $fld, ] ); // Size. $this->field_option( 'size', $field ); // Placeholder. $this->field_option( 'placeholder', $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 ); // Prepare arguments. $args['modern'] = false; if ( ! empty( $field['style'] ) && $field['style'] === self::STYLE_MODERN ) { $args['modern'] = true; $args['class'] = 'choicesjs-select'; } // Choices. $this->field_preview_option( 'choices', $field, $args ); // Quantity. $this->field_preview_option( 'quantity', $field ); // Description. $this->field_preview_option( 'description', $field ); } /** * Field display on the form front-end. * * @since 1.8.2 * * @param array $field Field data and settings. * @param array $deprecated Deprecated array of field attributes. * @param array $form_data Form data and settings. */ public function field_display( $field, $deprecated, $form_data ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded $container = $field['properties']['input_container']; $field_placeholder = ! empty( $field['placeholder'] ) ? $field['placeholder'] : ''; $is_modern = ! empty( $field['style'] ) && $field['style'] === self::STYLE_MODERN; $choices = $field['properties']['inputs']; if ( ! empty( $field['required'] ) ) { $container['attr']['required'] = 'required'; } // Add a class for Choices.js initialization. if ( $is_modern ) { $container['class'][] = 'choicesjs-select'; // Add a size-class to data attribute - it is used when Choices.js is initialized. if ( ! empty( $field['size'] ) ) { $container['data']['size-class'] = 'wpforms-field-row wpforms-field-' . sanitize_html_class( $field['size'] ); } $container['data']['search-enabled'] = $this->is_choicesjs_search_enabled( count( $choices ) ); } $has_default = false; // Check to see if any of the options were selected by default. foreach ( $choices as $choice ) { if ( ! empty( $choice['default'] ) ) { $has_default = true; break; } } // Fake placeholder for Modern style. if ( $is_modern && empty( $field_placeholder ) ) { $first_choices = reset( $choices ); $field_placeholder = $first_choices['label']['text']; $field_placeholder .= ! empty( $field['show_price_after_labels'] ) && isset( $first_choices['attr']['value'] ) ? ' - ' . wpforms_format_amount( wpforms_sanitize_amount( $first_choices['attr']['value'] ), true ) : ''; } // Preselect default if no other choices were marked as default. printf( ''; $this->display_quantity_dropdown( $field ); } /** * Validate field on form submit. * * @since 1.8.2 * * @param int $field_id Field ID. * @param string $field_submit Submitted field value (raw data). * @param array $form_data Form data and settings. */ public function validate( $field_id, $field_submit, $form_data ) { // Basic required check - If field is marked as required, check for entry data. if ( ! empty( $form_data['fields'][ $field_id ]['required'] ) && empty( $field_submit ) ) { wpforms()->obj( 'process' )->errors[ $form_data['id'] ][ $field_id ] = wpforms_get_required_label(); } // Validate that the option selected is real. if ( ! empty( $field_submit ) && empty( $form_data['fields'][ $field_id ]['choices'][ $field_submit ] ) ) { wpforms()->obj( 'process' )->errors[ $form_data['id'] ][ $field_id ] = esc_html__( 'Invalid payment option', 'wpforms-lite' ); } } /** * Format and sanitize field. * * @since 1.8.2 * * @param int $field_id Field ID. * @param string $field_submit Submitted field value (selected option). * @param array $form_data Form data and settings. */ public function format( $field_id, $field_submit, $form_data ) { $choice_label = ''; $field = $form_data['fields'][ $field_id ]; $name = ! empty( $field['label'] ) ? sanitize_text_field( $field['label'] ) : ''; // Fetch the amount. if ( ! empty( $field['choices'][ $field_submit ]['value'] ) ) { $amount = wpforms_sanitize_amount( $field['choices'][ $field_submit ]['value'] ); } else { $amount = 0; } $value = wpforms_format_amount( $amount, true ); if ( empty( $field_submit ) ) { $value = ''; } elseif ( ! empty( $field['choices'][ $field_submit ]['label'] ) ) { $choice_label = sanitize_text_field( $field['choices'][ $field_submit ]['label'] ); $value = $choice_label . ' - ' . $value; } $field_data = [ 'name' => $name, 'value' => $value, 'value_choice' => $choice_label, 'value_raw' => sanitize_text_field( $field_submit ), 'amount' => wpforms_format_amount( $amount ), 'amount_raw' => $amount, 'currency' => wpforms_get_currency(), 'id' => absint( $field_id ), 'type' => sanitize_key( $this->type ), ]; if ( $this->is_payment_quantities_enabled( $field ) ) { $field_data['quantity'] = $this->get_submitted_field_quantity( $field, $form_data ); } wpforms()->obj( 'process' )->fields[ $field_id ] = $field_data; } /** * Form frontend CSS enqueues. * * @since 1.8.2 * * @param array $forms Forms on the current page. */ public function enqueue_frontend_css( $forms ) { $has_modern_select = false; foreach ( $forms as $form ) { if ( $this->is_field_style( $form, self::STYLE_MODERN ) ) { $has_modern_select = true; break; } } if ( $has_modern_select || wpforms()->obj( 'frontend' )->assets_global() ) { $min = wpforms_get_min_suffix(); wp_enqueue_style( 'wpforms-choicesjs', WPFORMS_PLUGIN_URL . "assets/css/choices{$min}.css", [], '10.2.0' ); } } /** * Form frontend JS enqueues. * * @since 1.8.2 * * @param array $forms Forms on the current page. */ public function enqueue_frontend_js( $forms ) { $has_modern_select = false; foreach ( $forms as $form ) { if ( $this->is_field_style( $form, self::STYLE_MODERN ) ) { $has_modern_select = true; break; } } if ( $has_modern_select || wpforms()->obj( 'frontend' )->assets_global() ) { $this->enqueue_choicesjs_once( $forms ); } } /** * Whether the provided form has a dropdown field with a specified style. * * @since 1.8.2 * * @param array $form Form data. * @param string $style Desired field style. * * @return bool */ protected function is_field_style( $form, $style ) { $is_field_style = false; if ( empty( $form['fields'] ) ) { return $is_field_style; } foreach ( (array) $form['fields'] as $field ) { if ( ! empty( $field['type'] ) && $field['type'] === $this->type && ! empty( $field['style'] ) && sanitize_key( $style ) === $field['style'] ) { $is_field_style = true; break; } } return $is_field_style; } /** * Get field name for an ajax error message. * * @since 1.8.2 * * @param string|mixed $name Field name for error triggered. * @param array $field Field settings. * @param array $props List of properties. * @param string|string[] $error Error message. * * @return string * @noinspection PhpMissingReturnTypeInspection * @noinspection ReturnTypeCanBeDeclaredInspection */ public function ajax_error_field_name( $name, $field, $props, $error ) { $name = (string) $name; if ( ! isset( $field['type'] ) || $field['type'] !== $this->type ) { return $name; } return $props['input_container']['attr']['name'] ?? ''; } } data as $form_id => $honeypot_field_id ) { $ids[] = sprintf( '#wpforms-%1$d-field_%2$d-container', $form_id, $honeypot_field_id ); } if ( ! $ids ) { return; } $styles = sprintf( '%1$s { position: absolute !important; overflow: hidden !important; display: inline !important; height: 1px !important; width: 1px !important; z-index: -1000 !important; padding: 0 !important; } %1$s input { visibility: hidden; } #wpforms-conversational-form-page %1$s label { counter-increment: none; }', esc_attr( implode( ',', $ids ) ) ); // There must be no empty lines inside the script. Otherwise, wpautop adds

tags which break script execution. printf( "", esc_js( $styles ) ); } /** * Get honeypot field label. * * @since 1.9.0 * * @param array $form_data Form data. */ private function get_honeypot_label( array $form_data ): string { $labels = []; foreach ( $form_data['fields'] ?? [] as $field ) { if ( ! empty( $field['label'] ) ) { $labels[] = $field['label']; } } $words = explode( ' ', implode( ' ', $labels ) ); $count_words = count( $words ); $label_keys = (array) array_rand( $words, min( $count_words, 3 ) ); shuffle( $label_keys ); $label_words = array_map( static function ( $key ) use ( $words ) { return $words[ $key ]; }, $label_keys ); return implode( ' ', $label_words ); } /** * Add strings to the frontend. * * @since 1.9.0 * * @param array|mixed $strings Frontend strings. * * @return array Frontend strings. */ public function add_frontend_strings( $strings ): array { $strings = (array) $strings; // Store the honeypot field ID for validation and adding inline styles. $strings['hn_data'] = $this->forms_data; return $strings; } /** * Validate whether the modern Anti-Spam is enabled. * * @since 1.9.0 * * @param array $form_data Form data. * @param array $fields Fields. * @param array $entry Form submission raw data ($_POST). * * @return bool True if the entry is valid, false otherwise. * @noinspection PhpUnusedParameterInspection */ public function validate( array $form_data, array $fields, array &$entry ): bool { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh // Bail out if the modern Anti-Spam is not enabled. if ( ! $this->is_honeypot_enabled( $form_data ) ) { return true; } $honeypot_fields = array_diff_key( $entry['fields'], $form_data['fields'] ); $is_valid = true; // Compatibility with the WPML plugin (WPFML addon). // In case the form contains an Entry Preview field, they add an extra field with ID 0 to the entry. if ( isset( $entry['fields'][0] ) && defined( 'WPML_WP_FORMS_VERSION' ) && wpforms_has_field_type( 'entry-preview', $form_data ) ) { unset( $honeypot_fields[0] ); } foreach ( $honeypot_fields as $key => $honeypot_field ) { // Remove the honeypot field from the entry. unset( $entry['fields'][ $key ] ); // If the honeypot field is not empty, the entry is invalid. if ( ! empty( $honeypot_field ) ) { $is_valid = false; } } return $is_valid; } /** * Check if the modern Anti-Spam is enabled. * * @since 1.9.0 * * @param array $form_data Form data. * * @return bool True if the modern Anti-Spam is enabled, false otherwise. */ private function is_honeypot_enabled( array $form_data ): bool { static $is_enabled; if ( isset( $is_enabled ) ) { return $is_enabled; } /** * Filters whether the modern Anti-Spam is enabled. * * @since 1.9.0 * * @param bool $is_enabled True if the modern Anti-Spam is enabled, false otherwise. */ $is_enabled = (bool) apply_filters( 'wpforms_forms_anti_spam_v3_is_honeypot_enabled', ! empty( $form_data['settings']['antispam_v3'] ) ); return $is_enabled; } /** * Get the honeypot field ID. * * @since 1.9.0 * * @param array $form_data Form data. * * @return int Honeypot field ID. */ private function get_honeypot_field_id( array $form_data ): int { $max_key = max( array_keys( $form_data['fields'] ) ); // Find the first available field ID. for ( $i = 1; $i <= $max_key; $i++ ) { if ( ! isset( $form_data['fields'][ $i ] ) ) { return $i; } } // If no available field ID found, use the max ID + 1. return $max_key + 1; } /** * Update the form data on the builder settings panel. * * @since 1.9.0 * * @param array|bool $form_data Form data. * * @return array|bool */ public function init_builder_settings_form_data( $form_data ) { if ( ! $form_data ) { return $form_data; } // Update default time limit duration for the existing form. if ( empty( $form_data['settings']['anti_spam']['time_limit']['enable'] ) ) { $form_data['settings']['anti_spam']['time_limit']['duration'] = '2'; } return $form_data; } /** * Update the template form data. Set the modern Anti-Spam setting. * * @since 1.9.0 * * @param array|mixed $form_data Form data. * * @return array */ public function update_template_form_data( $form_data ): array { $form_data = (array) $form_data; // Unset the old Anti-Spam setting. unset( $form_data['settings']['antispam'] ); // Enable the modern Anti-Spam setting. $form_data['settings']['antispam_v3'] = $form_data['settings']['antispam_v3'] ?? '1'; $form_data['settings']['anti_spam'] = $form_data['settings']['anti_spam'] ?? []; // Enable the time limit setting. $form_data['settings']['anti_spam']['time_limit'] = [ 'enable' => '1', 'duration' => '2', ]; return $form_data; } } $properties['container']['class'][] = ' wpforms-payment-quantities-enabled'; } return $properties; } /** * Get the value, that is used to prefill via dynamic or fallback population. * Based on field data and current properties. * * @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 from Fallback only values (choice ID). * As payment-dropdown field doesn't support 'show_values' option - * we should transform value 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 choice ID, so shortcut for Dynamic when we have a label there. if ( ! is_numeric( $raw_value ) ) { return parent::get_field_populated_single_property_value( $raw_value, $input, $properties, $field ); } if ( ! empty( $field['choices'][ $raw_value ]['label'] ) && ! empty( $field['choices'][ $raw_value ]['value'] ) ) { return parent::get_field_populated_single_property_value( $field['choices'][ $raw_value ]['label'], $input, $properties, $field ); } return $properties; } /** * 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 ); // Quantity. $this->field_option( 'quantity', $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' ] ); // Style. $lbl = $this->field_element( 'label', $field, [ 'slug' => 'style', 'value' => esc_html__( 'Style', 'wpforms-lite' ), 'tooltip' => esc_html__( 'Classic style is the default one generated by your browser. Modern has a fresh look and displays all selected options in a single row.', 'wpforms-lite' ), ], false ); $fld = $this->field_element( 'select', $field, [ 'slug' => 'style', 'value' => ! empty( $field['style'] ) ? $field['style'] : self::STYLE_CLASSIC, 'options' => [ self::STYLE_CLASSIC => esc_html__( 'Classic', 'wpforms-lite' ), self::STYLE_MODERN => esc_html__( 'Modern', 'wpforms-lite' ), ], ], false ); $this->field_element( 'row', $field, [ 'slug' => 'style', 'content' => $lbl . $fld, ] ); // Size. $this->field_option( 'size', $field ); // Placeholder. $this->field_option( 'placeholder', $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 ); // Prepare arguments. $args['modern'] = false; if ( ! empty( $field['style'] ) && $field['style'] === self::STYLE_MODERN ) { $args['modern'] = true; $args['class'] = 'choicesjs-select'; } // Choices. $this->field_preview_option( 'choices', $field, $args ); // Quantity. $this->field_preview_option( 'quantity', $field ); // Description. $this->field_preview_option( 'description', $field ); } /** * Field display on the form front-end. * * @since 1.8.2 * * @param array $field Field data and settings. * @param array $deprecated Deprecated array of field attributes. * @param array $form_data Form data and settings. */ public function field_display( $field, $deprecated, $form_data ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded $container = $field['properties']['input_container']; $field_placeholder = ! empty( $field['placeholder'] ) ? $field['placeholder'] : ''; $is_modern = ! empty( $field['style'] ) && $field['style'] === self::STYLE_MODERN; $choices = $field['properties']['inputs']; if ( ! empty( $field['required'] ) ) { $container['attr']['required'] = 'required'; } // Add a class for Choices.js initialization. if ( $is_modern ) { $container['class'][] = 'choicesjs-select'; // Add a size-class to data attribute - it is used when Choices.js is initialized. if ( ! empty( $field['size'] ) ) { $container['data']['size-class'] = 'wpforms-field-row wpforms-field-' . sanitize_html_class( $field['size'] ); } $container['data']['search-enabled'] = $this->is_choicesjs_search_enabled( count( $choices ) ); } $has_default = false; // Check to see if any of the options were selected by default. foreach ( $choices as $choice ) { if ( ! empty( $choice['default'] ) ) { $has_default = true; break; } } // Fake placeholder for Modern style. if ( $is_modern && empty( $field_placeholder ) ) { $first_choices = reset( $choices ); $field_placeholder = $first_choices['label']['text']; $field_placeholder .= ! empty( $field['show_price_after_labels'] ) && isset( $first_choices['attr']['value'] ) ? ' - ' . wpforms_format_amount( wpforms_sanitize_amount( $first_choices['attr']['value'] ), true ) : ''; } // Preselect default if no other choices were marked as default. printf( ''; $this->display_quantity_dropdown( $field ); } /** * Validate field on form submit. * * @since 1.8.2 * * @param int $field_id Field ID. * @param string $field_submit Submitted field value (raw data). * @param array $form_data Form data and settings. */ public function validate( $field_id, $field_submit, $form_data ) { // Basic required check - If field is marked as required, check for entry data. if ( ! empty( $form_data['fields'][ $field_id ]['required'] ) && empty( $field_submit ) ) { wpforms()->obj( 'process' )->errors[ $form_data['id'] ][ $field_id ] = wpforms_get_required_label(); } // Validate that the option selected is real. if ( ! empty( $field_submit ) && empty( $form_data['fields'][ $field_id ]['choices'][ $field_submit ] ) ) { wpforms()->obj( 'process' )->errors[ $form_data['id'] ][ $field_id ] = esc_html__( 'Invalid payment option', 'wpforms-lite' ); } } /** * Format and sanitize field. * * @since 1.8.2 * * @param int $field_id Field ID. * @param string $field_submit Submitted field value (selected option). * @param array $form_data Form data and settings. */ public function format( $field_id, $field_submit, $form_data ) { $choice_label = ''; $field = $form_data['fields'][ $field_id ]; $name = ! empty( $field['label'] ) ? sanitize_text_field( $field['label'] ) : ''; // Fetch the amount. if ( ! empty( $field['choices'][ $field_submit ]['value'] ) ) { $amount = wpforms_sanitize_amount( $field['choices'][ $field_submit ]['value'] ); } else { $amount = 0; } $value = wpforms_format_amount( $amount, true ); if ( empty( $field_submit ) ) { $value = ''; } elseif ( ! empty( $field['choices'][ $field_submit ]['label'] ) ) { $choice_label = sanitize_text_field( $field['choices'][ $field_submit ]['label'] ); $value = $choice_label . ' - ' . $value; } $field_data = [ 'name' => $name, 'value' => $value, 'value_choice' => $choice_label, 'value_raw' => sanitize_text_field( $field_submit ), 'amount' => wpforms_format_amount( $amount ), 'amount_raw' => $amount, 'currency' => wpforms_get_currency(), 'id' => absint( $field_id ), 'type' => sanitize_key( $this->type ), ]; if ( $this->is_payment_quantities_enabled( $field ) ) { $field_data['quantity'] = $this->get_submitted_field_quantity( $field, $form_data ); } wpforms()->obj( 'process' )->fields[ $field_id ] = $field_data; } /** * Form frontend CSS enqueues. * * @since 1.8.2 * * @param array $forms Forms on the current page. */ public function enqueue_frontend_css( $forms ) { $has_modern_select = false; foreach ( $forms as $form ) { if ( $this->is_field_style( $form, self::STYLE_MODERN ) ) { $has_modern_select = true; break; } } if ( $has_modern_select || wpforms()->obj( 'frontend' )->assets_global() ) { $min = wpforms_get_min_suffix(); wp_enqueue_style( 'wpforms-choicesjs', WPFORMS_PLUGIN_URL . "assets/css/choices{$min}.css", [], '10.2.0' ); } } /** * Form frontend JS enqueues. * * @since 1.8.2 * * @param array $forms Forms on the current page. */ public function enqueue_frontend_js( $forms ) { $has_modern_select = false; foreach ( $forms as $form ) { if ( $this->is_field_style( $form, self::STYLE_MODERN ) ) { $has_modern_select = true; break; } } if ( $has_modern_select || wpforms()->obj( 'frontend' )->assets_global() ) { $this->enqueue_choicesjs_once( $forms ); } } /** * Whether the provided form has a dropdown field with a specified style. * * @since 1.8.2 * * @param array $form Form data. * @param string $style Desired field style. * * @return bool */ protected function is_field_style( $form, $style ) { $is_field_style = false; if ( empty( $form['fields'] ) ) { return $is_field_style; } foreach ( (array) $form['fields'] as $field ) { if ( ! empty( $field['type'] ) && $field['type'] === $this->type && ! empty( $field['style'] ) && sanitize_key( $style ) === $field['style'] ) { $is_field_style = true; break; } } return $is_field_style; } /** * Get field name for an ajax error message. * * @since 1.8.2 * * @param string|mixed $name Field name for error triggered. * @param array $field Field settings. * @param array $props List of properties. * @param string|string[] $error Error message. * * @return string * @noinspection PhpMissingReturnTypeInspection * @noinspection ReturnTypeCanBeDeclaredInspection */ public function ajax_error_field_name( $name, $field, $props, $error ) { $name = (string) $name; if ( ! isset( $field['type'] ) || $field['type'] !== $this->type ) { return $name; } return $props['input_container']['attr']['name'] ?? ''; } } {"version":"1.0","provider_name":"London Planner","provider_url":"https:\/\/londonplanner.com","author_name":"Chris Johnson","author_url":"https:\/\/londonplanner.com\/author\/chrisjohnson\/","title":"13 things to do at The O2 in London - London Planner - Feature","type":"rich","width":600,"height":338,"html":"

13 things to do at The O2 in London<\/a><\/blockquote>