charitable
/
includes
/
admin
/
campaign-builder
/
panels
/
settings
/
class-settings-donation-options.php
class-settings-donation-options.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.13, at includes/admin/campaign-builder/panels/settings/class-settings-donation-options.php
| 1 | <?php |
| 2 | /** |
| 3 | * The class that defines a subpanel for the settings area for the campaign builder. |
| 4 | * |
| 5 | * @package Charitable/Admin/Charitable_Campaign_Meta_Boxes |
| 6 | * @author David Bisset |
| 7 | * @copyright Copyright (c) 2023, WP Charitable LLC |
| 8 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 | * @since 1.8.0 |
| 10 | * @version 1.8.9.1 |
| 11 | */ |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | if ( ! class_exists( 'Charitable_Builder_Panel_Settings_Donation_Options' ) ) : |
| 18 | |
| 19 | /** |
| 20 | * General subpanel for Settings Panel for campaign builder. |
| 21 | * |
| 22 | * @since 1.8.0 |
| 23 | * @version 1.8.9.1 |
| 24 | */ |
| 25 | class Charitable_Builder_Panel_Settings_Donation_Options { |
| 26 | |
| 27 | /** |
| 28 | * Slug. |
| 29 | * |
| 30 | * @since 1.8.0 |
| 31 | * |
| 32 | * @var string |
| 33 | */ |
| 34 | private $slug = 'donation-options'; |
| 35 | |
| 36 | /** |
| 37 | * The label/headline at the top of the panel. |
| 38 | * |
| 39 | * @since 1.8.0 |
| 40 | * |
| 41 | * @var string |
| 42 | */ |
| 43 | private $primary_label = ''; |
| 44 | |
| 45 | /** |
| 46 | * Determines if the tab is initially active on a fresh new page load. |
| 47 | * |
| 48 | * @since 1.8.0 |
| 49 | * |
| 50 | * @var string |
| 51 | */ |
| 52 | private $active = false; |
| 53 | |
| 54 | |
| 55 | /** |
| 56 | * Get things going. Add action hooks for the sidebar menu and the panel itself. |
| 57 | * |
| 58 | * @since 1.8.0 |
| 59 | */ |
| 60 | public function __construct() { |
| 61 | |
| 62 | $this->primary_label = esc_html__( 'Donation Options', 'charitable' ); |
| 63 | |
| 64 | add_action( 'charitable_campaign_builder_settings_sidebar', array( $this, 'sidebar_tab' ), 10 ); |
| 65 | add_action( 'charitable_campaign_builder_settings_panels', array( $this, 'panel_content' ), 20 ); |
| 66 | |
| 67 | add_filter( 'charitable_campaign_builder_localized_conditionals', array( $this, 'field_conditionals' ), 10, 1 ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Generate sidebar html. |
| 72 | * |
| 73 | * @since 1.8.0 |
| 74 | */ |
| 75 | public function sidebar_tab() { |
| 76 | |
| 77 | $active = ( true === apply_filters( 'charitable_campaign_builder_settings_sidebar_active', $this->active, $this->slug ) ) ? 'active' : false; |
| 78 | |
| 79 | echo '<a href="#" class="charitable-panel-sidebar-section charitable-panel-sidebar-section-' . esc_attr( $this->slug ) . ' ' . esc_attr( $active ) . '" data-section="' . esc_attr( $this->slug ) . '">' . esc_html( $this->primary_label ) . ' <i class="fa fa-angle-right charitable-toggle-arrow"></i></a>'; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Add conditionals for fields in the donation options panel. |
| 84 | * |
| 85 | * @since 1.8.0 |
| 86 | * |
| 87 | * @param array $conditionals The existing conditionals. |
| 88 | * @return array |
| 89 | */ |
| 90 | public function field_conditionals( $conditionals ) { |
| 91 | |
| 92 | $conditionals['#charitable-panel-field-settings-charitable-campaign-allow-recurring-donations'] = array( // toggle. |
| 93 | 'checked' => array( |
| 94 | 'show' => array( |
| 95 | '.charitable-panel-fields-group-recurring-donations .charitable-panel-field:not(#charitable-panel-field-settings-charitable-campaign-allow-recurring-donations-wrap)', |
| 96 | ), |
| 97 | ), |
| 98 | 'unchecked' => array( |
| 99 | 'hide' => array( |
| 100 | '.charitable-panel-fields-group-recurring-donations .charitable-panel-field:not(#charitable-panel-field-settings-charitable-campaign-allow-recurring-donations-wrap)', |
| 101 | ), |
| 102 | ), |
| 103 | ); |
| 104 | $conditionals['#settings-donation-options-recurring-donations-mode--advanced'] = array( // radio |
| 105 | 'checked' => array( |
| 106 | 'if' => array( |
| 107 | '#charitable-panel-field-settings-charitable-campaign-allow-recurring-donations' => 'checked', |
| 108 | ), |
| 109 | 'show' => array( |
| 110 | '#charitable-panel-field-settings-campaign-recurring-donation-amounts-wrap, #charitable-panel-field-settings-charitable-campaign-allow-custom-recurring-donations-wrap, #charitable-panel-field-settings-campaign-recurring-default-tab-wrap', |
| 111 | ), |
| 112 | ), |
| 113 | 'unchecked' => array( |
| 114 | 'hide' => array( |
| 115 | '#charitable-panel-field-settings-campaign-recurring-donation-amounts-wrap, #charitable-panel-field-settings-charitable-campaign-allow-custom-recurring-donations-wrap, |
| 116 | #charitable-panel-field-settings-campaign-recurring-default-tab-wrap', |
| 117 | ), |
| 118 | ), |
| 119 | ); |
| 120 | |
| 121 | return $conditionals; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Generate panel content. |
| 126 | * |
| 127 | * @since 1.8.0 |
| 128 | * @version 1.8.9.1 |
| 129 | */ |
| 130 | public function panel_content( $campaign_data = false ) { // phpcs:ignore |
| 131 | |
| 132 | $charitable_builder_form_fields = new Charitable_Builder_Form_Fields(); |
| 133 | $settings = new Charitable_Builder_Panel_Settings(); |
| 134 | |
| 135 | $active = ( true === apply_filters( 'charitable_campaign_builder_settings_sidebar_active', $this->active, $this->slug ) ) ? 'active' : false; |
| 136 | $style = ( true === apply_filters( 'charitable_campaign_builder_settings_sidebar_active', $this->active, $this->slug ) ) ? 'display: block;' : false; |
| 137 | |
| 138 | ob_start(); |
| 139 | |
| 140 | ?> |
| 141 | |
| 142 | <div class="charitable-panel-content-section charitable-panel-content-section-<?php echo esc_attr( $this->slug ); ?> <?php echo esc_attr( $active ); ?>" style="<?php echo esc_html( $style ); ?>"> |
| 143 | |
| 144 | <div class="charitable-panel-content-section-title"><?php echo esc_html( $this->primary_label ); ?></div> |
| 145 | |
| 146 | <?php |
| 147 | |
| 148 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 149 | $suggested_donations_default = $settings->campaign_data_settings( 'suggested_donations_default', 'donation-options' ); |
| 150 | |
| 151 | echo $charitable_builder_form_fields->generate_donation_amounts( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 152 | $settings->campaign_data_settings( 'donation_amounts', 'donation-options' ), |
| 153 | esc_html__( 'Suggested Donation Amounts', 'charitable' ), |
| 154 | array( |
| 155 | 'id' => 'campaign_donation_amounts', |
| 156 | 'name' => array( 'settings', esc_attr( $this->slug ), 'donation_amounts' ), |
| 157 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 158 | 'default' => $suggested_donations_default, |
| 159 | ) |
| 160 | ); |
| 161 | |
| 162 | $currency_symbol_raw = function_exists( 'charitable_get_currency_helper' ) ? charitable_get_currency_helper()->get_currency_symbol() : 'images/campaign-builder/settings/goal_dollar.png'; |
| 163 | $currency_symbol = wp_kses_post( $currency_symbol_raw ); |
| 164 | |
| 165 | echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 166 | $settings->campaign_data_settings( 'minimum_donation_amount', 'donation-options' ), |
| 167 | esc_html__( 'Minimum Donation Amount', 'charitable' ), |
| 168 | array( |
| 169 | 'id' => 'campaign_minimum_donation_amount', |
| 170 | 'name' => array( 'settings', esc_attr( $this->slug ), 'minimum_donation_amount' ), |
| 171 | 'placeholder' => '', |
| 172 | // 'add_commas' => true, |
| 173 | 'description' => esc_html__( 'Leave empty to allow no restrictions on how small the donation can be.', 'charitable' ), |
| 174 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 175 | 'icon' => $currency_symbol, |
| 176 | 'container_class' => 'charitable-format-money', |
| 177 | ) |
| 178 | ); |
| 179 | |
| 180 | $default_allow_custom = ! empty( $_GET['campaign_id'] ) ? $settings->campaign_data_settings( 'allow_custom_donations', 'donation-options' ) : '1'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 181 | |
| 182 | echo $charitable_builder_form_fields->generate_toggle( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 183 | $default_allow_custom, |
| 184 | esc_html__( 'Allow Custom Donations', 'charitable' ), |
| 185 | array( |
| 186 | 'id' => 'campaign_allow_custom_donations', |
| 187 | 'checked_value' => '1', |
| 188 | 'name' => array( 'settings', esc_attr( $this->slug ), 'allow_custom_donations' ), |
| 189 | 'container_class' => 'charitable-campaign-builder-allow-custom-donations', |
| 190 | ) |
| 191 | ); |
| 192 | |
| 193 | do_action( 'charitable_campaign_builder_settings_donation_options_after', $this->active, $this->slug ); |
| 194 | |
| 195 | ?> |
| 196 | |
| 197 | </div> |
| 198 | |
| 199 | <?php |
| 200 | |
| 201 | $html = ob_get_clean(); |
| 202 | |
| 203 | echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | new Charitable_Builder_Panel_Settings_Donation_Options(); |
| 208 | |
| 209 | endif; |
| 210 |