$value ) { $checked = false; if ( $posted && ! empty( $_POST[$name] ) ) { if ( $multiple && in_array( esc_sql( $value ), (array) $_POST[$name] ) ) $checked = true; if ( ! $multiple && $_POST[$name] == esc_sql( $value ) ) $checked = true; } else { if ( in_array( $key + 1, (array) $defaults ) ) $checked = true; } $checked = $checked ? ' checked="checked"' : ''; if ( '' !== $tabindex_att ) { $tabindex = sprintf( ' tabindex="%d"', $tabindex_att ); $tabindex_att += 1; } else { $tabindex = ''; } if ( isset( $labels[$key] ) ) $label = $labels[$key]; else $label = $value; if ( $label_first ) { // put label first, input last $item = '' . esc_html( $label ) . ' '; $item .= ''; } else { $item = ''; $item .= ' ' . esc_html( $label ) . ''; } if ( $use_label_element ) $item = ''; $item = '' . $item . ''; $html .= $item; } $html = '' . $html . ''; $html = '' . $html . $validation_error . ''; return $html; } /* Validation filter */ add_filter( 'wpcf7_validate_checkbox', 'wpcf7_checkbox_validation_filter', 10, 2 ); add_filter( 'wpcf7_validate_checkbox*', 'wpcf7_checkbox_validation_filter', 10, 2 ); add_filter( 'wpcf7_validate_radio', 'wpcf7_checkbox_validation_filter', 10, 2 ); function wpcf7_checkbox_validation_filter( $result, $tag ) { $type = $tag['type']; $name = $tag['name']; if ( 'checkbox*' == $type ) { if ( empty( $_POST[$name] ) ) { $result['valid'] = false; $result['reason'][$name] = wpcf7_get_message( 'invalid_required' ); } } return $result; } /* Tag generator */ add_action( 'admin_init', 'wpcf7_add_tag_generator_checkbox_and_radio', 30 ); function wpcf7_add_tag_generator_checkbox_and_radio() { wpcf7_add_tag_generator( 'checkbox', __( 'Checkboxes', 'wpcf7' ), 'wpcf7-tg-pane-checkbox', 'wpcf7_tg_pane_checkbox' ); wpcf7_add_tag_generator( 'radio', __( 'Radio buttons', 'wpcf7' ), 'wpcf7-tg-pane-radio', 'wpcf7_tg_pane_radio' ); } function wpcf7_tg_pane_checkbox( &$contact_form ) { wpcf7_tg_pane_checkbox_and_radio( 'checkbox' ); } function wpcf7_tg_pane_radio( &$contact_form ) { wpcf7_tg_pane_checkbox_and_radio( 'radio' ); } function wpcf7_tg_pane_checkbox_and_radio( $type = 'checkbox' ) { if ( 'radio' != $type ) $type = 'checkbox'; ?>