| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly. |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* The template used to display select form fields. |
| 10 |
* |
| 11 |
* @author WP Charitable LLC |
| 12 |
* @package Charitable/Templates/Form Fields |
| 13 |
* @since 1.0.0 |
| 14 |
* @version 1.0.0 |
| 15 |
* @version 1.8.8.6 |
| 16 |
*/ |
| 17 |
|
| 18 |
if ( ! isset( $view_args['form'] ) || ! isset( $view_args['field'] ) ) { |
| 19 |
return; |
| 20 |
} |
| 21 |
|
| 22 |
$charitable_form = $view_args['form']; |
| 23 |
$charitable_field = $view_args['field']; |
| 24 |
$charitable_classes = $view_args['classes']; |
| 25 |
$charitable_is_required = isset( $charitable_field['required'] ) ? $charitable_field['required'] : false; |
| 26 |
$charitable_options = isset( $charitable_field['options'] ) ? $charitable_field['options'] : array(); |
| 27 |
$charitable_value = isset( $charitable_field['value'] ) ? $charitable_field['value'] : ''; |
| 28 |
|
| 29 |
if ( is_array( $charitable_value ) ) { |
| 30 |
$charitable_value = current( $charitable_value ); |
| 31 |
} |
| 32 |
|
| 33 |
if ( count( $charitable_options ) ) : |
| 34 |
|
| 35 |
?> |
| 36 |
<div id="charitable_field_<?php echo esc_attr( $charitable_field['key'] ); ?>" class="<?php echo esc_attr( $charitable_classes ); ?>"> |
| 37 |
<?php if ( isset( $charitable_field['label'] ) ) : ?> |
| 38 |
<label for="charitable_field_<?php echo esc_attr( $charitable_field['key'] ); ?>_element"> |
| 39 |
<?php echo wp_kses_post( $charitable_field['label'] ); ?> |
| 40 |
<?php if ( $charitable_is_required ) : ?> |
| 41 |
<abbr class="required" title="<?php esc_html_e( 'Required', 'charitable' ); ?>">*</abbr> |
| 42 |
<?php endif ?> |
| 43 |
</label> |
| 44 |
<?php endif ?> |
| 45 |
<select name="<?php echo esc_attr( $charitable_field['key'] ); ?>" id="charitable_field_<?php echo esc_attr( $charitable_field['key'] ); ?>_element"> |
| 46 |
<?php |
| 47 |
foreach ( $charitable_options as $charitable_val => $charitable_label ) : |
| 48 |
|
| 49 |
if ( is_array( $charitable_label ) ) : |
| 50 |
?> |
| 51 |
<optgroup label="<?php echo esc_attr( $charitable_val ); ?>"> |
| 52 |
<?php foreach ( $charitable_label as $charitable_val => $charitable_label ) : ?> |
| 53 |
<option value="<?php echo esc_attr( $charitable_val ); ?>" <?php selected( $charitable_val, $charitable_value ); ?>><?php echo esc_html( $charitable_label ); ?></option> |
| 54 |
<?php endforeach; ?> |
| 55 |
</optgroup> |
| 56 |
<?php else : ?> |
| 57 |
<option value="<?php echo esc_attr( $charitable_val ); ?>" <?php selected( $charitable_val, $charitable_value ); ?>><?php echo esc_html( $charitable_label ); ?></option> |
| 58 |
<?php |
| 59 |
|
| 60 |
endif; |
| 61 |
endforeach; |
| 62 |
|
| 63 |
?> |
| 64 |
</select> |
| 65 |
<?php if ( isset( $charitable_field['help'] ) ) : ?> |
| 66 |
<p class="charitable-field-help"><?php echo $charitable_field['help']; // phpcs:ignore ?></p> |
| 67 |
<?php endif ?> |
| 68 |
</div> |
| 69 |
<?php |
| 70 |
|
| 71 |
endif; |
| 72 |
|