PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13.1
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13.1
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / includes / admin / campaign-builder / panels / settings / class-settings-general.php

class-settings-general.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.13.1, at includes/admin/campaign-builder/panels/settings/class-settings-general.php

344 lines 12.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.0
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Builder_Panel_Settings_General' ) ) :
18
19 /**
20 * General subpanel for Settings Panel for campaign builder.
21 *
22 * @since 1.8.0
23 */
24 class Charitable_Builder_Panel_Settings_General {
25
26 /**
27 * Slug.
28 *
29 * @since 1.8.0
30 *
31 * @var string
32 */
33 private $slug = 'general';
34
35 /**
36 * The label/headline at the top of the panel.
37 *
38 * @since 1.8.0
39 *
40 * @var string
41 */
42 private $primary_label = '';
43
44 /**
45 * Determines if the tab is initially active on a fresh new page load.
46 *
47 * @since 1.8.0
48 *
49 * @var string
50 */
51 private $active = true;
52
53 /**
54 * Get things going. Add action hooks for the sidebar menu and the panel itself.
55 *
56 * @since 1.8.0
57 */
58 public function __construct() {
59
60 $this->primary_label = esc_html__( 'General Settings', 'charitable' );
61
62 add_action( 'charitable_campaign_builder_settings_sidebar', array( $this, 'sidebar_tab' ), 1 );
63 add_action( 'charitable_campaign_builder_settings_panels', array( $this, 'panel_content' ), 10 );
64 }
65
66 /**
67 * Generate sidebar html.
68 *
69 * @since 1.8.0
70 */
71 public function sidebar_tab() {
72
73 $active = ( true === apply_filters( 'charitable_campaign_builder_settings_sidebar_active', $this->active, $this->slug ) ) ? 'active' : false;
74
75 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>';
76 }
77
78 /**
79 * Displays the content of the general settings panel.
80 *
81 * @since 1.8.0
82 *
83 * @param array|bool $campaign_data Optional. An array of campaign data. Default is false.
84 */
85 public function panel_content( $campaign_data = false ) { // phpcs:ignore
86
87 $charitable_builder_form_fields = new Charitable_Builder_Form_Fields();
88 $settings = new Charitable_Builder_Panel_Settings();
89
90 $active = ( true === apply_filters( 'charitable_campaign_builder_settings_sidebar_active', $this->active, $this->slug ) ) ? 'active' : false;
91 $style = ( true === apply_filters( 'charitable_campaign_builder_settings_sidebar_active', $this->active, $this->slug ) ) ? 'display: block;' : false;
92
93 $campaign_id = isset( $_GET['campaign_id'] ) ? intval( $_GET['campaign_id'] ) : false; // phpcs:ignore
94 $campaign = charitable_get_campaign( $campaign_id );
95 $status = ( false !== $campaign_id ) ? $campaign->get_status() : 'not-saved';
96 $post_status = ( false !== $campaign_id ) ? get_post_status( $campaign_id ) : 'not-saved';
97
98 if ( 'finished' === $status && $campaign->has_goal() ) {
99 $status = $campaign->has_achieved_goal() ? 'successful' : 'unsuccessful';
100 }
101
102 switch ( $status ) {
103 case 'active':
104 $message = '<p>Your campaign is currently active and accepting donations.</p>';
105 break;
106
107 case 'unsuccessful':
108 $message = '<p><i class="fa fa-exclamation-circle"></i> <strong>What This Means:</strong> Your campaign\'s end date has past and did not meet it\'s campaign goal. You can extend the campaign end date or create a new campaign when you are ready to try again.</p>';
109 break;
110
111 case 'successful':
112 $message = '<p><i class="fa fa-exclamation-circle"></i> <strong>What This Means:</strong> Your campaign\'s end date has past and met it\'s campaign goal.</p>';
113 break;
114
115 case 'not-saved':
116 default:
117 $message = '<p><i class="fa fa-exclamation-circle"></i> <strong>What This Means:</strong> Your new campaign is unsaved. Click "Save" button in the top bar to save your campaign.</p>';
118 break;
119 }
120
121 switch ( $post_status ) {
122 case 'publish':
123 $post_status = 'public';
124 break;
125 default:
126 $post_status = $post_status;
127 break;
128
129 }
130
131 $post_status = 'public';
132
133 ob_start();
134
135 ?>
136
137 <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_attr( $style ); ?>">
138
139 <div class="charitable-panel-content-section-title"><?php echo esc_html( $this->primary_label ); ?></div>
140
141 <?php
142
143 do_action( 'charitable_campaign_builder_before_settings_general', $settings, $this->slug );
144
145 echo $charitable_builder_form_fields->generate_textbox( // phpcs:ignore
146 $settings->campaign_data_settings( 'description', 'general' ),
147 esc_html__( 'Campaign Description', 'charitable' ),
148 array(
149 'id' => 'campaign_description',
150 'name' => array( 'settings', esc_attr( $this->slug ), 'description' ),
151 'class' => 'campaign-builder-htmleditor',
152 'rows' => 10,
153 'html' => true,
154 'hidden' => true,
155 )
156 );
157
158 echo $charitable_builder_form_fields->generate_textbox( // phpcs:ignore
159 $settings->campaign_data_settings( 'extended_description', 'general' ),
160 esc_html__( 'Campaign Extended Description', 'charitable' ),
161 array(
162 'id' => 'campaign_extended_description',
163 'name' => array( 'settings', esc_attr( $this->slug ), 'extended_description' ),
164 'class' => 'campaign-builder-htmleditor',
165 'rows' => 30,
166 'html' => true,
167 'hidden' => true,
168 )
169 );
170
171 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore
172 $settings->campaign_data_settings( 'goal', 'general' ),
173 esc_html__( 'Goal', 'charitable' ),
174 array(
175 'id' => 'campaign_goal',
176 'name' => array( 'settings', esc_attr( $this->slug ), 'goal' ),
177 'placeholder' => '∞',
178 'add_commas' => true,
179 'tooltip' => esc_html__( 'Set a monetary goal that you want to reach for this campaign. Leave blank for no goal.', 'charitable' ),
180 'icon' => function_exists( 'charitable_get_currency_helper' ) ? charitable_get_currency_helper()->get_currency_symbol() : 'images/campaign-builder/settings/goal_dollar.png', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
181 )
182 );
183
184 echo $charitable_builder_form_fields->generate_date( // phpcs:ignore
185 $settings->campaign_data_settings( 'end_date', 'general' ),
186 esc_html__( 'Ending Date', 'charitable' ),
187 array(
188 'id' => 'campaign_end_date',
189 'name' => array( 'settings', esc_attr( $this->slug ), 'end_date' ),
190 'placeholder' => '∞',
191 'class' => 'campaign-builder-datepicker',
192 'label_below' => '',
193 'tooltip' => esc_html__( 'Set an ending date for your campaign, or leave blank to let the campaign run forever', 'charitable' ),
194 'icon' => 'images/campaign-builder/settings/calendar_month.png',
195 )
196 );
197
198 $tags_to_load = array();
199
200 $taxonomies = get_terms(
201 array(
202 'taxonomy' => 'campaign_tag',
203 'hide_empty' => false,
204 )
205 );
206
207 if ( ! empty( $taxonomies ) ) :
208 foreach ( $taxonomies as $category ) {
209 $tags_to_load[ $category->term_id ] = esc_html( $category->name );
210 }
211 endif;
212
213 echo $charitable_builder_form_fields->generate_tag_selector( // phpcs:ignore
214 $settings->campaign_data_settings( 'tags', 'general' ),
215 esc_html__( 'Tags', 'charitable' ),
216 array(
217 'id' => 'campaign_tags',
218 'name' => array( 'settings', esc_attr( $this->slug ), 'tags' ),
219 'options' => $tags_to_load, // phpcs:ignore
220 // translators: %s: URL to edit tags.
221 'tooltip' => wp_kses(
222 sprintf(
223 /* translators: %s is the URL to the Charitable settings campaign tags page. */
224 __( '<a href="%s" target="_blank">Visit the Tags page in Charitable\'s tool menu</a> to create, edit, and remove tags.', 'charitable' ),
225 esc_url( admin_url( 'edit-tags.php?taxonomy=campaign_tag&post_type=campaign' ) )
226 ),
227 [
228 'a' => [
229 'href' => [],
230 'target' => [],
231 ],
232 ]
233 ),
234 'default' => false,
235 )
236 );
237
238 echo $charitable_builder_form_fields->generate_categories( // phpcs:ignore
239 $settings->campaign_data_settings( 'categories', 'general' ),
240 'Categories',
241 array(
242 'id' => 'campaign_categories',
243 'name' => array( 'settings', esc_attr( $this->slug ), 'categories' ),
244 'class' => 'campaign-tag-categories',
245 'tooltip' => wp_kses(
246 sprintf(
247 /* translators: %s is the URL to the Charitable settings campaign categories page. */
248 __( '<a href="%s" target="_blank">Visit the Categories page in Charitable\'s tool menu</a> to create, edit, and remove categories.', 'charitable' ),
249 esc_url( admin_url( 'edit-tags.php?taxonomy=campaign_category&post_type=campaign' ) )
250 ),
251 [
252 'a' => [
253 'href' => [],
254 'target' => [],
255 ],
256 ]
257 ),
258 )
259 );
260
261 $users = apply_filters( 'charitable_campaign_builder_settings_general_users', charitable_get_users_as_campaign_creators( 'permissions', get_current_user_id() ) );
262 $campaign = isset( $campaign_id ) && 0 !== $campaign_id ? get_post( $campaign_id ) : false;
263
264 if ( ! empty( $users ) ) {
265
266 foreach ( $users as $user ) {
267 $users_to_pass[ $user->data->ID ] = array(
268 'avatar' => esc_url( get_avatar_url( $user->data->ID ) ),
269 'text' => ( '' . charitable_get_creator_data( $user->data->ID ) ),
270 'meta' => '&nbsp;( ID: ' . $user->data->ID . ' )&nbsp;Joined: ' . date( 'M d, Y ', strtotime( $user->data->user_registered ) ) . ' ', // phpcs:ignore
271 );
272 }
273
274 $campaign_creator_id = ( $campaign_id && ! empty( $campaign->post_author ) ) ? intval( $campaign->post_author ) : get_current_user_id();
275
276 echo $charitable_builder_form_fields->generate_user_dropdown( // phpcs:ignore
277 $settings->campaign_data_settings( 'campaign_creator_id', 'campaign-creator' ),
278 esc_html__( 'Campaign Creator', 'charitable' ),
279 array(
280 'id' => 'campaign_campaign_creator_id',
281 'name' => array( 'settings', esc_attr( $this->slug ), 'campaign_creator_id' ),
282 'class' => 'campaign-builder-campaign-creator-id',
283 'options' => $users_to_pass, // phpcs:ignore
284 'html' => true,
285 'default' => get_current_user_id(), // phpcs:ignore
286 'selected_value' => intval( $campaign_creator_id ),
287 'tooltip' => wp_kses(
288 sprintf(
289 /* translators: %s is the URL to the WordPress users page. */
290 __( 'Campaign creators can be any registered <a href="%s" target="_blank">WordPress user</a> with create or edit campaign permissions.', 'charitable' ),
291 esc_url( admin_url( 'users.php' ) )
292 ),
293 [
294 'a' => [
295 'href' => [],
296 'target' => [],
297 ],
298 ]
299 ),
300 )
301 );
302
303 }
304
305 do_action( 'charitable_campaign_builder_after_settings_general', $settings, $this->slug );
306
307 ?>
308
309 <div class="charitable-panel-fields-group" data-group="settings_advanced"> <?php /* class used to have unfoldable */ ?>
310 <div class="charitable-panel-fields-group-border-top"></div>
311 <div class="charitable-panel-fields-group-title"><?php echo esc_html__( 'Advanced', 'charitable' ); ?> <?php /* <i class="fa fa-chevron-circle-right"></i> */ ?>
312 </div>
313 <div class="charitable-panel-fields-group-inner" <?php /* style="display: none;" */ ?>>
314
315 <?php
316
317 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore
318 $settings->campaign_data_settings( 'form_css_class', 'general' ),
319 esc_html__( 'Form CSS Class', 'charitable' ),
320 array(
321 'id' => 'campaign_builder_css_class',
322 'name' => array( 'settings', esc_attr( $this->slug ), 'form_css_class' ),
323 'tooltip' => esc_html__( 'Assign a CSS class to the campaign container.', 'charitable' ),
324 )
325 );
326
327 ?>
328
329 </div>
330 </div>
331
332 </div>
333
334 <?php
335
336 $html = ob_get_clean();
337
338 echo $html; // phpcs:ignore
339 }
340 }
341
342 new Charitable_Builder_Panel_Settings_General();
343
344 endif;