| @@ -1,75 +1,133 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 3 | +// Exit if accessed directly. | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 2 | 8 | /** |
| 3 | 9 | * Display select field. |
| 4 | 10 | * |
| 5 | 11 | * @author David Bisset |
| 6 | 12 | * @package Charitable/Admin View/Settings |
| 7 | - * @copyright Copyright (c) 2022, WP Charitable LLC | |
| 13 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 8 | 14 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 | 15 | * @since 1.0.0 |
| 10 | - * @version 1.6.25 | |
| 16 | + * @version 1.8.5.7 - Added show_button argument. | |
| 17 | + * @version 1.8.8.6 | |
| 11 | 18 | */ |
| 12 | 19 | |
| 13 | -$value = charitable_get_option( $view_args['key'] ); | |
| 20 | +$charitable_value = charitable_get_option( $view_args['key'] ); | |
| 14 | 21 | |
| 15 | -if ( false === $value ) { | |
| 16 | - $value = isset( $view_args['default'] ) ? $view_args['default'] : ''; | |
| 22 | +if ( false === $charitable_value ) { | |
| 23 | + $charitable_value = isset( $view_args['default'] ) ? $view_args['default'] : ''; | |
| 17 | 24 | } |
| 18 | 25 | |
| 19 | -$form_action_url = isset( $view_args['form_action_url'] ) ? $view_args['form_action_url'] : ''; | |
| 20 | -$form_action_method = isset( $view_args['form_action_method'] ) ? $view_args['form_action_method'] : 'POST'; | |
| 21 | -$button_label = isset( $view_args['button_label'] ) ? $view_args['button_label'] : 'Submit'; | |
| 22 | -$nonce_action_name = isset( $view_args['nonce_action_name'] ) ? $view_args['nonce_action_name'] : 'wpcharitable-action'; | |
| 23 | -$nonce_field_name = isset( $view_args['nonce_field_name'] ) ? $view_args['nonce_field_name'] : false; | |
| 24 | -$select_name = isset( $view_args['select_name'] ) ? $view_args['select_name'] : $view_args['name']; | |
| 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 | +} | |
| 25 | 45 | ?> |
| 26 | -<form action="<?php echo $form_action_url; ?>" method="POST" enctype="multipart/form-data" class="form-contains-file"> | |
| 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"> | |
| 27 | 48 | |
| 28 | -<?php wp_nonce_field( $nonce_action_name, $nonce_field_name ); ?> | |
| 49 | + <?php wp_nonce_field( $charitable_nonce_action_name, $charitable_nonce_field_name ); ?> | |
| 29 | 50 | |
| 30 | -<?php if ( isset( $view_args['options'] ) ) : ?> | |
| 31 | - <p class="top-label">Select a campaign to import donations into:</p> | |
| 51 | + <input type="hidden" name="action" value="<?php echo esc_attr( $view_args['action'] ); ?>"> | |
| 52 | + | |
| 32 | 53 | <?php endif; ?> |
| 33 | 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 | + | |
| 34 | 59 | <?php if ( isset( $view_args['options'] ) ) : ?> |
| 35 | - <div class="charitable-setting-dropdown-container"> | |
| 36 | - <select id="<?php printf( 'charitable_settings_%s', implode( '_', $view_args['key'] ) ); ?>" | |
| 37 | - name="<?php printf( 'charitable_settings[%s]', $select_name ); ?>" | |
| 38 | - class="<?php echo esc_attr( $view_args['classes'] ); ?>" | |
| 39 | - <?php echo charitable_get_arbitrary_attributes( $view_args ); ?> | |
| 40 | - > | |
| 41 | - <?php | |
| 42 | - foreach ( $view_args['options'] as $key => $option ) : | |
| 43 | - if ( is_array( $option ) ) : | |
| 44 | - $label = isset( $option['label'] ) ? $option['label'] : ''; | |
| 45 | - ?> | |
| 46 | - <optgroup label="<?php echo $label; ?>"> | |
| 47 | - <?php foreach ( $option['options'] as $k => $opt ) : ?> | |
| 48 | - <option value="<?php echo $k; ?>" <?php selected( $k, $value ); ?>><?php echo $opt; ?></option> | |
| 49 | - <?php endforeach ?> | |
| 50 | - </optgroup> | |
| 51 | - <?php else : ?> | |
| 52 | - <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $value ); ?>><?php echo $option; ?></option> | |
| 53 | - <?php | |
| 54 | - endif; | |
| 55 | - endforeach | |
| 56 | - ?> | |
| 57 | - </select> | |
| 58 | - <?php endif; ?> | |
| 59 | - </div> | |
| 60 | - <div class="charitable-setting-file-container"> | |
| 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"> | |
| 61 | 91 | |
| 62 | - <input type="file" id="<?php printf( 'charitable_settings_%s', implode( '_', $view_args['key'] ) ); ?>" | |
| 63 | - name="<?php printf( 'charitable_settings[%s]', $view_args['name'] ); ?>" | |
| 64 | - class="<?php echo esc_attr( $view_args['classes'] ); ?>" | |
| 65 | - <?php echo charitable_get_arbitrary_attributes( $view_args ); ?> | |
| 66 | - accept=".jsn,.json" | |
| 67 | - /> | |
| 68 | - <input class="button button-primary" type="submit" value="<?php echo $button_label; ?>"> | |
| 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; ?> | |
| 69 | 101 | |
| 70 | - </div> | |
| 71 | -</form> | |
| 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; ?> | |
| 72 | 130 | <?php if ( isset( $view_args['help'] ) ) : ?> |
| 73 | - <div class="charitable-help"><?php echo $view_args['help']; ?></div> | |
| 131 | + <div class="charitable-help"><?php echo $view_args['help']; // phpcs:ignore ?></div> | |
| 74 | 132 | <?php |
| 75 | 133 | endif; |