PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 4.15.3
GiveWP – Donation Plugin and Fundraising Platform v4.15.3
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / class-admin-settings.php
give / includes / admin Last commit date
add-ons 4 years ago donors 7 months ago emails 5 months ago forms 1 year ago payments 1 year ago reports 1 year ago settings 1 month ago shortcodes 1 year ago tools 4 months ago upgrades 5 months ago views 1 year ago abstract-admin-settings-page.php 2 years ago admin-actions.php 1 month ago admin-filters.php 9 months ago admin-footer.php 2 years ago admin-pages.php 5 months ago class-addon-activation-banner.php 9 months ago class-admin-settings.php 1 year ago class-api-keys-table.php 4 years ago class-blank-slate.php 1 year ago class-give-admin.php 5 years ago class-give-html-elements.php 1 year ago class-i18n-module.php 4 years ago dashboard-widgets.php 3 years ago give-metabox-functions.php 3 years ago import-functions.php 11 months ago misc-functions.php 2 years ago plugins.php 9 months ago setting-page-functions.php 6 years ago
class-admin-settings.php
1346 lines
1 <?php
2 /**
3 * Give Admin Settings Class
4 *
5 * @package Give
6 * @subpackage Classes/Give_Admin_Settings
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.8
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 if ( ! class_exists( 'Give_Admin_Settings' ) ) :
17
18 /**
19 * Give_Admin_Settings Class.
20 *
21 * @since 1.8
22 */
23 class Give_Admin_Settings {
24
25 /**
26 * Setting pages.
27 *
28 * @since 1.8
29 * @var array List of settings.
30 */
31 private static $settings = [];
32
33 /**
34 * Setting filter and action prefix.
35 *
36 * @since 1.8
37 * @var string setting filter and action name prefix.
38 */
39 private static $setting_filter_prefix = '';
40
41 /**
42 * Error messages.
43 *
44 * @since 1.8
45 * @var array List of errors.
46 */
47 private static $errors = [];
48
49 /**
50 * Update messages.
51 *
52 * @since 1.8
53 * @var array List of messages.
54 */
55 private static $messages = [];
56
57 /**
58 * Include the settings page classes.
59 *
60 * @since 1.8
61 * @return array
62 */
63 public static function get_settings_pages() {
64 /**
65 * Filter the setting page.
66 *
67 * Note: filter dynamically fire on basis of setting page slug.
68 * For example: if you register a setting page with give-settings menu slug
69 * then filter will be give-settings_get_settings_pages
70 *
71 * @since 3.17.1 cast to array
72 * @since 1.8
73 *
74 * @param array $settings Array of settings class object.
75 */
76 self::$settings = (array)apply_filters( self::$setting_filter_prefix . '_get_settings_pages', [] );
77
78 return self::$settings;
79 }
80
81 /**
82 * Verify admin setting nonce
83 *
84 * @since 1.8.14
85 * @access public
86 *
87 * @return bool
88 */
89 public static function verify_nonce() {
90 if ( empty( $_REQUEST['_give-save-settings'] ) || ! wp_verify_nonce( $_REQUEST['_give-save-settings'], 'give-save-settings' ) ) {
91 return false;
92 }
93
94 return true;
95 }
96
97 /**
98 * Save the settings.
99 *
100 * @since 1.8
101 * @return void
102 */
103 public static function save() {
104 $current_tab = give_get_current_setting_tab();
105
106 if ( ! self::verify_nonce() ) {
107 echo '<div class="notice error"><p>' . esc_attr__( 'Action failed. Please refresh the page and retry.', 'give' ) . '</p></div>';
108 die();
109 }
110
111 /**
112 * Trigger Action.
113 *
114 * Note: action dynamically fire on basis of setting page slug and current tab.
115 * For example: if you register a setting page with give-settings menu slug and general current tab name
116 * then action will be give-settings_save_general
117 *
118 * @since 1.8
119 */
120 do_action( self::$setting_filter_prefix . '_save_' . $current_tab );
121
122 self::add_message( 'give-setting-updated', __( 'Your settings have been saved.', 'give' ) );
123
124 /**
125 * Trigger Action.
126 *
127 * Note: action dynamically fire on basis of setting page slug.
128 * For example: if you register a setting page with give-settings menu slug
129 * then action will be give-settings_saved
130 *
131 * @since 1.8
132 */
133 do_action( self::$setting_filter_prefix . '_saved' );
134 }
135
136 /**
137 * Add a message.
138 *
139 * @since 1.8
140 *
141 * @param string $code Message code (Note: This should be unique).
142 * @param string $message Message text.
143 *
144 * @return void
145 */
146 public static function add_message( $code, $message ) {
147 self::$messages[ $code ] = $message;
148 }
149
150 /**
151 * Add an error.
152 *
153 * @since 1.8
154 *
155 * @param string $code Message code (Note: This should be unique).
156 * @param string $message Message text.
157 *
158 * @return void
159 */
160 public static function add_error( $code, $message ) {
161 self::$errors[ $code ] = $message;
162 }
163
164 /**
165 * Output messages + errors.
166 *
167 * @since 1.8
168 * @return void
169 */
170 public static function show_messages() {
171 $notice_html = '';
172 $classes = 'give-notice settings-error notice is-dismissible';
173
174 self::$errors = apply_filters( self::$setting_filter_prefix . '_error_notices', self::$errors );
175 self::$messages = apply_filters( self::$setting_filter_prefix . '_update_notices', self::$messages );
176
177 if ( 0 < count( self::$errors ) ) {
178 foreach ( self::$errors as $code => $message ) {
179 $notice_html .= sprintf(
180 '<div id="setting-error-%1$s" class="%2$s error" style="display: none"><p>%3$s</p></div>',
181 $code,
182 $classes,
183 $message
184 );
185 }
186 }
187
188 if ( 0 < count( self::$messages ) ) {
189 foreach ( self::$messages as $code => $message ) {
190 $notice_html .= sprintf(
191 '<div id="setting-error-%1$s" class="%2$s updated" style="display: none"><p><strong>%3$s</strong></p></div>',
192 $code,
193 $classes,
194 $message
195 );
196 }
197 }
198
199 echo $notice_html;
200 }
201
202 /**
203 * Settings page.
204 *
205 * Handles the display of the main give settings page in admin.
206 *
207 * @since 1.8
208 * @return bool
209 */
210 public static function output() {
211 // Get current setting page.
212 self::$setting_filter_prefix = give_get_current_setting_page();
213
214 // Bailout: Exit if setting page is not defined.
215 if ( empty( self::$setting_filter_prefix ) ) {
216 return false;
217 }
218
219 /**
220 * Trigger Action.
221 *
222 * Note: action dynamically fire on basis of setting page slug
223 * For example: if you register a setting page with give-settings menu slug
224 * then action will be give-settings_start
225 *
226 * @since 1.8
227 */
228 do_action( self::$setting_filter_prefix . '_start' );
229
230 $current_tab = give_get_current_setting_tab();
231 $current_section = give_get_current_setting_section();
232
233 // Include settings pages.
234 $all_setting = self::get_settings_pages();
235
236 /* @var object $current_setting_obj */
237 $current_setting_obj = new StdClass();
238
239 foreach ( $all_setting as $setting ) {
240 if (
241 is_object($setting) && method_exists( $setting, 'get_id' ) &&
242 $current_tab === $setting->get_id()
243 ) {
244 $current_setting_obj = $setting;
245 break;
246 }
247 }
248
249 // Save settings if data has been posted.
250 if ( isset( $_POST['_give-save-settings'] ) ) {
251 self::save();
252 }
253
254 /**
255 * Filter the tabs for current setting page.
256 *
257 * Note: filter dynamically fire on basis of setting page slug.
258 * For example: if you register a setting page with give-settings menu slug and general current tab name
259 * then action will be give-settings_tabs_array
260 *
261 * @since 1.8
262 */
263 $tabs = apply_filters( self::$setting_filter_prefix . '_tabs_array', [] );
264
265 include 'views/html-admin-settings.php';
266
267 return true;
268 }
269
270 /**
271 * Get a setting from the settings API.
272 *
273 * @since 1.8
274 *
275 * @param string $option_name Option Name.
276 * @param string $field_id Field ID.
277 * @param mixed $default Default.
278 *
279 * @return string|bool
280 */
281 public static function get_option( $option_name = '', $field_id = '', $default = false ) {
282 // Bailout.
283 if ( empty( $option_name ) && empty( $field_id ) ) {
284 return false;
285 }
286
287 if ( ! empty( $field_id ) && ! empty( $option_name ) ) {
288 // Get field value if any.
289 $option_value = get_option( $option_name );
290
291 $option_value = ( is_array( $option_value ) && array_key_exists( $field_id, $option_value ) )
292 ? $option_value[ $field_id ]
293 : $default;
294 } else {
295 // If option name is empty but not field name then this means, setting is direct store to option table under there field name.
296 $option_name = ! $option_name ? $field_id : $option_name;
297
298 // Get option value if any.
299 $option_value = get_option( $option_name, $default );
300 }
301
302 /**
303 * Filter the option value
304 *
305 * @since 2.2.3
306 *
307 * @param mixed $option_value
308 * @param string $option_name
309 * @param string $field_id
310 * @param mixed $default
311 */
312 return apply_filters( 'give_admin_field_get_value', $option_value, $option_name, $field_id, $default );
313 }
314
315 /**
316 * Output admin fields.
317 *
318 * Loops though the give options array and outputs each field.
319 *
320 * @since 4.1.0 Display tabs only when there is more than one group available
321 * @since 1.8
322 * @access public
323 *
324 * @param array $sections Opens array to output.
325 * @param string $option_name Opens array to output.
326 *
327 * @return void
328 * @todo Refactor this function
329 *
330 */
331 public static function output_fields( $sections, $option_name = '' ) {
332
333 $current_page = give_get_current_setting_page();
334 $current_tab = give_get_current_setting_tab();
335 $current_section = give_get_current_setting_section();
336 $groups = give_get_settings_groups();
337
338 if ( $groups ) {
339 $defaultGroup = current( array_keys( $groups ) );
340 ?>
341 <div class="give-settings-section-content">
342 <?php
343 if (count($groups) > 1) : ?>
344 <div class="give-settings-section-group-menu">
345 <ul>
346 <?php
347 foreach ($groups as $slug => $group) {
348 $current_group = ! empty($_GET['group']) ? give_clean($_GET['group']) : $defaultGroup;
349 $active_class = ($slug === $current_group) ? 'active' : '';
350
351 echo sprintf(
352 '<li><a class="%1$s" href="%2$s" data-group="%3$s">%4$s</a></li>',
353 esc_html($active_class),
354 esc_url(admin_url("edit.php?post_type=give_forms&page={$current_page}&tab={$current_tab}&section={$current_section}&group={$slug}")),
355 esc_html($slug),
356 esc_html($group)
357 );
358 }
359 ?>
360 </ul>
361 </div>
362 <?php
363 endif; ?>
364 <div class="give-settings-section-group-content">
365 <?php
366 foreach ( $sections as $group => $fields ) {
367 $current_group = ! empty( $_GET['group'] ) ? give_clean( $_GET['group'] ) : $defaultGroup;
368 $hide_class = $group !== $current_group ? 'give-hidden' : '';
369
370 printf(
371 '<div id="give-settings-section-group-%1$s" class="give-settings-section-group %2$s">',
372 esc_attr( $group ),
373 esc_html( $hide_class )
374 );
375
376 /**
377 * Filter sub group settings.
378 *
379 * @since 2.8.0
380 */
381 $subGroups = apply_filters( "give_get_groups_{$current_section}_{$group}", [] );
382
383 if ( $subGroups ) {
384 $subGroupIds = array_keys( $subGroups );
385 $defaultSubGroup = current( $subGroupIds );
386 $lastSubGroupId = end( $subGroupIds );
387
388 echo '<ul class="give-subsubsub">';
389 foreach ( $subGroups as $id => $label ) {
390 $separator = $lastSubGroupId === $id ? '' : '&nbsp;|&nbsp;';
391 $currentSubGroup = ! empty( $_GET['sub-group'] ) ? give_clean( $_GET['sub-group'] ) : $defaultSubGroup;
392 $class = $id === $currentSubGroup ? 'current' : '';
393 printf(
394 '<li><a data-subgroup="%1$s" href="%2$s" class="%5$s">%3$s</a>%4$s</li>',
395 $id,
396 esc_url( admin_url( "edit.php?post_type=give_forms&page={$current_page}&tab={$current_tab}&section={$current_section}&group={$group}&sub-group={$id}" ) ),
397 $label,
398 $separator,
399 $class
400 );
401 }
402 echo '</ul>';
403
404 foreach ( $fields as $id => $subgroup ) {
405 $current_group = ! empty( $_GET['sub-group'] ) ? give_clean( $_GET['sub-group'] ) : $defaultSubGroup;
406 $hide_class = $id !== $current_group ? 'give-hidden' : '';
407
408 printf(
409 '<div id="give-settings-section-subgroup-%1$s" class="give-settings-section-subgroup %2$s">',
410 esc_attr( $id ),
411 esc_html( $hide_class )
412 );
413
414 foreach ( $subgroup as $setting ) {
415 if ( ! isset( $setting['type'] ) ) {
416 continue;
417 }
418 self::prepare_settings_field( $setting, $option_name );
419 }
420
421 echo '</div>';
422 }
423 } else {
424 foreach ( $fields as $value ) {
425 if ( ! isset( $value['type'] ) ) {
426 continue;
427 }
428 self::prepare_settings_field( $value, $option_name );
429 }
430 }
431
432 echo '</div>';
433 }
434 ?>
435 </div>
436 </div>
437 <?php
438 } else {
439
440 // Loop through each section.
441 foreach ( $sections as $value ) {
442 if ( ! isset( $value['type'] ) ) {
443 continue;
444 }
445 self::prepare_settings_field( $value, $option_name );
446 }
447 }
448
449 }
450
451 /**
452 * This function will help you prepare the admin settings field.
453 *
454 * @since 4.1.0 Added support for code editor field.
455 * @since 2.5.5
456 *
457 * @param array $value Settings Field Array.
458 * @param string $option_name Option Name.
459 *
460 * @return mixed
461 */
462 public static function prepare_settings_field( $value, $option_name ) {
463
464 $current_tab = give_get_current_setting_tab();
465
466 // Field Default values.
467 $defaults = [
468 'id' => '',
469 'class' => '',
470 'css' => '',
471 'default' => '',
472 'desc' => '',
473 'table_html' => true,
474 'repeat' => false,
475 'repeat_btn_title' => __( 'Add Field', 'give' ),
476 ];
477
478 // Set title.
479 $defaults['title'] = isset( $value['name'] ) ? $value['name'] : '';
480
481 // Set default setting.
482 $value = wp_parse_args( $value, $defaults );
483
484 // Colorpicker field.
485 $value['class'] = ( 'colorpicker' === $value['type'] ? trim( $value['class'] ) . ' give-colorpicker' : $value['class'] );
486 $value['type'] = ( 'colorpicker' === $value['type'] ? 'text' : $value['type'] );
487
488 // Custom attribute handling.
489 $custom_attributes = [];
490
491 if ( ! empty( $value['attributes'] ) && is_array( $value['attributes'] ) ) {
492 foreach ( $value['attributes'] as $attribute => $attribute_value ) {
493 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
494 }
495 }
496
497 // Description handling.
498 $description = self::get_field_description( $value );
499
500 // Switch based on type.
501 switch ( $value['type'] ) {
502
503 // Section Titles.
504 case 'title':
505 if ( ! empty( $value['title'] ) || ! empty( $value['desc'] ) ) {
506 ?>
507 <div class="give-setting-tab-header give-setting-tab-header-<?php echo $current_tab; ?>">
508 <?php if ( ! empty( $value['title'] ) ) : ?>
509 <h2><?php echo self::get_field_title( $value ); ?></h2>
510 <hr>
511 <?php endif; ?>
512
513 <?php if ( ! empty( $value['desc'] ) ) : ?>
514 <?php echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) ); ?>
515 <?php endif; ?>
516 </div>
517 <?php
518 }
519
520 if ( $value['table_html'] ) {
521 echo '<table class="form-table give-setting-tab-body give-setting-tab-body-' . $current_tab . '">' . "\n\n";
522 }
523
524 if ( ! empty( $value['id'] ) ) {
525
526 /**
527 * Trigger Action.
528 *
529 * Note: action dynamically fire on basis of field id.
530 *
531 * @since 1.8
532 */
533 do_action( 'give_settings_' . sanitize_title( $value['id'] ) );
534 }
535
536 break;
537
538 // Section Ends.
539 case 'sectionend':
540 if ( ! empty( $value['id'] ) ) {
541
542 /**
543 * Trigger Action.
544 *
545 * Note: action dynamically fire on basis of field id.
546 *
547 * @since 1.8
548 */
549 do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_end' );
550 }
551
552 if ( $value['table_html'] ) {
553 echo '</table>';
554 }
555
556 if ( ! empty( $value['id'] ) ) {
557
558 /**
559 * Trigger Action.
560 *
561 * Note: action dynamically fire on basis of field id.
562 *
563 * @since 1.8
564 */
565 do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_after' );
566 }
567
568 break;
569
570 // Standard text inputs and subtypes like 'number'.
571 case 'colorpicker':
572 case 'hidden':
573 $value['wrapper_class'] = empty( $value['wrapper_class'] ) ? 'give-hidden' : trim( $value['wrapper_class'] ) . ' give-hidden';
574 case 'text':
575 case 'email':
576 case 'number':
577 case 'password':
578 $type = $value['type'];
579 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
580
581 // Set default value for repeater field if not any value set yet.
582 if ( $value['repeat'] && is_string( $option_value ) ) {
583 $option_value = [ $value['default'] ];
584 }
585 ?>
586 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
587 <th scope="row" class="titledesc">
588 <label
589 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
590 </th>
591 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?>">
592 <?php if ( $value['repeat'] ) : ?>
593 <?php foreach ( $option_value ?: [''] as $index => $field_value ) : ?>
594 <p>
595 <input
596 name="<?php echo esc_attr( $value['id'] ); ?>[]"
597 type="<?php echo esc_attr( $type ); ?>"
598 style="<?php echo esc_attr( $value['css'] ); ?>"
599 value="<?php echo esc_attr( $field_value ); ?>"
600 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?> <?php echo esc_attr( $value['id'] ); ?>"
601 <?php echo implode( ' ', $custom_attributes ); ?>
602 />
603 <span class="give-remove-setting-field"
604 title="<?php esc_html_e( 'Remove setting field', 'give' ); ?>">-</span>
605 </p>
606 <?php endforeach; ?>
607 <a href="#" data-id="<?php echo $value['id']; ?>"
608 class="give-repeat-setting-field button-secondary"><?php echo $value['repeat_btn_title']; ?></a>
609 <?php else : ?>
610 <input
611 name="<?php echo esc_attr( $value['id'] ); ?>"
612 id="<?php echo esc_attr( $value['id'] ); ?>"
613 type="<?php echo esc_attr( $type ); ?>"
614 style="<?php echo esc_attr( $value['css'] ); ?>"
615 value="<?php echo esc_attr( $option_value ); ?>"
616 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
617 <?php echo implode( ' ', $custom_attributes ); ?>
618 />
619 <?php endif; ?>
620 <?php echo $description; ?>
621 </td>
622 </tr>
623 <?php
624 break;
625
626 // Textarea.
627 case 'textarea':
628 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
629 $default_attributes = [
630 'rows' => 10,
631 'cols' => 60,
632 ];
633 $textarea_attributes = isset( $value['attributes'] ) ? $value['attributes'] : [];
634 ?>
635 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
636 <th scope="row" class="titledesc">
637 <label
638 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
639 </th>
640 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?>">
641 <textarea
642 name="<?php echo esc_attr( $value['id'] ); ?>"
643 id="<?php echo esc_attr( $value['id'] ); ?>"
644 style="<?php echo esc_attr( $value['css'] ); ?>"
645 class="<?php echo esc_attr( $value['class'] ); ?>"
646 <?php echo give_get_attribute_str( $textarea_attributes, $default_attributes ); ?>
647 ><?php echo esc_textarea( $option_value ); ?></textarea>
648 <?php echo $description; ?>
649 </td>
650 </tr>
651 <?php
652 break;
653
654 // Code Editor.
655 case 'code_editor':
656 $option_value = self::get_option($option_name, $value['id'], $value['default']);
657 $editor_attributes = isset($value['editor_attributes']) ? $value['editor_attributes'] : [];
658
659 wp_enqueue_code_editor([
660 'type' => $editor_attributes['mode'] ?? 'text/html',
661 ]);
662 ?>
663 <tr valign="top" <?php
664 echo ! empty($value['wrapper_class']) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
665 <th scope="row" class="titledesc">
666 <label
667 for="<?php
668 echo esc_attr($value['id']); ?>"><?php
669 echo self::get_field_title($value); ?></label>
670 </th>
671 <td class="give-forminp give-forminp-<?php
672 echo sanitize_title($value['type']); ?>">
673 <textarea
674 name="<?php
675 echo esc_attr($value['id']); ?>"
676 id="<?php
677 echo esc_attr($value['id']); ?>"
678 style="<?php
679 echo esc_attr($value['css']); ?>"
680 class="<?php
681 echo esc_attr($value['class']); ?>"
682 ><?php
683 echo esc_textarea($option_value); ?></textarea>
684 <?php
685 echo $description; ?>
686
687 <script>
688 window.addEventListener('DOMContentLoaded', function() {
689 if (typeof wp.codeEditor === 'undefined') {
690 return;
691 }
692
693 wp.codeEditor.initialize(<?php echo esc_attr($value['id']); ?>, {
694 codeEditor: {
695 mode: '<?php echo esc_attr($editor_attributes['mode'] ?? 'text/html'); ?>',
696 lineNumbers: <?php echo esc_attr(
697 $editor_attributes['lineNumbers'] ?? true
698 ); ?>,
699 lineWrapping: <?php echo esc_attr(
700 $editor_attributes['lineWrapping'] ?? true
701 ); ?>,
702 autoCloseBrackets: <?php echo esc_attr(
703 $editor_attributes['autoCloseBrackets'] ?? true
704 ); ?>,
705 matchBrackets: <?php echo esc_attr(
706 $editor_attributes['matchBrackets'] ?? true
707 ); ?>,
708 indentUnit: <?php echo esc_attr($editor_attributes['indentUnit'] ?? 4); ?>,
709 tabSize: <?php echo esc_attr($editor_attributes['tabSize'] ?? 4); ?>,
710 },
711 });
712 });
713 </script>
714 </td>
715 </tr>
716 <?php
717 break;
718
719 // Select boxes.
720 case 'select':
721 case 'multiselect':
722 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
723 $setting_name = esc_attr( $value['id'] ) . ( 'multiselect' === $value['type'] ? '[]' : '' );
724
725 /**
726 * Insert page in option if missing.
727 *
728 * Check success_page setting in general settings.
729 */
730 if (
731 isset( $value['attributes'] ) &&
732 false !== strpos( $value['class'], 'give-select-chosen' ) &&
733 in_array( 'data-search-type', array_keys( $value['attributes'] ) ) &&
734 'pages' === $value['attributes']['data-search-type'] &&
735 ! in_array( $option_value, array_keys( $value['options'] ) )
736 ) {
737 $value['options'][ $option_value ] = get_the_title( $option_value );
738 }
739 ?>
740 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
741 <th scope="row" class="titledesc">
742 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
743 </th>
744 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?>">
745 <select name="<?php echo $setting_name; ?>"
746 id="<?php echo esc_attr( $value['id'] ); ?>"
747 style="<?php echo esc_attr( $value['css'] ); ?>"
748 class="<?php echo esc_attr( $value['class'] ); ?>"
749 <?php echo implode( ' ', $custom_attributes ); ?>
750 <?php echo ( 'multiselect' === $value['type'] ) ? 'multiple="multiple"' : ''; ?>
751 >
752
753 <?php
754 if ( ! empty( $value['options'] ) ) {
755 foreach ( $value['options'] as $key => $val ) {
756 ?>
757 <option value="<?php echo esc_attr( $key ); ?>"
758 <?php
759
760 if ( is_array( $option_value ) ) {
761 selected( in_array( $key, $option_value ), true );
762 } else {
763 selected( $option_value, $key );
764 }
765
766 ?>
767 ><?php echo $val; ?></option>
768 <?php
769 }
770 }
771 ?>
772
773 </select> <?php echo $description; ?>
774 </td>
775 </tr>
776 <?php
777 break;
778
779 // Radio inputs.
780 case 'radio_inline':
781 $value['class'] = empty( $value['class'] ) ? 'give-radio-inline' : $value['class'] . ' give-radio-inline';
782 case 'radio':
783 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
784 ?>
785 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
786 <th scope="row" class="titledesc">
787 <label
788 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
789 </th>
790 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
791 <fieldset>
792 <ul>
793 <?php
794 foreach ( $value['options'] as $key => $val ) {
795 ?>
796 <li>
797 <label><input
798 name="<?php echo esc_attr( $value['id'] ); ?>"
799 value="<?php echo $key; ?>"
800 type="radio"
801 style="<?php echo esc_attr( $value['css'] ); ?>"
802 <?php echo implode( ' ', $custom_attributes ); ?>
803 <?php checked( $key, $option_value ); ?>
804 /> <?php echo $val; ?></label>
805 </li>
806 <?php
807 }
808 ?>
809 <?php echo $description; ?>
810 </fieldset>
811 </td>
812 </tr>
813 <?php
814 break;
815
816 // Checkbox input.
817 case 'checkbox':
818 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
819 ?>
820 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
821 <th scope="row" class="titledesc">
822 <label
823 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
824 </th>
825 <td class="give-forminp">
826 <input
827 name="<?php echo esc_attr( $value['id'] ); ?>"
828 id="<?php echo esc_attr( $value['id'] ); ?>"
829 type="checkbox"
830 class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
831 value="1"
832 <?php checked( $option_value, 'on' ); ?>
833 <?php echo implode( ' ', $custom_attributes ); ?>
834 />
835 <?php echo $description; ?>
836 </td>
837 </tr>
838 <?php
839 break;
840
841 // Multi Checkbox input.
842 case 'multicheck':
843 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
844 $option_value = is_array( $option_value ) ? $option_value : [];
845 ?>
846 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
847 <th scope="row" class="titledesc">
848 <label
849 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
850 </th>
851 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
852 <fieldset>
853 <ul>
854 <?php
855 foreach ( $value['options'] as $key => $val ) {
856 ?>
857 <li>
858 <label>
859 <input
860 name="<?php echo esc_attr( $value['id'] ); ?>[]"
861 value="<?php echo $key; ?>"
862 type="checkbox"
863 style="<?php echo esc_attr( $value['css'] ); ?>"
864 <?php echo implode( ' ', $custom_attributes ); ?>
865 <?php
866 if ( in_array( $key, $option_value ) ) {
867 echo 'checked="checked"';
868 }
869 ?>
870 /> <?php echo $val; ?>
871 </label>
872 </li>
873 <?php
874 }
875 ?>
876 <?php echo $description; ?>
877 </fieldset>
878 </td>
879 </tr>
880 <?php
881 break;
882
883 // File input field.
884 case 'file':
885 case 'media':
886 $option_value = esc_url( self::get_option( $option_name, $value['id'], $value['default'] ) );
887 $button_label = sprintf( __( 'Add or Upload %s', 'give' ), ( 'file' === $value['type'] ? __( 'File', 'give' ) : __( 'Image', 'give' ) ) );
888 $fvalue = empty( $value['fvalue'] ) ? 'url' : $value['fvalue'];
889
890 $allow_media_preview_tags = [ 'jpg', 'jpeg', 'png', 'gif', 'ico' ];
891 $preview_image_src = $option_value ? ( 'id' === $fvalue ? wp_get_attachment_url( $option_value ) : $option_value ) : '';
892 $preview_image_extension = $preview_image_src ? pathinfo( $preview_image_src, PATHINFO_EXTENSION ) : '';
893 $is_show_preview = in_array( $preview_image_extension, $allow_media_preview_tags );
894 ?>
895 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
896 <th scope="row" class="titledesc">
897 <label
898 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
899 </th>
900 <td class="give-forminp">
901 <div class="give-field-wrap">
902 <label for="<?php echo $value['id']; ?>">
903 <input
904 name="<?php echo esc_attr( $value['id'] ); ?>"
905 id="<?php echo esc_attr( $value['id'] ); ?>"
906 type="text"
907 class="give-input-field<?php echo esc_attr( isset( $value['class'] ) ? ' ' . $value['class'] : '' ); ?>"
908 value="<?php echo $option_value; ?>"
909 style="<?php echo esc_attr( $value['css'] ); ?>"
910 <?php echo implode( ' ', $custom_attributes ); ?>
911 />&nbsp;&nbsp;&nbsp;&nbsp;<input class="give-upload-button button" type="button"
912 data-fvalue="<?php echo $fvalue; ?>"
913 data-field-type="<?php echo $value['type']; ?>"
914 value="<?php echo $button_label; ?>">
915 <?php echo $description; ?>
916 <div
917 class="give-image-thumb<?php echo ! $option_value || ! $is_show_preview ? ' give-hidden' : ''; ?>">
918 <span class="give-delete-image-thumb dashicons dashicons-no-alt"></span>
919 <img src="<?php echo $preview_image_src; ?>" alt="">
920 </div>
921 </label>
922 </div>
923 </td>
924 </tr>
925 <?php
926 break;
927
928 // WordPress Editor.
929 case 'wysiwyg':
930 // Get option value.
931 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
932
933 // Get editor settings.
934 $editor_settings = ! empty( $value['options'] ) ? $value['options'] : [];
935 ?>
936 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
937 <th scope="row" class="titledesc">
938 <label
939 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
940 </th>
941 <td class="give-forminp">
942 <?php wp_editor( $option_value, $value['id'], $editor_settings ); ?>
943 <?php echo $description; ?>
944 </td>
945 </tr>
946 <?php
947 break;
948
949 // Custom: Email preview buttons field.
950 case 'email_preview_buttons':
951 ?>
952 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
953 <th scope="row" class="titledesc">
954 <label
955 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
956 </th>
957 <td class="give-forminp">
958 <?php give_email_preview_buttons_callback( $value ); ?>
959 <?php echo $description; ?>
960 </td>
961 </tr>
962 <?php
963 break;
964
965 // Custom: API field.
966 case 'api':
967 give_api_callback();
968 echo $description;
969 break;
970
971 // Custom: Gateway API key.
972 case 'api_key':
973 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
974 $type = ! empty( $option_value ) ? 'password' : 'text';
975 ?>
976 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
977 <th scope="row" class="titledesc">
978 <label
979 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
980 </th>
981 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?>">
982 <input
983 name="<?php echo esc_attr( $value['id'] ); ?>"
984 id="<?php echo esc_attr( $value['id'] ); ?>"
985 type="<?php echo esc_attr( $type ); ?>"
986 style="<?php echo esc_attr( $value['css'] ); ?>"
987 value="<?php echo esc_attr( trim( $option_value ) ); ?>"
988 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
989 <?php echo implode( ' ', $custom_attributes ); ?>
990 /> <?php echo $description; ?>
991 </td>
992 </tr>
993 <?php
994 break;
995
996 // Note: only for internal use.
997 case 'chosen':
998 // Get option value.
999 $option_value = array_filter( (array) self::get_option( $option_name, $value['id'], $value['default'] ) );
1000 $wrapper_class = ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '';
1001 $type = '';
1002 $allow_new_values = ! empty( $value['allow-custom-values'] ) && (bool) $value['allow-custom-values'] ? 'data-allows-new-values="true"' : '';
1003 $name = give_get_field_name( $value );
1004 $choices = $value['options'];
1005 $value['style'] = isset( $value['style'] ) ? $value['style'] : '';
1006
1007 // Set attributes based on multiselect datatype.
1008 if ( ! empty( $value['data_type'] ) && 'multiselect' === $value['data_type'] ) {
1009 $type = 'multiple';
1010 $name .= '[]';
1011 $option_value = empty( $option_value ) ? [] : $option_value;
1012 }
1013
1014 // Add dynamically added values to options
1015 // we can add option dynamically to chosen select field. For example: "Title Prefixes"
1016 if ( $allow_new_values && $option_value ) {
1017 $choices = array_merge( array_combine( $option_value, $option_value ), $value['options'] );
1018 }
1019 ?>
1020 <tr valign="top" <?php echo $wrapper_class; ?>>
1021 <th scope="row" class="titledesc">
1022 <label for="<?php
1023 echo esc_attr($value['id']); ?>"><?php
1024 echo wp_kses_post(self::get_field_title($value)); ?></label>
1025 </th>
1026 <td class="give-forminp give-forminp-<?php echo esc_attr( $value['type'] ); ?>">
1027 <select
1028 class="give-select-chosen give-chosen-settings"
1029 style="<?php echo esc_attr( $value['style'] ); ?>"
1030 name="<?php echo esc_attr( $name ); ?>"
1031 id="<?php echo esc_attr( $value['id'] ); ?>"
1032 data-placeholder="<?php echo esc_attr__( 'Select Some Options', 'give'); ?>"
1033 <?php
1034 echo "{$type} {$allow_new_values}";
1035 echo implode( ' ', $custom_attributes );
1036 ?>
1037 >
1038 <?php
1039 foreach ( $choices as $key => $name ) {
1040 echo sprintf(
1041 '<option %1$s value="%2$s">%3$s</option>',
1042 in_array( $key, $option_value ) ? 'selected="selected"' : '',
1043 esc_attr( $key ),
1044 $name
1045 );
1046 }
1047 ?>
1048 </select>
1049 <?php echo wp_kses_post( $description ); ?>
1050 </td>
1051 </tr>
1052 <?php
1053 break;
1054
1055 // Custom: Data field.
1056 case 'data':
1057 include GIVE_PLUGIN_DIR . 'includes/admin/tools/views/html-admin-page-data.php';
1058
1059 echo $description;
1060 break;
1061
1062 // Custom: Give Docs Link field type.
1063 case 'give_docs_link':
1064 $wrapper_class = ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '';
1065 ?>
1066 <tr valign="top" <?php echo esc_html( $wrapper_class ); ?>>
1067 <td class="give-docs-link" colspan="2">
1068 <p class="give-docs-link">
1069 <a href="<?php echo esc_url( $value['url'] ); ?>" target="_blank">
1070 <?php
1071 echo sprintf(
1072 /* translators: %s Title */
1073 esc_html__( 'Need Help? See docs on "%s"', 'give' ),
1074 esc_html( $value['title'] )
1075 );
1076 ?>
1077 <span class="dashicons dashicons-editor-help"></span>
1078 </a>
1079 </p>
1080 </td>
1081 </tr>
1082 <?php
1083 break;
1084
1085 // Default: run an action
1086 // You can add or handle your custom field action.
1087 default:
1088 // Get option value.
1089 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
1090 do_action( 'give_admin_field_' . $value['type'], $value, $option_value );
1091 break;
1092 }
1093 }
1094
1095 /**
1096 * Helper function to get the formatted description for a given form field.
1097 * Plugins can call this when implementing their own custom settings types.
1098 *
1099 * @since 1.8
1100 *
1101 * @param array $value The form field value array
1102 *
1103 * @return string The HTML description of the field.
1104 */
1105 public static function get_field_description( $value ) {
1106 $description = '';
1107
1108 // Support for both 'description' and 'desc' args.
1109 $description_key = isset( $value['description'] ) ? 'description' : 'desc';
1110 $value = ( isset( $value[ $description_key ] ) && ! empty( $value[ $description_key ] ) ) ? $value[ $description_key ] : '';
1111
1112 if ( ! empty( $value ) ) {
1113 $description = '<div class="give-field-description">' . wp_kses_post( $value ) . '</div>';
1114 }
1115
1116 return $description;
1117 }
1118
1119
1120 /**
1121 * Helper function to get the formated title.
1122 * Plugins can call this when implementing their own custom settings types.
1123 *
1124 * @since 1.8
1125 *
1126 * @param array $value The form field value array
1127 *
1128 * @return array The description and tip as a 2 element array
1129 */
1130 public static function get_field_title( $value ) {
1131 $title = esc_html( $value['title'] );
1132
1133 // If html tag detected then allow them to print.
1134 if ( strip_tags( $title ) ) {
1135 $title = $value['title'];
1136 }
1137
1138 return $title;
1139 }
1140
1141 /**
1142 * Save admin fields.
1143 *
1144 * Loops though the give options array and outputs each field.
1145 *
1146 * @since 4.1.0 Added validation for code editor field.
1147 * @since 1.8
1148 *
1149 * @param array $options Options array to output
1150 * @param string $option_name Option name to save output. If empty then option will be store in there own option name i.e option id.
1151 *
1152 * @return bool
1153 */
1154 public static function save_fields( $options, $option_name = '' ) {
1155
1156 // Fetch form posted super global data.
1157 $post_data = give_clean( $_POST );
1158
1159 // Bailout, if posted data doesn't exists.
1160 if ( empty( $post_data ) ) {
1161 return false;
1162 }
1163
1164 $new_options = [];
1165 $options_keys = array_keys( $options );
1166 $is_vertical_tabs = is_array( $options_keys ) && count( $options_keys ) && ! is_numeric( $options_keys[0] );
1167
1168 if ( $is_vertical_tabs ) {
1169
1170 // Loop through each vertical tabs related field options to destructure into single array.
1171 foreach ( $options as $option ) {
1172 // Get option from a sub group (if any).
1173 if ( ! is_numeric( array_keys( $option )[0] ) ) {
1174 foreach ( $option as $subGroup ) {
1175 $new_options = array_merge( $new_options, $subGroup );
1176 }
1177 continue;
1178 }
1179
1180 $new_options = array_merge( $new_options, $option );
1181 }
1182
1183 // Assign new field options.
1184 $options = $new_options;
1185 }
1186
1187 // Options to update will be stored here and saved later.
1188 $update_options = [];
1189
1190 // Loop options and get values to save.
1191 foreach ( $options as $option ) {
1192 if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) ) {
1193 continue;
1194 }
1195
1196 // Get posted value.
1197 if ( strstr( $option['id'], '[' ) ) {
1198 parse_str( $option['id'], $option_name_array );
1199 $field_option_name = current( array_keys( $option_name_array ) );
1200 $setting_name = key( $option_name_array[ $field_option_name ] );
1201 $raw_value = isset( $_POST[ $field_option_name ][ $setting_name ] ) ? wp_unslash( $_POST[ $field_option_name ][ $setting_name ] ) : null;
1202 } else {
1203 $field_option_name = $option['id'];
1204 $setting_name = '';
1205 $raw_value = isset( $_POST[ $option['id'] ] ) ? wp_unslash( $_POST[ $option['id'] ] ) : null;
1206 }
1207
1208 // Format the value based on option type.
1209 switch ( $option['type'] ) {
1210 case 'checkbox':
1211 $value = is_null( $raw_value ) ? '' : 'on';
1212 break;
1213 case 'wysiwyg':
1214 case 'textarea':
1215 case 'code_editor':
1216 $value = wp_kses_post( trim( $raw_value ) );
1217 break;
1218 case 'multiselect':
1219 case 'chosen':
1220 $value = array_filter( array_map( 'give_clean', (array) $raw_value ) );
1221 break;
1222 default:
1223 $value = give_clean( $raw_value );
1224 break;
1225 }
1226
1227 /**
1228 * Sanitize the value of an option.
1229 *
1230 * @since 1.8
1231 */
1232 $value = apply_filters( 'give_admin_settings_sanitize_option', $value, $option, $raw_value );
1233
1234 /**
1235 * Sanitize the value of an option by option name.
1236 *
1237 * @since 1.8
1238 */
1239 $value = apply_filters( "give_admin_settings_sanitize_option_{$field_option_name}", $value, $option, $raw_value );
1240
1241 if ( is_null( $value ) ) {
1242 continue;
1243 }
1244
1245 // Check if option is an array and handle that differently to single values.
1246 if ( $field_option_name && $setting_name ) {
1247 if ( ! isset( $update_options[ $field_option_name ] ) ) {
1248 $update_options[ $field_option_name ] = get_option( $field_option_name, [] );
1249 }
1250 if ( ! is_array( $update_options[ $field_option_name ] ) ) {
1251 $update_options[ $field_option_name ] = [];
1252 }
1253 $update_options[ $field_option_name ][ $setting_name ] = $value;
1254 } else {
1255 $update_options[ $field_option_name ] = $value;
1256 }
1257 }
1258
1259 // Save all options in our array or there own option name i.e. option id.
1260 if ( empty( $option_name ) ) {
1261 foreach ( $update_options as $name => $value ) {
1262 update_option( $name, $value, false );
1263
1264 /**
1265 * Trigger action.
1266 *
1267 * Note: This is dynamically fire on basis of option name.
1268 *
1269 * @since 1.8
1270 */
1271 do_action( "give_save_option_{$name}", $value, $name );
1272 }
1273 } else {
1274 $old_options = ( $old_options = get_option( $option_name ) ) ? $old_options : [];
1275 $update_options = array_merge( $old_options, $update_options );
1276
1277 update_option( $option_name, $update_options, false );
1278
1279 /**
1280 * Trigger action.
1281 *
1282 * Note: This is dynamically fire on basis of setting name.
1283 *
1284 * @since 1.8
1285 */
1286 do_action( "give_save_settings_{$option_name}", $update_options, $option_name, $old_options );
1287 }
1288
1289 return true;
1290 }
1291
1292
1293 /**
1294 * Check if admin saving setting or not.
1295 *
1296 * @since 1.8.17
1297 *
1298 * @return bool
1299 */
1300 public static function is_saving_settings() {
1301 return self::verify_nonce();
1302 }
1303
1304 /**
1305 * Verify setting page
1306 *
1307 * @since 2.0
1308 * @access public
1309 *
1310 * @param string $tab
1311 * @param string $section
1312 *
1313 * @return bool
1314 */
1315 public static function is_setting_page( $tab = '', $section = '' ) {
1316 $is_setting_page = false;
1317
1318 // Are we accessing admin?
1319 if ( ! is_admin() ) {
1320 return $is_setting_page;
1321 }
1322
1323 // Are we accessing any give page?
1324 if (
1325 ! isset( $_GET['post_type'], $_GET['page'] )
1326 || 'give_forms' !== give_clean( $_GET['post_type'] )
1327 ) {
1328 return $is_setting_page;
1329 }
1330
1331 // Check fo setting tab.
1332 if ( ! empty( $tab ) ) {
1333 $is_setting_page = ( $tab === give_get_current_setting_tab() );
1334 }
1335
1336 // Check fo setting section.
1337 if ( ! empty( $section ) ) {
1338 $is_setting_page = ( $section === give_get_current_setting_section() );
1339 }
1340
1341 return $is_setting_page;
1342 }
1343 }
1344
1345 endif;
1346