'text', 'name' => '', 'value' => '', 'label' => '', 'checkbox_label' => '', 'checkbox_value' => 'yes', 'description' => '', 'placeholder' => '', 'maxlength' => false, 'required' => false, 'autocomplete' => false, 'id' => '', 'default_class' => true, 'class' => [], 'td_class' => [], 'label_class' => [], 'input_class' => [], 'field_class' => [], 'return' => false, 'options' => [], 'show_fields' => [], 'only_hide_fields' => [], 'custom_attributes' => [], 'validate' => [], 'default' => '', 'autofocus' => '', 'priority' => '', 'after_field_text' => '', 'show_frontend_fields' => false, 'radio_single_line' => false, 'default_image' => '', 'show_condition' => true, 'td_colspan' => '', ]; $args = wp_parse_args( $args, $defaults ); if ( ! $args[ 'show_condition' ] ) { return; } $value = $args[ 'value' ]; if ( ! empty( $args[ 'after_field_text' ] ) ) { $args[ 'after_field_text' ] = ' ' . $args[ 'after_field_text' ]; } if ( ! empty( $args[ 'name' ] ) ) { $name = $args[ 'name' ]; } else { $name = '_' . str_replace( '-', '_', $args[ 'id' ] ); } if ( empty( $args[ 'checkbox_label' ] ) ) { $args[ 'checkbox_label' ] = $args[ 'label' ]; } if ( empty( $args[ 'id' ] ) ) { $args[ 'id' ] = str_replace( [ '[', ']', '_' ], [ '-', '', '-' ], $name ); $args[ 'id' ] = trim( $args[ 'id' ], '-' ); } $args = apply_filters( 'ddfw_form_field_args', $args, $name, $value ); if ( is_string( $args['class'] ) ) { $args['class'] = [ $args['class'] ]; } if ( is_string( $args['td_class'] ) ) { $args['td_class'] = [ $args['td_class'] ]; } if ( $args['required'] ) { $args['class'][] = 'validate-required'; // Marks the input itself, without the browser's own validation ( a required field hidden // by a toggle would block the form ), so scripts such as the date picker can tell. $args['custom_attributes']['data-required'] = 'true'; $required = ' *'; } else { $required = ''; } if ( is_string( $args['label_class'] ) ) { $args['label_class'] = [ $args['label_class'] ]; } if ( is_null( $value ) ) { $value = $args['default']; } $custom_attributes = []; $args['custom_attributes'] = array_filter( (array) $args['custom_attributes'], 'strlen' ); if ( $args['maxlength'] ) { $args['custom_attributes']['maxlength'] = absint( $args['maxlength'] ); } if ( ! empty( $args['autocomplete'] ) ) { $args['custom_attributes']['autocomplete'] = $args['autocomplete']; } if ( true === $args['autofocus'] ) { $args['custom_attributes']['autofocus'] = 'autofocus'; } if ( $args['description'] && $args['id'] ) { $args['custom_attributes']['aria-describedby'] = $args['id'] . '-description'; } if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) ) { foreach ( $args['custom_attributes'] as $attribute => $attribute_value ) { $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; } } if ( ! empty( $args['validate'] ) ) { foreach ( $args['validate'] as $validate ) { $args['class'][] = 'validate-' . $validate; } } $field = ''; $label_id = $args['id']; $sort = $args['priority'] ? $args['priority'] : ''; $is_admin = $args['show_frontend_fields'] ? false : is_admin(); if ( ! empty( $args['show_adminend_fields'] ) && $args['show_adminend_fields'] ) { $is_admin = true; } if ( $is_admin ) { $field_container = '
%1$s
'; } $default_input_class = $is_admin ? 'regular-text' : 'form-control woocommerce-Input woocommerce-Input--text input-text'; switch ( $args['type'] ) { case 'country': ob_start(); $countries = 'shipping_country' === $name ? WC()->countries->get_shipping_countries() : WC()->countries->get_allowed_countries(); if ( 1 === count( $countries ) ) { ?> class="country_to_state" readonly="readonly" /> data-input-classes=""/> /> /> $option_text ) { if ( ! $args['radio_single_line'] ) { ?>id="" data-show-fields='' data-only-hide-fields='' />
true, // Choose if you want to use wpautop. 'media_buttons' => true, // Choose if showing media button(s). 'textarea_name' => $name, // Set the textarea name to something different, square brackets [] can be used here. 'textarea_rows' => 10, // Set the number of rows. 'tabindex' => '', 'editor_css' => '', // Extra CSS styles to include in the editor iframe. 'editor_class' => '', // Add extra class(es) to the editor textarea. 'teeny' => false, // Output the minimal editor config used in Press This. 'dfw' => false, // Replace the default fullscreen with DFW (needs specific DOM elements and css). 'quicktags' => true, // Load Quicktags, can be used to pass settings directly to Quicktags using an array(). 'tinymce' => [ 'content_css' => '' ], ] ); $field .= '%%DDFW_EDITOR_FIELD%%'; break; case 'image': ob_start(); $image_src = wp_get_attachment_image_src( $value, 'thumbnail' ); $image_url = ! empty( $image_src ) ? $image_src[0] : ( $args['default_image'] ? $args['default_image'] : '' ); ?>>
> '; } $field = sprintf( $field_container, $field_html ); } $field = apply_filters( 'ddfw_form_field_' . $args[ 'type' ], $field, $name, $args, $value ); $field = apply_filters( 'ddfw_form_field', $field, $name, $args, $value ); if ( 'editor' === $args[ 'type' ] ) { // The surrounding wrapper went through the ddfw_form_field filters, so // it is escaped with wp_kses() on output. The editor itself is rendered // straight from wp_editor() (core escapes its own markup, which wp_kses // would otherwise strip), so no filtered/untrusted string is echoed. $parts = explode( '%%DDFW_EDITOR_FIELD%%', $field, 2 ); if ( $args[ 'return' ] ) { ob_start(); wp_editor( $value, $args[ 'id' ], $editor_args ); $editor_html = ob_get_clean(); return wp_kses( $parts[0], ddfw_kses_allowed_form_html() ) . $editor_html . ( isset( $parts[1] ) ? wp_kses( $parts[1], ddfw_kses_allowed_form_html() ) : '' ); } echo wp_kses( $parts[0], ddfw_kses_allowed_form_html() ); wp_editor( $value, $args[ 'id' ], $editor_args ); if ( isset( $parts[1] ) ) { echo wp_kses( $parts[1], ddfw_kses_allowed_form_html() ); } return; } if ( $args[ 'return' ] ) { return $field; } echo wp_kses( $field, ddfw_kses_allowed_form_html() ); } } }