| @@ -7,9 +7,19 @@ | ||
| 7 | 7 | * Show the radio field on the front-end. |
| 8 | 8 | * Extra line breaks show as space on the front-end when |
| 9 | 9 | * the form is double filtered and not minimized. |
| 10 | 10 | * |
| 11 | + * @var array $field | |
| 12 | + * @var string $field_name | |
| 13 | + * @var bool $read_only | |
| 14 | + * @var string $html_id | |
| 15 | + * @var array|null $args | |
| 16 | + * | |
| 11 | 17 | * @phpcs:disable Generic.WhiteSpace.ScopeIndent |
| 18 | + * | |
| 19 | + * @since 6.30 Added `$hide_label`. | |
| 20 | + * | |
| 21 | + * @var bool $hide_label | |
| 12 | 22 | */ |
| 13 | 23 | |
| 14 | 24 | if ( isset( $field['post_field'] ) && $field['post_field'] === 'post_category' ) { |
| 15 | 25 | $type = $field['type']; |
| @@ -14,13 +24,21 @@ | ||
| 14 | 24 | if ( isset( $field['post_field'] ) && $field['post_field'] === 'post_category' ) { |
| 15 | 25 | $type = $field['type']; |
| 16 | 26 | do_action( 'frm_after_checkbox', compact( 'field', 'field_name', 'type' ) ); |
| 17 | 27 | } elseif ( is_array( $field['options'] ) ) { |
| 28 | + if ( FrmFieldsHelper::should_skip_rendering_choices_for_field( $field ) ) { | |
| 29 | + return; | |
| 30 | + } | |
| 31 | + | |
| 18 | 32 | foreach ( $field['options'] as $opt_key => $opt ) { |
| 19 | - if ( isset( $shortcode_atts ) && isset( $shortcode_atts['opt'] ) && ( $shortcode_atts['opt'] !== $opt_key ) ) { | |
| 33 | + if ( isset( $shortcode_atts ) && isset( $shortcode_atts['opt'] ) && $shortcode_atts['opt'] !== $opt_key ) { | |
| 20 | 34 | continue; |
| 21 | 35 | } |
| 22 | 36 | |
| 37 | + if ( FrmFieldsHelper::should_hide_field_choice( $opt_key, $field ) ) { | |
| 38 | + continue; | |
| 39 | + } | |
| 40 | + | |
| 23 | 41 | $field_val = FrmFieldsHelper::get_value_from_array( $opt, $opt_key, $field ); |
| 24 | 42 | $opt = FrmFieldsHelper::get_label_from_array( $opt, $opt_key, $field ); |
| 25 | 43 | |
| 26 | 44 | /** |
| @@ -28,19 +46,23 @@ | ||
| 28 | 46 | * |
| 29 | 47 | * @since 5.0.04 |
| 30 | 48 | * |
| 31 | 49 | * @param string $label Label HTML. |
| 32 | - * @param array $args The arguments. Contains `field`. | |
| 50 | + * @param array $args The arguments. Contains `field` and `field_val`. | |
| 33 | 51 | */ |
| 34 | - $label = apply_filters( 'frm_choice_field_option_label', $opt, compact( 'field' ) ); | |
| 52 | + $label = apply_filters( 'frm_choice_field_option_label', $opt, compact( 'field', 'field_val' ) ); | |
| 35 | 53 | ?> |
| 36 | 54 | <div class="<?php echo esc_attr( apply_filters( 'frm_radio_class', 'frm_radio', $field, $field_val ) ); ?>" id="<?php echo esc_attr( FrmFieldsHelper::get_checkbox_id( $field, $opt_key, 'radio' ) ); ?>"><?php |
| 37 | 55 | |
| 38 | - if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) { | |
| 56 | + $checked = FrmAppHelper::check_selected( $field['value'], $field_val ) ? 'checked="checked" ' : ' '; | |
| 57 | + $should_echo_disabled_att = FrmFieldsHelper::should_disable_choice( $opt_key, trim( $checked ) !== '', $field ); | |
| 58 | + | |
| 59 | + if ( empty( $hide_label ) ) { | |
| 39 | 60 | $label_attributes = array( |
| 40 | 61 | 'for' => $html_id . '-' . $opt_key, |
| 41 | 62 | ); |
| 42 | - if ( $read_only ) { | |
| 63 | + | |
| 64 | + if ( $read_only || $should_echo_disabled_att ) { | |
| 43 | 65 | $label_attributes['class'] = 'frm-label-disabled'; |
| 44 | 66 | } |
| 45 | 67 | ?> |
| 46 | 68 | <label <?php FrmAppHelper::array_to_html_params( $label_attributes, true ); ?>> |
| @@ -45,21 +67,27 @@ | ||
| 45 | 67 | ?> |
| 46 | 68 | <label <?php FrmAppHelper::array_to_html_params( $label_attributes, true ); ?>> |
| 47 | 69 | <?php |
| 48 | 70 | } |
| 49 | - $checked = FrmAppHelper::check_selected( $field['value'], $field_val ) ? 'checked="checked" ' : ' '; | |
| 50 | 71 | |
| 72 | + $checked = FrmAppHelper::check_selected( $field['value'], $field_val ) ? 'checked="checked" ' : ' '; | |
| 51 | 73 | $other_opt = false; |
| 52 | 74 | $other_args = FrmFieldsHelper::prepare_other_input( compact( 'field_name', 'opt_key', 'field' ), $other_opt, $checked ); |
| 53 | 75 | ?> |
| 54 | 76 | <input type="radio" name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $html_id . '-' . $opt_key ); ?>" value="<?php echo esc_attr( $field_val ); ?>" |
| 55 | 77 | <?php |
| 56 | - echo $checked . ' '; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 57 | 78 | do_action( 'frm_field_input_html', $field ); |
| 79 | + echo $checked; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 80 | + | |
| 81 | + if ( $should_echo_disabled_att ) { | |
| 82 | + echo 'disabled="disabled" '; | |
| 83 | + } | |
| 58 | 84 | ?>/><?php |
| 59 | - | |
| 60 | - if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) { | |
| 61 | - echo ' ' . FrmAppHelper::kses( $label, 'all' ) . '</label>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 85 | + if ( empty( $hide_label ) ) { | |
| 86 | + echo ' '; | |
| 87 | + FrmAppHelper::kses_echo( $label, 'all' ); | |
| 88 | + FrmFieldsHelper::after_choice_input( $field, $opt_key ); | |
| 89 | + echo '</label>'; | |
| 62 | 90 | } |
| 63 | 91 | |
| 64 | 92 | $other_args = array( |
| 65 | 93 | 'other_opt' => $other_opt, |