| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly. |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Display select field. |
| 10 |
* |
| 11 |
* @author David Bisset |
| 12 |
* @package Charitable/Admin View/Settings |
| 13 |
* @copyright Copyright (c) 2023, WP Charitable LLC |
| 14 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 15 |
* @since 1.0.0 |
| 16 |
* @version 1.8.5.7 - Added show_button argument. |
| 17 |
* @version 1.8.8.6 |
| 18 |
*/ |
| 19 |
|
| 20 |
$charitable_value = charitable_get_option( $view_args['key'] ); |
| 21 |
|
| 22 |
if ( false === $charitable_value ) { |
| 23 |
$charitable_value = isset( $view_args['default'] ) ? $view_args['default'] : ''; |
| 24 |
} |
| 25 |
|
| 26 |
$charitable_form_action_url = isset( $view_args['form_action_url'] ) ? $view_args['form_action_url'] : ''; |
| 27 |
$charitable_form_action_method = isset( $view_args['form_action_method'] ) ? $view_args['form_action_method'] : 'POST'; |
| 28 |
$charitable_show_button = isset( $view_args['show_button'] ) ? $view_args['show_button'] : true; |
| 29 |
$charitable_button_label = isset( $view_args['button_label'] ) ? $view_args['button_label'] : 'Submit'; |
| 30 |
$charitable_nonce_action_name = isset( $view_args['nonce_action_name'] ) ? $view_args['nonce_action_name'] : 'wpcharitable-action'; |
| 31 |
$charitable_nonce_field_name = isset( $view_args['nonce_field_name'] ) ? $view_args['nonce_field_name'] : false; |
| 32 |
$charitable_select_name = isset( $view_args['select_name'] ) ? $view_args['select_name'] : $view_args['name']; |
| 33 |
$charitable_accept = isset( $view_args['accept'] ) ? $view_args['accept'] : '.jsn,.json'; |
| 34 |
$charitable_form_tag = isset( $view_args['form_tag'] ) ? $view_args['form_tag'] : true; |
| 35 |
$charitable_wrapper_class = isset( $view_args['wrapper_class'] ) ? $view_args['wrapper_class'] : ''; |
| 36 |
$charitable_thumbnail_preview = isset( $view_args['thumbnail_preview'] ) ? $view_args['thumbnail_preview'] : false; // This is the ID of the attachment. |
| 37 |
$charitable_remove_button = isset( $view_args['show_remove_button'] ) ? $view_args['show_remove_button'] : false; |
| 38 |
$charitable_remove_button_text = isset( $view_args['remove_button_text'] ) ? $view_args['remove_button_text'] : __( 'Remove current logo', 'charitable' ); |
| 39 |
$charitable_error_message = false; |
| 40 |
|
| 41 |
// determine if the fields should be shown, based on what we are trying to do with them. |
| 42 |
if ( isset( $view_args['nonce_action_name'] ) && 'import_donations' === $view_args['nonce_action_name'] && is_array( $view_args['options'] ) && 0 === count( $view_args['options'] ) ) { |
| 43 |
$charitable_error_message = '<strong>' . __( 'You have no campaigns to import donations into.', 'charitable' ) . '</strong>'; |
| 44 |
} |
| 45 |
?> |
| 46 |
<?php if ( $charitable_form_tag ) : ?> |
| 47 |
<form action="<?php echo esc_url( $charitable_form_action_url ); ?>" method="POST" enctype="multipart/form-data" class="form-contains-file charitable-import-campaign-donations-form"> |
| 48 |
|
| 49 |
<?php wp_nonce_field( $charitable_nonce_action_name, $charitable_nonce_field_name ); ?> |
| 50 |
|
| 51 |
<input type="hidden" name="action" value="<?php echo esc_attr( $view_args['action'] ); ?>"> |
| 52 |
|
| 53 |
<?php endif; ?> |
| 54 |
|
| 55 |
<?php if ( isset( $view_args['options'] ) && ! empty( $view_args['subtitle'] ) && ! $charitable_error_message ) : ?> |
| 56 |
<p class="top-label"><?php echo esc_html( $view_args['subtitle'] ); ?></p> |
| 57 |
<?php endif; ?> |
| 58 |
|
| 59 |
<?php if ( isset( $view_args['options'] ) ) : ?> |
| 60 |
<div class="charitable-setting-dropdown-container <?php echo esc_attr( $view_args['wrapper_class'] ); ?>"> |
| 61 |
<?php if ( ! $charitable_error_message ) { ?> |
| 62 |
<select id="<?php printf( 'charitable_settings_%s', implode( '_', $view_args['key'] ) ); // phpcs:ignore ?>" |
| 63 |
name="<?php printf( 'charitable_settings[%s]', esc_attr( $charitable_select_name ) ); ?>" |
| 64 |
class="<?php echo esc_attr( $view_args['classes'] ); ?>" |
| 65 |
<?php echo charitable_get_arbitrary_attributes( $view_args ); // phpcs:ignore ?> |
| 66 |
> |
| 67 |
<?php |
| 68 |
foreach ( $view_args['options'] as $charitable_key => $charitable_option ) : |
| 69 |
if ( is_array( $charitable_option ) ) : |
| 70 |
$charitable_label = isset( $charitable_option['label'] ) ? $charitable_option['label'] : ''; |
| 71 |
?> |
| 72 |
<optgroup label="<?php echo esc_attr( $charitable_label ); ?>"> |
| 73 |
<?php foreach ( $charitable_option['options'] as $charitable_k => $charitable_opt ) : ?> |
| 74 |
<option value="<?php echo esc_attr( $charitable_k ); ?>" <?php selected( $charitable_k, $charitable_value ); ?>><?php echo esc_html( $charitable_opt ); ?></option> |
| 75 |
<?php endforeach ?> |
| 76 |
</optgroup> |
| 77 |
<?php else : ?> |
| 78 |
<option value="<?php echo esc_attr( $charitable_key ); ?>" <?php selected( $charitable_key, $charitable_value ); ?>><?php echo esc_html( $charitable_option ); ?></option> |
| 79 |
<?php |
| 80 |
endif; |
| 81 |
endforeach |
| 82 |
?> |
| 83 |
</select> |
| 84 |
<?php } else { ?> |
| 85 |
<p><?php echo $charitable_error_message; // phpcs:ignore ?></p> |
| 86 |
<?php } ?> |
| 87 |
<?php endif; ?> |
| 88 |
</div> |
| 89 |
<?php if ( ! $charitable_error_message ) { ?> |
| 90 |
<div class="charitable-setting-file-container"> |
| 91 |
|
| 92 |
<input type="file" id="<?php printf( 'charitable_settings_%s', implode( '_', $view_args['key'] ) ); // phpcs:ignore ?>" |
| 93 |
name="<?php printf( 'charitable_settings[%s]', esc_attr( $view_args['name'] ) ); ?>" |
| 94 |
class="<?php echo esc_attr( $view_args['classes'] ); ?>" |
| 95 |
<?php echo charitable_get_arbitrary_attributes( $view_args ); // phpcs:ignore ?> |
| 96 |
accept="<?php echo esc_attr( $charitable_accept ); ?>" |
| 97 |
/> |
| 98 |
<?php if ( $charitable_show_button ) : ?> |
| 99 |
<input class="button button-primary" type="submit" value="<?php echo esc_attr( $charitable_button_label ); ?>"> |
| 100 |
<?php endif; ?> |
| 101 |
|
| 102 |
</div> |
| 103 |
<?php } ?> |
| 104 |
<?php if ( $charitable_thumbnail_preview ) : ?> |
| 105 |
<div class="charitable-setting-file-thumbnail-preview" style="max-height: 100px; display: flex; align-items: center; justify-content: left;"> |
| 106 |
<img src="<?php echo esc_url( wp_get_attachment_url( $charitable_thumbnail_preview ) ); ?>" alt="<?php echo esc_attr( $view_args['name'] ); ?>" style="max-height: 100px; width: auto; height: auto; object-fit: contain;"> |
| 107 |
</div> |
| 108 |
<?php |
| 109 |
// Add checkbox for removing the logo - if there is no remove button id, don't show the checkbox. |
| 110 |
if ( ! empty( $view_args['remove_button_id'] ) ) { |
| 111 |
$charitable_remove_checkbox_name = 'charitable_settings[' . $view_args['remove_button_id'] . ']'; |
| 112 |
$charitable_remove_checkbox_id = 'charitable_settings_' . $view_args['remove_button_id']; |
| 113 |
?> |
| 114 |
<div class="charitable-setting-remove-logo" style="margin-top: 10px;"> |
| 115 |
<label> |
| 116 |
<input type="checkbox" |
| 117 |
name="<?php echo esc_attr( $charitable_remove_checkbox_name ); ?>" |
| 118 |
id="<?php echo esc_attr( $charitable_remove_checkbox_id ); ?>" |
| 119 |
value="1" |
| 120 |
<?php checked( isset( $_POST['charitable_settings'][ $view_args['remove_button_id'] ] ) && $_POST['charitable_settings'][ $view_args['remove_button_id'] ] ); // phpcs:ignore ?> |
| 121 |
> |
| 122 |
<?php echo esc_html( $charitable_remove_button_text ); ?> |
| 123 |
</label> |
| 124 |
</div> |
| 125 |
<?php } ?> |
| 126 |
<?php endif; ?> |
| 127 |
<?php if ( $charitable_form_tag ) : ?> |
| 128 |
</form> |
| 129 |
<?php endif; ?> |
| 130 |
<?php if ( isset( $view_args['help'] ) ) : ?> |
| 131 |
<div class="charitable-help"><?php echo $view_args['help']; // phpcs:ignore ?></div> |
| 132 |
<?php |
| 133 |
endif; |
| 134 |
|