PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.3.0
GiveWP – Donation Plugin and Fundraising Platform v2.3.0
4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.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 All 257 releases
give / includes / admin / settings / class-settings-general.php

class-settings-general.php in GiveWP – Donation Plugin and Fundraising Platform 2.3.0, at includes/admin/settings/class-settings-general.php

581 lines 20.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Give Settings Page/Tab
4 *
5 * @package Give
6 * @subpackage Classes/Give_Settings_General
7 * @copyright Copyright (c) 2016, WordImpress
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; // Exit if accessed directly.
14 }
15
16 if ( ! class_exists( 'Give_Settings_General' ) ) :
17
18 /**
19 * Give_Settings_General.
20 *
21 * @sine 1.8
22 */
23 class Give_Settings_General extends Give_Settings_Page {
24
25 /**
26 * Constructor.
27 */
28 public function __construct() {
29 $this->id = 'general';
30 $this->label = __( 'General', 'give' );
31
32 $this->default_tab = 'general-settings';
33
34 if ( $this->id === give_get_current_setting_tab() ) {
35 add_action( 'give_save_settings_give_settings', array( $this, '_give_change_donation_stating_number' ), 10, 3 );
36 add_action( 'give_admin_field_give_sequential_donation_code_preview', array( $this, '_render_give_sequential_donation_code_preview' ), 10, 3 );
37 add_action( 'give_admin_field_give_currency_preview', array( $this, '_render_give_currency_preview' ), 10, 2 );
38 add_action( 'give_admin_field_give_unlock_all_settings', array( $this, '_render_give_unlock_all_settings' ), 10, 3 );
39 }
40
41 parent::__construct();
42 }
43
44 /**
45 * Get settings array.
46 *
47 * @since 1.8
48 * @return array
49 */
50 public function get_settings() {
51 $settings = array();
52 $current_section = give_get_current_setting_section();
53
54 switch ( $current_section ) {
55 case 'access-control':
56 $settings = array(
57 // Section 3: Access control.
58 array(
59 'id' => 'give_title_session_control_1',
60 'type' => 'title',
61 ),
62 array(
63 'id' => 'session_lifetime',
64 'name' => __( 'Session Lifetime', 'give' ),
65 'desc' => __( 'The length of time a user\'s session is kept alive. Give starts a new session per user upon donation. Sessions allow donors to view their donation receipts without being logged in.', 'give' ),
66 'type' => 'select',
67 'options' => array(
68 '86400' => __( '24 Hours', 'give' ),
69 '172800' => __( '48 Hours', 'give' ),
70 '259200' => __( '72 Hours', 'give' ),
71 '604800' => __( '1 Week', 'give' ),
72 ),
73 ),
74 array(
75 'id' => 'limit_display_donations',
76 'name' => __( 'Limit Donations Displayed', 'give' ),
77 'desc' => __( 'Adjusts the number of donations displayed to a non logged-in user when they attempt to access the Donation History page without an active session. For security reasons, it\'s best to leave this at 1-3 donations.', 'give' ),
78 'default' => '1',
79 'type' => 'number',
80 'css' => 'width:50px;',
81 'attributes' => array(
82 'min' => '1',
83 'max' => '10',
84 ),
85 ),
86 array(
87 'name' => __( 'Email Access', 'give' ),
88 'desc' => __( 'Would you like your donors to be able to access their donation history using only email? Donors whose sessions have expired and do not have an account may still access their donation history via a temporary email access link.', 'give' ),
89 'id' => 'email_access',
90 'type' => 'radio_inline',
91 'default' => 'disabled',
92 'options' => array(
93 'enabled' => __( 'Enabled', 'give' ),
94 'disabled' => __( 'Disabled', 'give' ),
95 ),
96 ),
97 array(
98 'name' => __( 'Enable reCAPTCHA', 'give' ),
99 'desc' => __( 'Would you like to enable the reCAPTCHA feature?', 'give' ),
100 'id' => 'enable_recaptcha',
101 'type' => 'radio_inline',
102 'default' => 'disabled',
103 'options' => array(
104 'enabled' => __( 'Enabled', 'give' ),
105 'disabled' => __( 'Disabled', 'give' ),
106 ),
107 ),
108 array(
109 'id' => 'recaptcha_key',
110 'name' => __( 'reCAPTCHA Site Key', 'give' ),
111 /* translators: %s: https://www.google.com/recaptcha/ */
112 'desc' => sprintf( __( 'If you would like to prevent spam on the email access form navigate to <a href="%s" target="_blank">the reCAPTCHA website</a> and sign up for an API key and paste your reCAPTCHA site key here. The reCAPTCHA uses Google\'s user-friendly single click verification method.', 'give' ), esc_url( 'http://docs.givewp.com/recaptcha' ) ),
113 'default' => '',
114 'type' => 'text',
115 ),
116 array(
117 'id' => 'recaptcha_secret',
118 'name' => __( 'reCAPTCHA Secret Key', 'give' ),
119 'desc' => __( 'Please paste the reCAPTCHA secret key here from your reCAPTCHA API Keys panel.', 'give' ),
120 'default' => '',
121 'type' => 'text',
122 ),
123 array(
124 'name' => __( 'Access Control Docs Link', 'give' ),
125 'id' => 'access_control_docs_link',
126 'url' => esc_url( 'http://docs.givewp.com/settings-access-control' ),
127 'title' => __( 'Access Control', 'give' ),
128 'type' => 'give_docs_link',
129 ),
130 array(
131 'id' => 'give_title_session_control_1',
132 'type' => 'sectionend',
133 ),
134 );
135 break;
136
137 case 'currency-settings' :
138 $currency_position_before = __( 'Before - %s&#x200e;10', 'give' );
139 $currency_position_after = __( 'After - 10%s&#x200f;', 'give' );
140
141 $settings = array(
142 // Section 2: Currency
143 array(
144 'type' => 'title',
145 'id' => 'give_title_general_settings_2',
146 ),
147 array(
148 'name' => __( 'Currency Settings', 'give' ),
149 'desc' => '',
150 'type' => 'give_title',
151 'id' => 'give_title_general_settings_2',
152 ),
153 array(
154 'name' => __( 'Currency', 'give' ),
155 'desc' => __( 'The donation currency. Note that some payment gateways have currency restrictions.', 'give' ),
156 'id' => 'currency',
157 'class' => 'give-select-chosen',
158 'type' => 'select',
159 'options' => give_get_currencies(),
160 'default' => 'USD',
161 ),
162 array(
163 'name' => __( 'Currency Position', 'give' ),
164 'desc' => __( 'The position of the currency symbol.', 'give' ),
165 'id' => 'currency_position',
166 'type' => 'select',
167 'options' => array(
168 /* translators: %s: currency symbol */
169 'before' => sprintf( $currency_position_before, give_currency_symbol( give_get_currency() ) ),
170 /* translators: %s: currency symbol */
171 'after' => sprintf( $currency_position_after, give_currency_symbol( give_get_currency() ) ),
172 ),
173 'default' => 'before',
174 'attributes' => array(
175 'data-before-template' => sprintf( $currency_position_before, '{currency_pos}' ),
176 'data-after-template' => sprintf( $currency_position_after, '{currency_pos}' ),
177 ),
178 ),
179 array(
180 'name' => __( 'Thousands Separator', 'give' ),
181 'desc' => __( 'The symbol (typically , or .) to separate thousands.', 'give' ),
182 'id' => 'thousands_separator',
183 'type' => 'text',
184 'default' => ',',
185 'css' => 'width:12em;',
186 ),
187 array(
188 'name' => __( 'Decimal Separator', 'give' ),
189 'desc' => __( 'The symbol (usually , or .) to separate decimal points.', 'give' ),
190 'id' => 'decimal_separator',
191 'type' => 'text',
192 'default' => '.',
193 'css' => 'width:12em;',
194 ),
195 array(
196 'name' => __( 'Number of Decimals', 'give' ),
197 'desc' => __( 'The number of decimal points displayed in amounts.', 'give' ),
198 'id' => 'number_decimals',
199 'type' => 'text',
200 'default' => 2,
201 'css' => 'width:12em;',
202 ),
203 array(
204 'name' => __( 'Currency Preview', 'give' ),
205 'desc' => __( 'A preview of the formatted currency. This preview cannot be edited directly as it is generated from the settings above.', 'give' ),
206 'id' => 'currency_preview',
207 'type' => 'give_currency_preview',
208 'default' => give_format_amount( 123456.12345,
209 array(
210 'sanitize' => false,
211 'currency' => give_get_option( 'currency' ),
212 )
213 ),
214 'css' => 'width:12em;',
215 ),
216 array(
217 'name' => __( 'Currency Options Docs Link', 'give' ),
218 'id' => 'currency_settings_docs_link',
219 'url' => esc_url( 'http://docs.givewp.com/settings-currency' ),
220 'title' => __( 'Currency Settings', 'give' ),
221 'type' => 'give_docs_link',
222 ),
223 array(
224 'type' => 'sectionend',
225 'id' => 'give_title_general_settings_2',
226 ),
227 );
228
229 break;
230
231 case 'general-settings':
232 // Get default country code.
233 $countries = give_get_country();
234
235 // get the list of the states of which default country is selected.
236 $states = give_get_states( $countries );
237
238 // Get the country list that does not have any states init.
239 $no_states_country = give_no_states_country_list();
240
241 $states_label = give_get_states_label();
242 $country = give_get_country();
243 $label = __( 'State', 'give' );
244 // Check if $country code exists in the array key for states label.
245 if ( array_key_exists( $country, $states_label ) ) {
246 $label = $states_label[ $country ];
247 }
248
249
250 $settings = array(
251 // Section 1: General.
252 array(
253 'type' => 'title',
254 'id' => 'give_title_general_settings_1',
255 ),
256 array(
257 'name' => __( 'General Settings', 'give' ),
258 'desc' => '',
259 'type' => 'give_title',
260 'id' => 'give_title_general_settings_1',
261 ),
262 array(
263 'name' => __( 'Success Page', 'give' ),
264 /* translators: %s: [give_receipt] */
265 'desc' => sprintf( __( 'The page donors are sent to after completing their donations. The %s shortcode should be on this page.', 'give' ), '<code>[give_receipt]</code>' ),
266 'id' => 'success_page',
267 'class' => 'give-select give-select-chosen',
268 'type' => 'select',
269 'options' => give_cmb2_get_post_options( array(
270 'post_type' => 'page',
271 'numberposts' => 30,
272 ) ),
273 'attributes' => array(
274 'data-search-type' => 'pages'
275 )
276 ),
277 array(
278 'name' => __( 'Failed Donation Page', 'give' ),
279 'desc' => __( 'The page donors are sent to if their donation is cancelled or fails.', 'give' ),
280 'class' => 'give-select give-select-chosen',
281 'id' => 'failure_page',
282 'type' => 'select',
283 'options' => give_cmb2_get_post_options( array(
284 'post_type' => 'page',
285 'numberposts' => 30,
286 ) ),
287 'attributes' => array(
288 'data-search-type' => 'pages'
289 )
290 ),
291 array(
292 'name' => __( 'Donation History Page', 'give' ),
293 /* translators: %s: [donation_history] */
294 'desc' => sprintf( __( 'The page showing a complete donation history for the current user. The %s shortcode should be on this page.', 'give' ), '<code>[donation_history]</code>' ),
295 'id' => 'history_page',
296 'class' => 'give-select give-select-chosen',
297 'type' => 'select',
298 'options' => give_cmb2_get_post_options( array(
299 'post_type' => 'page',
300 'numberposts' => 30,
301 ) ),
302 'attributes' => array(
303 'data-search-type' => 'pages'
304 )
305 ),
306 array(
307 'name' => __( 'Base Country', 'give' ),
308 'desc' => __( 'The country your site operates from.', 'give' ),
309 'id' => 'base_country',
310 'type' => 'select',
311 'options' => give_get_country_list(),
312 'class' => 'give-select give-select-chosen',
313 'attributes' => array(
314 'data-search-type' => 'no_ajax'
315 ),
316 'default' => $country,
317 ),
318 /**
319 * Add base state to give setting
320 *
321 * @since 1.8.14
322 */
323 array(
324 'wrapper_class' => ( array_key_exists( $countries, $no_states_country ) ? 'give-hidden' : '' ),
325 'name' => __( 'Base State/Province', 'give' ),
326 'desc' => __( 'The state/province your site operates from.', 'give' ),
327 'id' => 'base_state',
328 'type' => ( empty( $states ) ? 'text' : 'select' ),
329 'class' => ( empty( $states ) ? '' : 'give-select give-select-chosen' ),
330 'options' => $states,
331 'attributes' => array(
332 'data-search-type' => 'no_ajax',
333 'data-placeholder' => $label,
334 ),
335 ),
336 array(
337 'name' => __( 'General Options Docs Link', 'give' ),
338 'id' => 'general_options_docs_link',
339 'url' => esc_url( 'http://docs.givewp.com/settings-general' ),
340 'title' => __( 'General Options', 'give' ),
341 'type' => 'give_docs_link',
342 ),
343 array(
344 'type' => 'sectionend',
345 'id' => 'give_title_general_settings_1',
346 ),
347 );
348 break;
349
350 case 'sequential-ordering':
351 $settings = array(
352
353 // Section 4: Sequential Ordering
354
355 array(
356 'id' => 'give_title_general_settings_4',
357 'type' => 'title'
358 ),
359 array(
360 'name' => __( 'Sequential Ordering', 'give' ),
361 'id' => "{$current_section}_status",
362 'desc' => __( 'Custom donation numbering that increases sequentially to prevent gaps between donation IDs. If disabled, then donation numbers are generated from WordPress post IDs, which will result in gaps between numbers.', 'give' ),
363 'type' => 'radio_inline',
364 'default' => 'disabled',
365 'options' => array(
366 'enabled' => __( 'Enabled', 'give' ),
367 'disabled' => __( 'Disabled', 'give' )
368 )
369 ),
370 array(
371 'name' => __( 'Next Donation Number', 'give' ),
372 'id' => "{$current_section}_number",
373 'desc' => sprintf(
374 __( 'The number used to generate the next donation ID. This value must be greater than or equal to %s to avoid conflicts with existing donation IDs.', 'give' ),
375 '<code>' . Give()->seq_donation_number->get_next_number() . '</code>'
376 ),
377 'type' => 'number',
378 ),
379 array(
380 'name' => __( 'Number Prefix', 'give' ),
381 'id' => "{$current_section}_number_prefix",
382 'desc' => sprintf(
383 __( 'The prefix appended to all sequential donation numbers. Spaces are replaced by %s.', 'give' ),
384 '<code>-</code>'
385 ),
386 'type' => 'text',
387 ),
388 array(
389 'name' => __( 'Number Suffix', 'give' ),
390 'id' => "{$current_section}_number_suffix",
391 'desc' => sprintf(
392 __( 'The suffix appended to all sequential donation numbers. Spaces are replaced by %s.', 'give' ),
393 '<code>-</code>'
394 ),
395 'type' => 'text',
396 ),
397 array(
398 'name' => __( 'Number Padding', 'give' ),
399 'id' => "{$current_section}_number_padding",
400 'desc' => sprintf(
401 __( 'The minimum number of digits in the sequential donation number. Enter %s to display %s as %s.', 'give' ),
402 '<code>4</code>',
403 '<code>1</code>',
404 '<code>0001</code>'
405 ),
406 'type' => 'number',
407 'default' => '0',
408 ),
409 array(
410 'name' => __( 'Donation ID Preview', 'give' ),
411 'id' => "{$current_section}_preview",
412 'type' => 'give_sequential_donation_code_preview',
413 'desc' => __( 'A preview of the next sequential donation ID. This preview cannot be edited directly as it is generated from the settings above.', 'give' ),
414 ),
415 array(
416 'name' => __( 'Sequential Ordering Docs Link', 'give' ),
417 'id' => "{$current_section}_doc link",
418 'url' => esc_url( 'http://docs.givewp.com/settings-sequential-ordering' ),
419 'title' => __( 'Sequential Ordering', 'give' ),
420 'type' => 'give_docs_link',
421 ),
422 array(
423 'id' => 'give_title_general_settings_4',
424 'type' => 'sectionend'
425 )
426 );
427 }
428
429 /**
430 * Filter the general settings.
431 * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8
432 */
433 $settings = apply_filters( 'give_settings_general', $settings );
434
435 /**
436 * Filter the settings.
437 *
438 * @since 1.8
439 *
440 * @param array $settings
441 */
442 $settings = apply_filters( 'give_get_settings_' . $this->id, $settings );
443
444 // Output.
445 return $settings;
446 }
447
448 /**
449 * Get sections.
450 *
451 * @since 1.8
452 * @return array
453 */
454 public function get_sections() {
455 $sections = array(
456 'general-settings' => __( 'General', 'give' ),
457 'currency-settings' => __( 'Currency', 'give' ),
458 'access-control' => __( 'Access Control', 'give' ),
459 'sequential-ordering' => __( 'Sequential Ordering', 'give' ),
460 );
461
462 return apply_filters( 'give_get_sections_' . $this->id, $sections );
463 }
464
465
466 /**
467 * Set flag to reset sequestion donation number starting point when "Sequential Starting Number" value changes
468 *
469 * @since 2.1
470 * @access public
471 *
472 * @param $update_options
473 * @param $option_name
474 * @param $old_options
475 *
476 * @return bool
477 */
478 public function _give_change_donation_stating_number( $update_options, $option_name, $old_options ) {
479 if ( ! isset( $_POST['sequential-ordering_number'] ) ) {
480 return false;
481 }
482
483 if ( ( $next_number = Give()->seq_donation_number->get_next_number() ) > $update_options['sequential-ordering_number'] ) {
484 give_update_option( 'sequential-ordering_number', $next_number );
485
486 Give_Admin_Settings::add_error(
487 'give-invalid-sequential-starting-number',
488 sprintf(
489 __( 'Next Donation Number must be equal to or larger than %s to avoid conflicts with existing donation IDs.', 'give' ),
490 $next_number
491 )
492 );
493 } elseif ( $update_options['sequential-ordering_number'] !== $old_options['sequential-ordering_number'] ) {
494 update_option( '_give_reset_sequential_number', 1, false );
495 }
496
497 return true;
498 }
499
500 /**
501 * Render give_sequential_donation_code_preview field type
502 *
503 * @since 2.1.0
504 * @access public
505 *
506 * @param $field
507 */
508 public function _render_give_sequential_donation_code_preview( $field ) {
509 ?>
510 <tr valign="top" <?php echo ! empty( $field['wrapper_class'] ) ? 'class="' . $field['wrapper_class'] . '"' : '' ?>>
511 <th scope="row" class="titledesc">
512 <label
513 for="<?php echo esc_attr( $field['id'] ); ?>"><?php echo esc_html( $field['name'] ) ?></label>
514 </th>
515 <td class="give-forminp">
516 <input id="<?php echo esc_attr( $field['id'] ); ?>" class="give-input-field" type="text" disabled>
517 <?php echo Give_Admin_Settings::get_field_description( $field ); ?>
518 </td>
519 </tr>
520 <?php
521 }
522
523 /**
524 * Render give_currency_code_preview field type
525 *
526 * @since 2.3.0
527 * @access public
528 *
529 * @param array $field Field Attributes array.
530 *
531 * @return void
532 */
533 public function _render_give_currency_preview( $field, $value ) {
534 $currency = give_get_currency();
535 $currency_position = give_get_currency_position();
536 $currency_symbol = give_currency_symbol( $currency, false );
537 $formatted_currency = ( 'before' === $currency_position )
538 ? sprintf( '%1$s%2$s', esc_html( $currency_symbol ), esc_html( $field['default'] ) )
539 : sprintf( '%1$s%2$s', esc_html( $field['default'] ), esc_html( $currency_symbol ) );
540 ?>
541 <tr valign="top" <?php echo ! empty( $field['wrapper_class'] ) ? 'class="' . $field['wrapper_class'] . '"' : '' ?>>
542 <th scope="row" class="titledesc">
543 <label
544 for="<?php echo esc_attr( $field['id'] ); ?>"><?php echo esc_html( $field['name'] ) ?></label>
545 </th>
546 <td class="give-forminp">
547 <input id="<?php echo esc_attr( $field['id'] ); ?>" class="give-input-field" type="text" disabled value="<?php echo esc_attr( $formatted_currency ); ?>">
548 <?php echo Give_Admin_Settings::get_field_description( $field ); ?>
549 </td>
550 </tr>
551 <?php
552 }
553
554 /**
555 * Render give_unlock_all_settings field type
556 *
557 * @since 2.1.0
558 * @access public
559 *
560 * @param $field
561 */
562 public function _render_give_unlock_all_settings( $field ) {
563 ?>
564 <tr valign="top" <?php echo ! empty( $field['wrapper_class'] ) ? 'class="' . $field['wrapper_class'] . '"' : '' ?>>
565 <th scope="row" class="titledesc">
566 <label
567 for="<?php echo esc_attr( $field['id'] ); ?>"><?php echo esc_html( $field['name'] ) ?></label>
568 </th>
569 <td class="give-forminp">
570 <?php echo Give_Admin_Settings::get_field_description( $field ); ?>
571 <a href="" id="<?php echo $field['id']; ?>" data-message="<?php echo $field['confirmation_msg'] ?>"><?php echo __( 'Unlock all settings', 'give' ); ?></a>
572 </td>
573 </tr>
574 <?php
575 }
576 }
577
578 endif;
579
580 return new Give_Settings_General();
581