PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.7
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.7
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 1.7.0.9 All 211 releases
charitable / includes / admin / settings / class-charitable-settings.php

class-charitable-settings.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.7, at includes/admin/settings/class-charitable-settings.php

827 lines 27.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Settings UI.
4 *
5 * @package Charitable/Classes/Charitable_Settings
6 * @author David Bisset
7 * @copyright Copyright (c) 2022, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.0.0
10 * @version 1.0.0
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_Settings' ) ) :
19
20 /**
21 * Charitable_Settings
22 *
23 * @final
24 * @since 1.0.0
25 */
26 final class Charitable_Settings {
27
28 /**
29 * The single instance of this class.
30 *
31 * @var Charitable_Settings|null
32 */
33 private static $instance = null;
34
35 /**
36 * Dynamic groups.
37 *
38 * @since 1.5.7
39 *
40 * @var array
41 */
42 private $dynamic_groups;
43
44 /**
45 * List of static pages, used in some settings.
46 *
47 * @since 1.5.9
48 *
49 * @var array
50 */
51 private $pages;
52
53 /**
54 * Create object instance.
55 *
56 * @since 1.0.0
57 */
58 private function __construct() {
59 do_action( 'charitable_admin_settings_start', $this );
60
61 add_action( 'charitable_after_admin_settings', [ $this, 'settings_cta' ] );
62 }
63
64 /**
65 * Returns and/or create the single instance of this class.
66 *
67 * @since 1.2.0
68 *
69 * @return Charitable_Settings
70 */
71 public static function get_instance() {
72 if ( is_null( self::$instance ) ) {
73 self::$instance = new self();
74 }
75
76 return self::$instance;
77 }
78
79 /**
80 * Return the array of tabs used on the settings page.
81 *
82 * @since 1.0.0
83 *
84 * @return string[]
85 */
86 public function get_sections() {
87 /**
88 * Filter the settings tabs.
89 *
90 * @since 1.0.0
91 *
92 * @param string[] $tabs List of tabs in key=>label format.
93 */
94 return apply_filters(
95 'charitable_settings_tabs',
96 array(
97 'general' => __( 'General', 'charitable' ),
98 'gateways' => __( 'Payment Gateways', 'charitable' ),
99 'emails' => __( 'Emails', 'charitable' ),
100 'privacy' => __( 'Privacy', 'charitable' ),
101 'tools' => __( 'Tools', 'charitable' ),
102 'advanced' => __( 'Advanced', 'charitable' ),
103 )
104 );
105
106 }
107
108 /**
109 * Optionally add the extensions tab.
110 *
111 * @since 1.3.0
112 *
113 * @param string[] $tabs The existing set of tabs.
114 * @return string[]
115 */
116 public function maybe_add_extensions_tab( $tabs ) {
117 $actual_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general';
118
119 /* Set the tab to 'extensions' */
120 $_GET['tab'] = 'extensions';
121
122 /**
123 * Filter the settings in the extensions tab.
124 *
125 * @since 1.3.0
126 *
127 * @param array $fields Array of fields. Empty by default.
128 */
129 $settings = apply_filters( 'charitable_settings_tab_fields_extensions', array() );
130
131 /* Set the tab back to whatever it actually is */
132 $_GET['tab'] = $actual_tab;
133
134 if ( ! empty( $settings ) ) {
135 $tabs = charitable_add_settings_tab(
136 $tabs,
137 'extensions',
138 __( 'Extensions', 'charitable' ),
139 array(
140 'index' => 4,
141 )
142 );
143 }
144
145 return $tabs;
146 }
147
148 /**
149 * Add the hidden "extensions" section field.
150 *
151 * @since 1.6.7
152 *
153 * @param array $fields All the settings fields.
154 * @return array
155 */
156 public function add_hidden_extensions_setting_field( $fields ) {
157 if ( ! array_key_exists( 'extensions', $fields ) ) {
158 return $fields;
159 }
160
161 $fields['extensions']['section'] = array(
162 'title' => '',
163 'type' => 'hidden',
164 'priority' => 10000,
165 'value' => 'extensions',
166 'save' => false,
167 );
168
169 return $fields;
170 }
171
172 /**
173 * Register setting.
174 *
175 * @since 1.0.0
176 *
177 * @return void
178 */
179 public function register_settings() {
180 if ( ! charitable_is_settings_view() ) {
181 return;
182 }
183
184 register_setting( 'charitable_settings', 'charitable_settings', array( $this, 'sanitize_settings' ) );
185
186 $fields = $this->get_fields();
187
188 if ( empty( $fields ) ) {
189 return;
190 }
191
192 $sections = array_merge( $this->get_sections(), $this->get_dynamic_groups() );
193
194 /* Register each section */
195 foreach ( $sections as $section_key => $section ) {
196 $section_id = 'charitable_settings_' . $section_key;
197
198 add_settings_section(
199 $section_id,
200 __return_null(),
201 '__return_false',
202 $section_id
203 );
204
205 if ( ! isset( $fields[ $section_key ] ) || empty( $fields[ $section_key ] ) ) {
206 continue;
207 }
208
209 /* Sort by priority */
210 $section_fields = $fields[ $section_key ];
211 uasort( $section_fields, 'charitable_priority_sort' );
212
213 /* Add the individual fields within the section */
214 foreach ( $section_fields as $key => $field ) {
215 $this->register_field( $field, array( $section_key, $key ) );
216 }
217 }
218 }
219
220 /**
221 * Sanitize submitted settings before saving to the database
222 * This includes: "workaround" for Stripe keys with 1.7.0.0, additional settings options after 1.7.0.6+
223 *
224 * @since 1.0.0
225 *
226 * @param array $values The submitted values.
227 * @return string
228 */
229 public function sanitize_settings( $values ) {
230
231 $old_values = get_option( 'charitable_settings', array() );
232 $new_values = array();
233
234 if ( ! is_array( $old_values ) ) {
235 $old_values = array();
236 }
237
238 if ( ! is_array( $values ) ) {
239 $values = array();
240 }
241
242 /* Loop through all fields, merging the submitted values into the master array */
243 foreach ( $values as $section => $submitted ) {
244 $new_values = array_merge( $new_values, $this->get_section_submitted_values( $section, $submitted ) );
245 }
246
247 $settings_keys = array_keys( $new_values );
248
249 if ( defined( 'CHARITABLE_DEBUG' ) && CHARITABLE_DEBUG ) {
250 error_log( 'santiize_settings' );
251 error_log( 'values:' );
252 error_log( print_r( $values, true ) );
253 error_log( 'old_values:' );
254 error_log( print_r( $old_values, true ) );
255 error_log( 'new_values:' );
256 error_log( print_r( $new_values, true ) );
257 }
258
259 // determine if Charitable gateway "test mode" is being changed, and if so add a notice to the user.
260 if ( array_key_exists('test_mode', $new_values ) && array_key_exists('test_mode', $old_values ) && $old_values['test_mode'] !== $new_values['test_mode'] ) {
261 $old_settings_keys = array_keys( $old_values );
262 $dismissible = true;
263 if ( in_array( 'gateways_stripe', $old_settings_keys ) ) {
264 charitable_get_admin_notices()->add_notice( 'Some active payment gateways <strong>(including Stripe)</strong> might have reset their connections due to an update in the test mode. Please check your active payment gateways in ensure they are still connected.', 'warning', false, $dismissible );
265 } else {
266 charitable_get_admin_notices()->add_notice( 'Some active payment gateways might have reset their connections due to an update in the test mode. Please check your active payment gateways in ensure they are still connected.', 'warning', false, $dismissible );
267 }
268 }
269
270 if ( in_array( 'gateways_stripe', $settings_keys ) && charitable()->is_stripe_connect_addon() && false === charitable_using_stripe_connect() ) {
271 // non-existant array keys in the array for API keys might be a result of the "manual update key" feature which is based on ajax and might not load keys into form if the user doesn't click on the link in the settings to view/edit them.
272 if ( ! array_key_exists( 'live_secret_key', $values['gateways_stripe'] ) && isset( $old_values['gateways_stripe']['live_secret_key'] ) && ( false !== $old_values['gateways_stripe']['live_secret_key'] ) ) {
273 $values['gateways_stripe']['live_secret_key'] = $old_values['gateways_stripe']['live_secret_key'];
274 }
275 if ( ! array_key_exists( 'live_public_key', $values['gateways_stripe'] ) && isset( $old_values['gateways_stripe']['live_public_key'] ) && ( false !== $old_values['gateways_stripe']['live_public_key'] ) ) {
276 $values['gateways_stripe']['live_public_key'] = $old_values['gateways_stripe']['live_secret_key'];
277 }
278 if ( ! array_key_exists( 'test_secret_key', $values['gateways_stripe'] ) && isset( $old_values['gateways_stripe']['test_secret_key'] ) && ( false !== $old_values['gateways_stripe']['test_secret_key'] ) ) {
279 $values['gateways_stripe']['test_secret_key'] = $old_values['gateways_stripe']['test_secret_key'];
280 }
281 if ( ! array_key_exists( 'test_public_key', $values['gateways_stripe'] ) && isset( $old_values['gateways_stripe']['test_public_key'] ) && ( false !== $old_values['gateways_stripe']['test_public_key'] ) ) {
282 $values['gateways_stripe']['test_public_key'] = $old_values['gateways_stripe']['test_public_key'];
283 }
284 if ( defined( 'CHARITABLE_DEBUG' ) && CHARITABLE_DEBUG ) {
285 error_log( 'update:' );
286 error_log( print_r( $values, true ) );
287 }
288 }
289
290 // determine if stripe is being returned as new values - if so, then perform the API key save workaround
291 if ( in_array( 'gateways_stripe', $settings_keys ) && charitable()->is_stripe_connect_addon() && false === charitable_using_stripe_connect() ) {
292 if ( defined( 'CHARITABLE_DEBUG' ) && CHARITABLE_DEBUG ) {
293 error_log( 'there is a stripe connect addon but we are not using stripe connect' );
294 }
295 // the stripe connect addon is installed AND the AM Stripe Connect isn't being used... so it's possible the keys could be manual and the user could be updating them... therefore let's just make sure the new values match the values incoming.
296 $new_values['gateways_stripe']['live_secret_key'] = ( isset( $values['gateways_stripe']['live_secret_key'] ) && ( false !== $values['gateways_stripe']['live_secret_key'] ) ) ? $values['gateways_stripe']['live_secret_key'] : null;
297 $new_values['gateways_stripe']['live_public_key'] = ( isset( $values['gateways_stripe']['live_public_key'] ) && ( false !== $values['gateways_stripe']['live_public_key'] ) ) ? $values['gateways_stripe']['live_public_key'] : null;
298 $new_values['gateways_stripe']['test_secret_key'] = ( isset( $values['gateways_stripe']['test_secret_key'] ) && ( false !== $values['gateways_stripe']['test_secret_key'] ) ) ? $values['gateways_stripe']['test_secret_key'] : null;
299 $new_values['gateways_stripe']['test_public_key'] = ( isset( $values['gateways_stripe']['test_public_key'] ) && ( false !== $values['gateways_stripe']['test_public_key'] ) ) ? $values['gateways_stripe']['test_public_key'] : null;
300 } else if ( in_array( 'gateways_stripe', $settings_keys ) ) {
301 // otherwise we preserve the keys
302 if ( defined( 'CHARITABLE_DEBUG' ) && CHARITABLE_DEBUG ) {
303 error_log( 'charitable debug, final with debug on:' );
304 $new_values['gateways_stripe']['live_secret_key'] = ( isset( $values['gateways_stripe']['live_secret_key'] ) && ( false !== $values['gateways_stripe']['live_secret_key'] ) ) ? $values['gateways_stripe']['live_secret_key'] : null;
305 $new_values['gateways_stripe']['live_public_key'] = ( isset( $values['gateways_stripe']['live_public_key'] ) && ( false !== $values['gateways_stripe']['live_public_key'] ) ) ? $values['gateways_stripe']['live_public_key'] : null;
306 $new_values['gateways_stripe']['test_secret_key'] = ( isset( $values['gateways_stripe']['test_secret_key'] ) && ( false !== $values['gateways_stripe']['test_secret_key'] ) ) ? $values['gateways_stripe']['test_secret_key'] : null;
307 $new_values['gateways_stripe']['test_public_key'] = ( isset( $values['gateways_stripe']['test_public_key'] ) && ( false !== $values['gateways_stripe']['test_public_key'] ) ) ? $values['gateways_stripe']['test_public_key'] : null;
308 } else {
309 $new_values['gateways_stripe']['live_secret_key'] = ( isset( $old_values['gateways_stripe']['live_secret_key'] ) && ( false !== $old_values['gateways_stripe']['live_secret_key'] ) ) ? $old_values['gateways_stripe']['live_secret_key'] : null;
310 $new_values['gateways_stripe']['live_public_key'] = ( isset( $old_values['gateways_stripe']['live_public_key'] ) && ( false !== $old_values['gateways_stripe']['live_public_key'] ) ) ? $old_values['gateways_stripe']['live_public_key'] : null;
311 $new_values['gateways_stripe']['test_secret_key'] = ( isset( $old_values['gateways_stripe']['test_secret_key'] ) && ( false !== $old_values['gateways_stripe']['test_secret_key'] ) ) ? $old_values['gateways_stripe']['test_secret_key'] : null;
312 $new_values['gateways_stripe']['test_public_key'] = ( isset( $old_values['gateways_stripe']['test_public_key'] ) && ( false !== $old_values['gateways_stripe']['test_public_key'] ) ) ? $old_values['gateways_stripe']['test_public_key'] : null;
313 }
314 }
315
316 // preserve any webhook keys, regardless if stripe connect addon is active or not.
317 if ( in_array( 'gateways_stripe', $settings_keys ) ) {
318 if ( array_key_exists( 'test_webhook_id', $old_values['gateways_stripe'] ) && isset( $old_values['gateways_stripe']['test_webhook_id'] ) ) {
319 $new_values['gateways_stripe']['test_webhook_id'] = $old_values['gateways_stripe']['test_webhook_id'];
320 }
321 if ( array_key_exists( 'live_webhook_id', $old_values['gateways_stripe'] ) && isset( $old_values['gateways_stripe']['live_webhook_id'] ) ) {
322 $new_values['gateways_stripe']['live_webhook_id'] = $old_values['gateways_stripe']['live_webhook_id'];
323 }
324 }
325
326 // account for incoming legacy licenses (1.7.0.4+)
327 // all we are doing is adding the licenses into the values so that the save_license hook can retreieve them and validate, etc.
328 if ( ! empty( $values['legacy_licenses'] ) && isset( $values['advanced']['section'] ) && 'licenses' === $values['advanced']['section'] ) {
329 if ( ! isset( $new_values['licenses']['legacy'] ) ) {
330 $new_values['licenses_legacy'] = (array) $values['legacy_licenses'];
331 }
332 }
333
334 // ensure any hex color text files are valid hex fields
335 if ( isset( $new_values['donation_form_default_highlight_colour'] ) ) {
336 $color_to_test = esc_html( $new_values['donation_form_default_highlight_colour'] );
337 $color_valid = false;
338 // check for a hex color string
339 if ( preg_match( '/^#[a-f0-9]{6}$/i', $color_to_test ) ) {
340 // hex color is valid
341 $color_valid = true;
342 }
343 // Check for a hex color string without hash
344 if ( preg_match( '/^[a-f0-9]{6}$/i', $color_to_test ) ) {
345 // hex color is valid
346 $color_valid = true;
347 $new_values['donation_form_default_highlight_colour'] = '#' . $color_to_test;
348 }
349 if ( false === $color_valid ) {
350 // not valid, make sure it is blank.
351 $new_values['donation_form_default_highlight_colour'] = false;
352 }
353 // clear the transient that stores the color styles
354 delete_transient( 'charitable_custom_styles' );
355 }
356
357 $values = wp_parse_args( $new_values, $old_values );
358
359 if ( defined( 'CHARITABLE_DEBUG' ) && CHARITABLE_DEBUG ) {
360 error_log( 'santiize_settings values updated' );
361 error_log( print_r( $values, true ) );
362 }
363
364 /**
365 * Filter sanitized settings.
366 *
367 * @since 1.0.0
368 *
369 * @param array $values All values, merged.
370 * @param array $new_values Newly submitted values.
371 * @param array $old_values Old settings.
372 */
373
374 $values = apply_filters( 'charitable_save_settings', $values, $new_values, $old_values );
375
376 $this->add_update_message( __( 'Settings saved', 'charitable' ), 'success' );
377
378 return $values;
379 }
380
381 /**
382 * Checkbox settings should always be either 1 or 0.
383 *
384 * @since 1.0.0
385 *
386 * @param mixed $value Submitted value for field.
387 * @param array $field Field definition.
388 * @return int
389 */
390 public function sanitize_checkbox_value( $value, $field ) {
391 if ( isset( $field['type'] ) && 'checkbox' == $field['type'] ) {
392 $value = intval( $value && 'on' == $value );
393 }
394
395 return $value;
396 }
397
398 /**
399 * Render field. This is the default callback used for all fields, unless an alternative callback has been specified.
400 *
401 * @since 1.0.0
402 *
403 * @param array $args Field definition.
404 * @return void
405 */
406 public function render_field( $args ) {
407 $field_type = isset( $args['type'] ) ? $args['type'] : 'text';
408
409 charitable_admin_view( 'settings/' . $field_type, $args );
410 }
411
412 /**
413 * Returns an array of all pages in the id=>title format.
414 *
415 * @since 1.0.0
416 *
417 * @return string[]
418 */
419 public function get_pages() {
420 if ( ! isset( $this->pages ) ) {
421 $this->pages = charitable_get_pages_options();
422 }
423
424 return $this->pages;
425 }
426
427 /**
428 * Add an update message.
429 *
430 * @since 1.4.6
431 *
432 * @param string $message The message text.
433 * @param string $type The type of message. Options: 'error', 'success', 'warning', 'info'.
434 * @param boolean $dismissible Whether the message can be dismissed.
435 * @return void
436 */
437 public function add_update_message( $message, $type = 'error', $dismissible = true ) {
438 if ( ! in_array( $type, array( 'error', 'success', 'warning', 'info' ) ) ) {
439 $type = 'error';
440 }
441
442 charitable_get_admin_notices()->add_notice( $message, $type, false, $dismissible );
443 }
444
445 /**
446 * Recursively add settings fields, given an array.
447 *
448 * @since 1.0.0
449 *
450 * @param array $field The setting field.
451 * @param array $keys Array containing the section key and field key.
452 * @return void
453 */
454 private function register_field( $field, $keys ) {
455 $section_id = 'charitable_settings_' . $keys[0];
456
457 if ( isset( $field['render'] ) && ! $field['render'] ) {
458 return;
459 }
460
461 /* Drop the first key, which is the section identifier */
462 $field['name'] = implode( '][', $keys );
463
464 if ( ! $this->is_dynamic_group( $keys[0] ) ) {
465 array_shift( $keys );
466 }
467
468 $field['key'] = $keys;
469 $field['classes'] = $this->get_field_classes( $field );
470 $callback = isset( $field['callback'] ) ? $field['callback'] : array( $this, 'render_field' );
471 $label = $this->get_field_label( $field, end( $keys ) );
472
473 add_settings_field(
474 sprintf( 'charitable_settings_%s', implode( '_', $keys ) ),
475 $label,
476 $callback,
477 $section_id,
478 $section_id,
479 $field
480 );
481 }
482
483 /**
484 * Return the label for the given field.
485 *
486 * @since 1.0.0
487 *
488 * @param array $field The field definition.
489 * @param string $key The field key.
490 * @return string
491 */
492 private function get_field_label( $field, $key ) {
493 $label = '';
494
495 if ( isset( $field['label_for'] ) ) {
496 $label = $field['label_for'];
497 }
498
499 if ( isset( $field['title'] ) ) {
500 $label = $field['title'];
501 }
502
503 return $label;
504 }
505
506 /**
507 * Return a space separated string of classes for the given field.
508 *
509 * @since 1.0.0
510 *
511 * @param array $field Field definition.
512 * @return string
513 */
514 private function get_field_classes( $field ) {
515 $classes = array( 'charitable-settings-field' );
516
517 if ( isset( $field['class'] ) ) {
518 $classes[] = $field['class'];
519 }
520
521 /**
522 * Filter the list of classes to apply to settings fields.
523 *
524 * @since 1.0.0
525 *
526 * @param array $classes The list of classes.
527 * @param array $field The field definition.
528 */
529 $classes = apply_filters( 'charitable_settings_field_classes', $classes, $field );
530
531 return implode( ' ', $classes );
532 }
533
534 /**
535 * Return an array with all the fields & sections to be displayed.
536 *
537 * @uses charitable_settings_fields
538 * @see Charitable_Settings::register_setting()
539 * @since 1.0.0
540 *
541 * @return array
542 */
543 private function get_fields() {
544 /**
545 * Use the charitable_settings_tab_fields to include the fields for new tabs.
546 * DO NOT use it to add individual fields. That should be done with the
547 * filters within each of the methods.
548 */
549 $fields = array();
550
551 foreach ( $this->get_sections() as $section_key => $section ) {
552 /**
553 * Filter the array of fields to display in a particular tab.
554 *
555 * @since 1.0.0
556 *
557 * @param array $fields Array of fields.
558 */
559 $fields[ $section_key ] = apply_filters( 'charitable_settings_tab_fields_' . $section_key, array() );
560 }
561
562 /**
563 * Filter the array of settings fields.
564 *
565 * @since 1.0.0
566 *
567 * @param array $fields Array of fields.
568 */
569 return apply_filters( 'charitable_settings_tab_fields', $fields );
570 }
571
572 /**
573 * Get the submitted value for a particular setting.
574 *
575 * @since 1.0.0
576 *
577 * @param string $key The key of the setting being saved.
578 * @param array $field The setting field.
579 * @param array $submitted The submitted values.
580 * @param string $section The section being saved.
581 * @return mixed|null Returns null if the value was not submitted or is not applicable.
582 */
583 private function get_setting_submitted_value( $key, $field, $submitted, $section ) {
584 $value = null;
585
586 if ( isset( $field['save'] ) && ! $field['save'] ) {
587 return $value;
588 }
589
590 $field_type = isset( $field['type'] ) ? $field['type'] : '';
591
592 switch ( $field_type ) {
593
594 case 'checkbox':
595 $value = intval( array_key_exists( $key, $submitted ) && 'on' == $submitted[ $key ] );
596 break;
597
598 case 'multi-checkbox':
599 $value = isset( $submitted[ $key ] ) ? $submitted[ $key ] : array();
600 break;
601
602 case '':
603 case 'heading':
604 return $value;
605
606 default:
607 if ( ! array_key_exists( $key, $submitted ) ) {
608 return $value;
609 }
610
611 $value = $submitted[ $key ];
612
613 }//end switch
614
615 /**
616 * General way to sanitize values. If you only need to sanitize a
617 * specific setting, used the filter below instead.
618 *
619 * @since 1.0.0
620 *
621 * @param mixed $value The current setting value.
622 * @param array $field The field configuration.
623 * @param array $submitted All submitted data.
624 * @param string $key The setting key.
625 * @param string $section The section being saved.
626 */
627 $value = apply_filters( 'charitable_sanitize_value', $value, $field, $submitted, $key, $section );
628
629 /**
630 * Sanitize the setting value.
631 *
632 * The filter hook is formatted like this: charitable_sanitize_value_{$section}_{$key}.
633 *
634 * @since 1.5.0
635 *
636 * @param mixed $value The current setting value.
637 * @param array $field The field configuration.
638 * @param array $submitted All submitted data.
639 */
640 return apply_filters( 'charitable_sanitize_value_' . $section . '_' . $key, $value, $field, $submitted );
641 }
642
643 /**
644 * Return the submitted values for the given section.
645 *
646 * @since 1.0.0
647 *
648 * @param string $section The section being edited.
649 * @param array $submitted The submitted values.
650 * @return array
651 */
652 private function get_section_submitted_values( $section, $submitted ) {
653 $values = array();
654 $form_fields = $this->get_fields();
655
656 if ( ! isset( $form_fields[ $section ] ) ) {
657 return $values;
658 }
659
660 foreach ( $form_fields[ $section ] as $key => $field ) {
661 $value = $this->get_setting_submitted_value( $key, $field, $submitted, $section );
662
663 if ( is_null( $value ) ) {
664 continue;
665 }
666
667 if ( $this->is_dynamic_group( $section ) ) {
668 $values[ $section ][ $key ] = $value;
669 continue;
670 }
671
672 $values[ $key ] = $value;
673 }
674
675 return $values;
676 }
677
678 /**
679 * Return list of dynamic groups.
680 *
681 * @since 1.0.0
682 *
683 * @return string[]
684 */
685 private function get_dynamic_groups() {
686 if ( ! isset( $this->dynamic_groups ) ) {
687 /**
688 * Filter the list of dynamic groups.
689 *
690 * @since 1.0.0
691 *
692 * @param array $groups The dynamic groups.
693 */
694 $this->dynamic_groups = apply_filters( 'charitable_dynamic_groups', array() );
695 }
696
697 return $this->dynamic_groups;
698 }
699
700 /**
701 * Returns whether the given key indicates the start of a new section of the settings.
702 *
703 * @since 1.0.0
704 *
705 * @param string $composite_key The unique key for this group.
706 * @return boolean
707 */
708 private function is_dynamic_group( $composite_key ) {
709 return array_key_exists( $composite_key, $this->get_dynamic_groups() );
710 }
711
712 /* DEPRECATED FUNCTIONS */
713
714 /**
715 * Get the update messages.
716 *
717 * @deprecated 1.7.0
718 *
719 * @since 1.4.13 Deprecated.
720 */
721 public function get_update_messages() {
722 charitable_get_deprecated()->deprecated_function(
723 __METHOD__,
724 '1.4.13',
725 'Charitable_Admin_Notices::get_notices()'
726 );
727
728 return charitable_get_admin_notices()->get_notices();
729 }
730
731 /**
732 * Display upgrade notice at the bottom on the plugin settings pages.
733 *
734 * @since 1.7.0.4
735 *
736 * @param string $view Current view inside the plugin settings page.
737 */
738 public function settings_cta( $view = false ) {
739
740 if ( charitable_is_pro() ) {
741 // no need to display this cta since they have a valid license.
742 return;
743 }
744
745 if ( get_option( 'charitable_lite_settings_upgrade', false ) || apply_filters( 'charitable_lite_settings_upgrade', false ) ) {
746 return;
747 }
748 ?>
749 <div class="settings-lite-cta">
750 <button type="button" class="button-link charitable-banner-dismiss dismiss">x</button>
751 <h5><?php esc_html_e( 'Get Charitable Pro and Unlock all the Powerful Features', 'charitable-lite' ); ?></h5>
752 <p><?php esc_html_e( 'Thanks for being a loyal Charitable Lite user. Upgrade to Charitable Pro to unlock all the awesome features and experience why Charitable is consistently rated a top WordPress donation and fundraising plugin.', 'charitable-lite' ); ?></p>
753 <p>
754 <?php
755 printf( __( 'We know that you will truly love Charitable. Over 10,000+ non-profits who have chosen Charitable to get more donations from their website can\'t be wrong!', 'charitable-lite' ) );
756 ?>
757 </p>
758 <h6><?php esc_html_e( 'Pro Features:', 'charitable-lite' ); ?></h6>
759 <div class="list">
760 <ul>
761 <li><?php esc_html_e( 'Offer recurring donations to donors', 'charitable-lite' ); ?></li>
762 <li><?php esc_html_e( 'Use fee relief to keep more donation dollars', 'charitable-lite' ); ?></li>
763 <li><?php esc_html_e( 'Integrate with popular email marketing platforms', 'charitable-lite' ); ?></li>
764 <li><?php esc_html_e( 'Expand your reach with peer-to-peer fundraising', 'charitable-lite' ); ?></li>
765 <li><?php esc_html_e( 'Allow donors to crowdfund donations', 'charitable-lite' ); ?></li>
766 </ul>
767 <ul>
768 <li><?php esc_html_e( 'Automate common tasks with Zapier and smart workflows', 'charitable-lite' ); ?></li>
769 <li><?php esc_html_e( 'Run campaigns with ambassador and team support', 'charitable-lite' ); ?></li>
770 <li><?php esc_html_e( 'Advanced donation management with annual receipts' ); ?></li>
771 <li><?php esc_html_e( 'Allow donors to give donations anonymously', 'charitable-lite' ); ?></li>
772 <li><?php esc_html_e( 'Add videos and updates to all campaigns', 'charitable-lite' ); ?></li>
773 </ul>
774 </div>
775 <p>
776 <a href="<?php echo esc_url( charitable_pro_upgrade_url( 'settings-upgrade' ) ); ?>" target="_blank" rel="noopener noreferrer">
777 <?php esc_html_e( 'Get Charitable Pro Today and Unlock all the Powerful Features »', 'charitable-lite' ); ?>
778 </a>
779 </p>
780 <p>
781 <?php
782 echo wp_kses(
783 __( '<strong>Bonus:</strong> Charitable Lite users get up to <span class="green">$200 off regular price</span>, automatically applied at checkout.', 'charitable-lite' ),
784 [
785 'strong' => [],
786 'span' => [
787 'class' => [],
788 ],
789 ]
790 );
791 ?>
792 </p>
793 </div>
794 <script type="text/javascript">
795 jQuery( function ( $ ) {
796 $( document ).on( 'click', '.settings-lite-cta .dismiss', function ( event ) {
797 event.preventDefault();
798 $.post( ajaxurl, {
799 action: 'charitable_lite_settings_upgrade',
800 chartiable_action: 'remove_lite_cta'
801 } );
802 $( '.settings-lite-cta' ).remove();
803 } );
804 } );
805 </script>
806 <?php
807 }
808
809 /**
810 * Dismiss upgrade notice at the bottom on the plugin settings pages.
811 *
812 * @since 1.7.0.4
813 */
814 public function settings_cta_dismiss() {
815
816 if ( ! charitable_current_user_can() ) {
817 wp_send_json_error();
818 }
819
820 update_option( 'charitable_lite_settings_upgrade', time() );
821
822 wp_send_json_success();
823 }
824 }
825
826 endif;
827