PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.2.4
GiveWP – Donation Plugin and Fundraising Platform v2.2.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 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-give-settings.php
give / includes / admin Last commit date
donors 7 years ago emails 7 years ago forms 7 years ago payments 7 years ago reports 7 years ago settings 7 years ago shortcodes 7 years ago tools 7 years ago upgrades 7 years ago views 8 years ago EDD_SL_Plugin_Updater.php 7 years ago abstract-admin-settings-page.php 8 years ago add-ons.php 8 years ago admin-actions.php 7 years ago admin-filters.php 8 years ago admin-footer.php 8 years ago admin-pages.php 8 years ago class-addon-activation-banner.php 7 years ago class-admin-settings.php 7 years ago class-api-keys-table.php 8 years ago class-blank-slate.php 8 years ago class-give-settings.php 7 years ago class-i18n-module.php 8 years ago dashboard-widgets.php 8 years ago give-metabox-functions.php 7 years ago plugins.php 7 years ago welcome.php 8 years ago
class-give-settings.php
1574 lines
1 <?php
2
3 /**
4 * Class Give_Plugin_Settings
5 *
6 * Register settings Include and setup custom metaboxes and fields.
7 *
8 * @package Give
9 * @subpackage Admin
10 * @license https://opensource.org/licenses/gpl-license GNU Public License
11 * @link https://github.com/webdevstudios/Custom-Metaboxes-and-Fields-for-WordPress
12 *
13 * @property $key
14 * @property $title
15 * @property $options_page
16 */
17 class Give_Plugin_Settings {
18
19 /**
20 * Option key, and option page slug.
21 *
22 * @var string
23 */
24 private $key = 'give_settings';
25
26 /**
27 * Options Page title.
28 *
29 * @var string
30 */
31 protected $title = '';
32
33 /**
34 * Options Page hook.
35 *
36 * @var string
37 */
38 protected $options_page = '';
39
40 /**
41 * Give_Plugin_Settings constructor.
42 */
43 public function __construct() {
44
45 // Custom settings fields.
46 add_action( 'cmb2_render_give_title', 'give_title_callback', 10, 5 );
47 add_action( 'cmb2_render_give_description', 'give_description_callback', 10, 5 );
48 add_action( 'cmb2_render_enabled_gateways', 'give_enabled_gateways_callback', 10, 5 );
49 add_action( 'cmb2_render_default_gateway', 'give_default_gateway_callback', 10, 5 );
50 add_action( 'cmb2_render_email_preview_buttons', 'give_email_preview_buttons_callback', 10, 5 );
51 add_action( 'cmb2_render_system_info', 'give_system_info_callback', 10, 5 );
52 add_action( 'cmb2_render_api', 'give_api_callback', 10, 5 );
53 add_action( 'cmb2_render_license_key', 'give_license_key_callback', 10, 5 );
54 }
55
56
57 /**
58 * Register our setting to WP
59 *
60 * @since 1.0
61 */
62 public function init() {
63 register_setting( $this->key, $this->key );
64
65 }
66
67
68 /**
69 * Filter CMB2 URL
70 *
71 * Required for CMB2 to properly load CSS/JS.
72 *
73 * @param $url
74 *
75 * @return mixed
76 */
77 public function give_update_cmb_meta_box_url( $url ) {
78 // Path to Give's CMB
79 return GIVE_PLUGIN_URL . '/includes/libraries/cmb2';
80 }
81
82
83 /**
84 * Retrieve settings tabs
85 *
86 * @since 1.0
87 * @return array $tabs
88 */
89 public function give_get_settings_tabs() {
90
91 $settings = $this->give_settings( null );
92
93 $tabs = array();
94 $tabs['general'] = __( 'General', 'give' );
95 $tabs['gateways'] = __( 'Payment Gateways', 'give' );
96 $tabs['display'] = __( 'Display Options', 'give' );
97 $tabs['emails'] = __( 'Emails', 'give' );
98
99 if ( ! empty( $settings['addons']['fields'] ) ) {
100 $tabs['addons'] = __( 'Add-ons', 'give' );
101 }
102
103 if ( ! empty( $settings['licenses']['fields'] ) ) {
104 $tabs['licenses'] = __( 'Licenses', 'give' );
105 }
106
107 $tabs['advanced'] = __( 'Advanced', 'give' );
108 $tabs['api'] = __( 'API', 'give' );
109 $tabs['system_info'] = __( 'System Info', 'give' );
110
111 return apply_filters( 'give_settings_tabs', $tabs );
112 }
113
114
115 /**
116 * Admin page markup. Mostly handled by CMB2
117 *
118 * @since 1.0
119 */
120 public function admin_page_display() {
121
122 $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $this->give_get_settings_tabs() ) ? $_GET['tab'] : 'general';
123
124 ?>
125
126 <div class="wrap give_settings_page cmb2_options_page <?php echo $this->key; ?>">
127
128 <h1 class="screen-reader-text"><?php echo get_admin_page_title(); ?></h1>
129
130 <h2 class="nav-tab-wrapper">
131 <?php
132 foreach ( $this->give_get_settings_tabs() as $tab_id => $tab_name ) {
133
134 $tab_url = esc_url(
135 add_query_arg(
136 array(
137 'settings-updated' => false,
138 'tab' => $tab_id,
139 )
140 )
141 );
142
143 $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
144
145 echo '<a href="' . esc_url( $tab_url ) . '" class="nav-tab' . $active . '" id="tab-' . $tab_id . '">' . esc_html( $tab_name ) . '</a>';
146
147 }
148 ?>
149 </h2>
150
151 <?php cmb2_metabox_form( $this->give_settings( $active_tab ), $this->key ); ?>
152
153 </div><!-- .wrap -->
154
155 <?php
156 }
157
158
159 /**
160 *
161 * Modify CMB2 Default Form Output
162 *
163 * @param string @args
164 *
165 * @since 1.0
166 *
167 * @param $form_format
168 * @param $object_id
169 * @param $cmb
170 *
171 * @return string
172 */
173 function give_modify_cmb2_form_output( $form_format, $object_id, $cmb ) {
174
175 // only modify the give settings form
176 if ( 'give_settings' == $object_id ) {
177
178 return '<form class="cmb-form" method="post" id="%1$s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="give_settings_saved" value="true"><input type="hidden" name="object_id" value="%2$s">%3$s<div class="give-submit-wrap"><input type="submit" name="submit-cmb" value="' . esc_attr__( 'Save Settings', 'give' ) . '" class="button-primary"></div></form>';
179
180 }
181
182 return $form_format;
183
184 }
185
186 /**
187 * Define General Settings Metabox and field configurations.
188 *
189 * Filters are provided for each settings section to allow add-ons and other plugins to add their own settings
190 *
191 * @param $active_tab |string active tab settings; null returns full array
192 *
193 * @return array
194 */
195 public function give_settings( $active_tab ) {
196
197 $give_settings = array(
198 /**
199 * General Settings
200 */
201 'general' => array(
202 'id' => 'general_settings',
203 'give_title' => __( 'General Settings', 'give' ),
204 'show_on' => array(
205 'key' => 'options-page',
206 'value' => array( $this->key ),
207 ),
208 'fields' => apply_filters(
209 'give_settings_general', array(
210 array(
211 'name' => __( 'General Settings', 'give' ),
212 'desc' => '',
213 'type' => 'give_title',
214 'id' => 'give_title_general_settings_1',
215 ),
216 array(
217 'name' => __( 'Success Page', 'give' ),
218 /* translators: %s: [give_receipt] */
219 '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>' ),
220 'id' => 'success_page',
221 'type' => 'select',
222 'options' => give_cmb2_get_post_options(
223 array(
224 'post_type' => 'page',
225 'numberposts' => 999,
226 )
227 ),
228 ),
229 array(
230 'name' => __( 'Failed Donation Page', 'give' ),
231 'desc' => __( 'The page donors are sent to if their donation is cancelled or fails.', 'give' ),
232 'id' => 'failure_page',
233 'type' => 'select',
234 'options' => give_cmb2_get_post_options(
235 array(
236 'post_type' => 'page',
237 'numberposts' => 999,
238 )
239 ),
240 ),
241 array(
242 'name' => __( 'Donation History Page', 'give' ),
243 /* translators: %s: [donation_history] */
244 '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>' ),
245 'id' => 'history_page',
246 'type' => 'select',
247 'options' => give_cmb2_get_post_options(
248 array(
249 'post_type' => 'page',
250 'numberposts' => 999,
251 )
252 ),
253 ),
254 array(
255 'name' => __( 'Base Country', 'give' ),
256 'desc' => __( 'The country your site operates from.', 'give' ),
257 'id' => 'base_country',
258 'type' => 'select',
259 'options' => give_get_country_list(),
260 ),
261 array(
262 'name' => __( 'Currency Settings', 'give' ),
263 'desc' => '',
264 'type' => 'give_title',
265 'id' => 'give_title_general_settings_2',
266 ),
267 array(
268 'name' => __( 'Currency', 'give' ),
269 'desc' => __( 'The donation currency. Note that some payment gateways have currency restrictions.', 'give' ),
270 'id' => 'currency',
271 'type' => 'select',
272 'options' => give_get_currencies(),
273 'default' => 'USD',
274 ),
275 array(
276 'name' => __( 'Currency Position', 'give' ),
277 'desc' => __( 'The position of the currency symbol.', 'give' ),
278 'id' => 'currency_position',
279 'type' => 'select',
280 'options' => array(
281 /* translators: %s: currency symbol */
282 'before' => sprintf( __( 'Before - %s&#x200e;10', 'give' ), give_currency_symbol( give_get_currency() ) ),
283 /* translators: %s: currency symbol */
284 'after' => sprintf( __( 'After - 10%s&#x200f;', 'give' ), give_currency_symbol( give_get_currency() ) ),
285 ),
286 'default' => 'before',
287 ),
288 array(
289 'name' => __( 'Thousands Separator', 'give' ),
290 'desc' => __( 'The symbol (usually , or .) to separate thousands.', 'give' ),
291 'id' => 'thousands_separator',
292 'type' => 'text_small',
293 'sanitization_cb' => 'give_sanitize_thousand_separator',
294 'default' => ',',
295 ),
296 array(
297 'name' => __( 'Decimal Separator', 'give' ),
298 'desc' => __( 'The symbol (usually , or .) to separate decimal points.', 'give' ),
299 'id' => 'decimal_separator',
300 'type' => 'text_small',
301 'default' => '.',
302 ),
303 array(
304 'name' => __( 'Number of Decimals', 'give' ),
305 'desc' => __( 'The number of decimal points displayed in amounts.', 'give' ),
306 'id' => 'number_decimals',
307 'type' => 'text_small',
308 'default' => 2,
309 'sanitization_cb' => 'give_sanitize_number_decimals',
310 ),
311 )
312 ),
313 ),
314 /**
315 * Payment Gateways
316 */
317 'gateways' => array(
318 'id' => 'payment_gateways',
319 'give_title' => __( 'Payment Gateways', 'give' ),
320 'show_on' => array(
321 'key' => 'options-page',
322 'value' => array( $this->key ),
323 ),
324 'fields' => apply_filters(
325 'give_settings_gateways', array(
326 array(
327 'name' => __( 'Gateways Settings', 'give' ),
328 'desc' => '',
329 'id' => 'give_title_gateway_settings_1',
330 'type' => 'give_title',
331 ),
332 array(
333 'name' => __( 'Test Mode', 'give' ),
334 'desc' => __( 'While in test mode no live donations are processed. To fully use test mode, you must have a sandbox (test) account for the payment gateway you are testing.', 'give' ),
335 'id' => 'test_mode',
336 'type' => 'checkbox',
337 ),
338 array(
339 'name' => __( 'Enabled Gateways', 'give' ),
340 'desc' => __( 'Enable your payment gateway. Can be ordered by dragging.', 'give' ),
341 'id' => 'gateways',
342 'type' => 'enabled_gateways',
343 ),
344 array(
345 'name' => __( 'Default Gateway', 'give' ),
346 'desc' => __( 'The gateway that will be selected by default.', 'give' ),
347 'id' => 'default_gateway',
348 'type' => 'default_gateway',
349 ),
350 array(
351 'name' => __( 'PayPal Standard', 'give' ),
352 'desc' => '',
353 'type' => 'give_title',
354 'id' => 'give_title_gateway_settings_2',
355 ),
356 array(
357 'name' => __( 'PayPal Email', 'give' ),
358 'desc' => __( 'Enter your PayPal account\'s email.', 'give' ),
359 'id' => 'paypal_email',
360 'type' => 'text_email',
361 ),
362 array(
363 'name' => __( 'PayPal Page Style', 'give' ),
364 'desc' => __( 'Enter the name of the page style to use, or leave blank to use the default.', 'give' ),
365 'id' => 'paypal_page_style',
366 'type' => 'text',
367 ),
368 array(
369 'name' => __( 'PayPal Transaction Type', 'give' ),
370 'desc' => __( 'Nonprofits must verify their status to withdraw donations they receive via PayPal. PayPal users that are not verified nonprofits must demonstrate how their donations will be used, once they raise more than $10,000. By default, Give transactions are sent to PayPal as donations. You may change the transaction type using this option if you feel you may not meet PayPal\'s donation requirements.', 'give' ),
371 'id' => 'paypal_button_type',
372 'type' => 'radio_inline',
373 'options' => array(
374 'donation' => __( 'Donation', 'give' ),
375 'standard' => __( 'Standard Transaction', 'give' ),
376 ),
377 'default' => 'donation',
378 ),
379 array(
380 'name' => __( 'Disable PayPal IPN Verification', 'give' ),
381 'desc' => __( 'If donations are not getting marked as complete, use a slightly less secure method of verifying donations.', 'give' ),
382 'id' => 'disable_paypal_verification',
383 'type' => 'checkbox',
384 ),
385 array(
386 'name' => __( 'Offline Donations', 'give' ),
387 'desc' => '',
388 'type' => 'give_title',
389 'id' => 'give_title_gateway_settings_3',
390 ),
391 array(
392 'name' => __( 'Collect Billing Details', 'give' ),
393 'desc' => __( 'Enable to request billing details for offline donations. Will appear above offline donation instructions. Can be enabled/disabled per form.', 'give' ),
394 'id' => 'give_offline_donation_enable_billing_fields',
395 'type' => 'checkbox',
396 ),
397 array(
398 'name' => __( 'Offline Donation Instructions', 'give' ),
399 'desc' => __( 'The following content will appear for all forms when the user selects the offline donation payment option. Note: You may customize the content per form as needed.', 'give' ),
400 'id' => 'global_offline_donation_content',
401 'default' => give_get_default_offline_donation_content(),
402 'type' => 'wysiwyg',
403 'options' => array(
404 'textarea_rows' => 6,
405 ),
406 ),
407 array(
408 'name' => __( 'Offline Donation Email Instructions Subject', 'give' ),
409 'desc' => __( 'Enter the subject line for the donation receipt email.', 'give' ),
410 'id' => 'offline_donation_subject',
411 'default' => esc_attr__( '{donation} - Offline Donation Instructions', 'give' ),
412 'type' => 'text',
413 ),
414 array(
415 'name' => __( 'Offline Donation Email Instructions', 'give' ),
416 'desc' => __( 'Enter the instructions you want emailed to the donor after they have submitted the donation form. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ),
417 'id' => 'global_offline_donation_email',
418 'default' => give_get_default_offline_donation_email_content(),
419 'type' => 'wysiwyg',
420 'options' => array(
421 'textarea_rows' => 6,
422 ),
423 ),
424 )
425 ),
426 ),
427 /** Display Settings */
428 'display' => array(
429 'id' => 'display_settings',
430 'give_title' => __( 'Display Settings', 'give' ),
431 'show_on' => array(
432 'key' => 'options-page',
433 'value' => array( $this->key ),
434 ),
435 'fields' => apply_filters(
436 'give_settings_display', array(
437 array(
438 'name' => __( 'Display Settings', 'give' ),
439 'desc' => '',
440 'id' => 'give_title_display_settings_1',
441 'type' => 'give_title',
442 ),
443 array(
444 'name' => __( 'Disable CSS', 'give' ),
445 'desc' => __( 'Enable this option if you would like to disable all of Give\'s included CSS stylesheets.', 'give' ),
446 'id' => 'disable_css',
447 'type' => 'checkbox',
448 ),
449 array(
450 'name' => __( 'Enable Floating Labels', 'give' ),
451 /* translators: %s: http://docs.givewp.com/form-floating-labels */
452 'desc' => sprintf(
453 wp_kses(
454 __( 'Enable <a href="%s" target="_blank">floating labels</a> in Give\'s donation forms. Note that if the "Disable CSS" option is enabled, you will need to style the floating labels yourself.', 'give' ), array(
455 'a' => array(
456 'href' => array(),
457 'target' => array(),
458 ),
459 )
460 ), esc_url( 'http://docs.givewp.com/form-floating-labels' )
461 ),
462 'id' => 'floatlabels',
463 'type' => 'checkbox',
464 ),
465 array(
466 'name' => __( 'Disable Welcome Screen', 'give' ),
467 /* translators: %s: about page URL */
468 'desc' => sprintf(
469 wp_kses(
470 __( 'Enable this option if you would like to disable the <a href="%s" target="_blank">Give Welcome screen</a> every time Give is activated and/or updated.', 'give' ), array(
471 'a' => array(
472 'href' => array(),
473 'target' => array(),
474 ),
475 )
476 ), esc_url( admin_url( 'index.php?page=give-about' ) )
477 ),
478 'id' => 'disable_welcome',
479 'type' => 'checkbox',
480 ),
481 array(
482 'name' => __( 'Post Types', 'give' ),
483 'desc' => '',
484 'id' => 'give_title_display_settings_2',
485 'type' => 'give_title',
486 ),
487 array(
488 'name' => __( 'Disable Form Single Views', 'give' ),
489 'desc' => __( 'By default, all forms have single views enabled which create a specific URL on your website for that form. This option disables the singular and archive views from being publicly viewable. Note: you will need to embed forms using a shortcode or widget if enabled.', 'give' ),
490 'id' => 'disable_forms_singular',
491 'type' => 'checkbox',
492 ),
493 array(
494 'name' => __( 'Disable Form Archives', 'give' ),
495 'desc' => __( 'Archives pages list all the forms you have created. This option will disable only the form\'s archive page(s). The single form\'s view will remain in place. Note: you will need to refresh your permalinks after this option has been enabled.', 'give' ),
496 'id' => 'disable_forms_archives',
497 'type' => 'checkbox',
498 ),
499 array(
500 'name' => __( 'Disable Form Excerpts', 'give' ),
501 'desc' => __( 'The excerpt is an optional summary or description of a donation form; in short, a summary as to why the user should give.', 'give' ),
502 'id' => 'disable_forms_excerpt',
503 'type' => 'checkbox',
504 ),
505 array(
506 'name' => __( 'Featured Image Size', 'give' ),
507 'desc' => __( 'The Featured Image is an image that is chosen as the representative image for a donation form. Some themes may have custom featured image sizes. Please select the size you would like to display for your single donation form\'s featured image.', 'give' ),
508 'id' => 'featured_image_size',
509 'type' => 'select',
510 'default' => 'large',
511 'options' => give_get_featured_image_sizes(),
512 ),
513 array(
514 'name' => __( 'Disable Form Featured Image', 'give' ),
515 'desc' => __( 'If you do not wish to use the featured image functionality you can disable it using this option and it will not be displayed for single donation forms.', 'give' ),
516 'id' => 'disable_form_featured_img',
517 'type' => 'checkbox',
518 ),
519 array(
520 'name' => __( 'Disable Single Form Sidebar', 'give' ),
521 'desc' => __( 'The sidebar allows you to add additional widget to the Give single form view. If you don\'t plan on using the sidebar you may disable it with this option.', 'give' ),
522 'id' => 'disable_form_sidebar',
523 'type' => 'checkbox',
524 ),
525 array(
526 'name' => __( 'Taxonomies', 'give' ),
527 'desc' => '',
528 'id' => 'give_title_display_settings_3',
529 'type' => 'give_title',
530 ),
531 array(
532 'name' => __( 'Enable Form Categories', 'give' ),
533 'desc' => __( 'Enables the "Category" taxonomy for all Give forms.', 'give' ),
534 'id' => 'categories',
535 'type' => 'checkbox',
536 ),
537 array(
538 'name' => __( 'Enable Form Tags', 'give' ),
539 'desc' => __( 'Enables the "Tag" taxonomy for all Give forms.', 'give' ),
540 'id' => 'tags',
541 'type' => 'checkbox',
542 ),
543 )
544 ),
545
546 ),
547 /**
548 * Emails Options
549 */
550 'emails' => array(
551 'id' => 'email_settings',
552 'give_title' => __( 'Email Settings', 'give' ),
553 'show_on' => array(
554 'key' => 'options-page',
555 'value' => array( $this->key ),
556 ),
557 'fields' => apply_filters(
558 'give_settings_emails', array(
559 array(
560 'name' => __( 'Email Settings', 'give' ),
561 'desc' => '',
562 'id' => 'give_title_email_settings_1',
563 'type' => 'give_title',
564 ),
565 array(
566 'id' => 'email_template',
567 'name' => __( 'Email Template', 'give' ),
568 'desc' => __( 'Choose a template. Click "Save Changes" then "Preview Donation Receipt" to see the new template.', 'give' ),
569 'type' => 'select',
570 'options' => give_get_email_templates(),
571 ),
572 array(
573 'id' => 'email_logo',
574 'name' => __( 'Logo', 'give' ),
575 'desc' => __( 'Upload or choose a logo to be displayed at the top of the donation receipt emails. Displayed on HTML emails only.', 'give' ),
576 'type' => 'file',
577 ),
578 array(
579 'id' => 'from_name',
580 'name' => __( 'From Name', 'give' ),
581 'desc' => __( 'The name that appears in the "From" field in donation receipt emails.', 'give' ),
582 'default' => get_bloginfo( 'name' ),
583 'type' => 'text',
584 ),
585 array(
586 'id' => 'from_email',
587 'name' => __( 'From Email', 'give' ),
588 'desc' => __( 'Email to send donation receipts from. This will act as the "from" and "reply-to" address.', 'give' ),
589 'default' => get_bloginfo( 'admin_email' ),
590 'type' => 'text',
591 ),
592 array(
593 'name' => __( 'Donation Receipt', 'give' ),
594 'desc' => '',
595 'id' => 'give_title_email_settings_2',
596 'type' => 'give_title',
597 ),
598 array(
599 'id' => 'donation_subject',
600 'name' => __( 'Donation Email Subject', 'give' ),
601 'desc' => __( 'Enter the subject line for the donation receipt email.', 'give' ),
602 'default' => esc_attr__( 'Donation Receipt', 'give' ),
603 'type' => 'text',
604 ),
605 array(
606 'id' => 'donation_receipt',
607 'name' => __( 'Donation Receipt', 'give' ),
608 'desc' => sprintf(
609 /* translators: %s: emails tags list */
610 __( 'Enter the email that is sent to users after completing a successful donation. HTML is accepted. Available template tags: %s', 'give' ),
611 '<br/>' . give_get_emails_tags_list()
612 ),
613 'type' => 'wysiwyg',
614 'default' => give_get_default_donation_receipt_email(),
615 ),
616 array(
617 'name' => __( 'New Donation Notification', 'give' ),
618 'desc' => '',
619 'id' => 'give_title_email_settings_3',
620 'type' => 'give_title',
621 ),
622 array(
623 'id' => 'donation_notification_subject',
624 'name' => __( 'Donation Notification Subject', 'give' ),
625 'desc' => __( 'Enter the subject line for the donation notification email.', 'give' ),
626 'type' => 'text',
627 'default' => esc_attr__( 'New Donation - #{payment_id}', 'give' ),
628 ),
629 array(
630 'id' => 'donation_notification',
631 'name' => __( 'Donation Notification', 'give' ),
632 'desc' => sprintf(
633 /* translators: %s: emails tags list */
634 __( 'Enter the email that is sent to donation notification emails after completion of a donation. HTML is accepted. Available template tags: %s', 'give' ),
635 '<br/>' . give_get_emails_tags_list()
636 ),
637 'type' => 'wysiwyg',
638 'default' => give_get_default_donation_notification_email(),
639 ),
640 array(
641 'id' => 'admin_notice_emails',
642 'name' => __( 'Donation Notification Emails', 'give' ),
643 'desc' => __( 'Enter the email address(es) that should receive a notification anytime a donation is made, please only enter <span class="give-underline">one email address per line</span> and <strong>not separated by commas</strong>.', 'give' ),
644 'type' => 'textarea',
645 'default' => get_bloginfo( 'admin_email' ),
646 ),
647 array(
648 'id' => 'disable_admin_notices',
649 'name' => __( 'Disable Admin Notifications', 'give' ),
650 'desc' => __( 'Check this box if you do not want to receive emails when new donations are made.', 'give' ),
651 'type' => 'checkbox',
652 ),
653 )
654 ),
655 ),
656 /** Extension Settings */
657 'addons' => array(
658 'id' => 'addons',
659 'give_title' => __( 'Give Add-ons Settings', 'give' ),
660 'show_on' => array(
661 'key' => 'options-page',
662 'value' => array( $this->key ),
663 ),
664 'fields' => apply_filters(
665 'give_settings_addons', array()
666 ),
667 ),
668 /** Licenses Settings */
669 'licenses' => array(
670 'id' => 'licenses',
671 'give_title' => __( 'Give Licenses', 'give' ),
672 'show_on' => array(
673 'key' => 'options-page',
674 'value' => array( $this->key ),
675 ),
676 'fields' => apply_filters(
677 'give_settings_licenses', array()
678 ),
679 ),
680 /** Advanced Options */
681 'advanced' => array(
682 'id' => 'advanced_options',
683 'give_title' => __( 'Advanced Options', 'give' ),
684 'show_on' => array(
685 'key' => 'options-page',
686 'value' => array( $this->key ),
687 ),
688 'fields' => apply_filters(
689 'give_settings_advanced', array(
690 array(
691 'name' => __( 'Access Control', 'give' ),
692 'desc' => '',
693 'id' => 'give_title_session_control_1',
694 'type' => 'give_title',
695 ),
696 array(
697 'id' => 'session_lifetime',
698 'name' => __( 'Session Lifetime', 'give' ),
699 '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' ),
700 'type' => 'select',
701 'options' => array(
702 '86400' => __( '24 Hours', 'give' ),
703 '172800' => __( '48 Hours', 'give' ),
704 '259200' => __( '72 Hours', 'give' ),
705 '604800' => __( '1 Week', 'give' ),
706 ),
707 ),
708 array(
709 'name' => __( 'Email Access', 'give' ),
710 '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' ),
711 'id' => 'email_access',
712 'type' => 'checkbox',
713 ),
714 array(
715 'id' => 'recaptcha_key',
716 'name' => __( 'reCAPTCHA Site Key', 'give' ),
717 /* translators: %s: https://www.google.com/recaptcha/ */
718 '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. The reCAPTCHA uses Google\'s user-friendly single click verification method.', 'give' ), esc_url( 'https://www.google.com/recaptcha/' ) ),
719 'default' => '',
720 'type' => 'text',
721 ),
722 array(
723 'id' => 'recaptcha_secret',
724 'name' => __( 'reCAPTCHA Secret Key', 'give' ),
725 'desc' => __( 'Please paste the reCAPTCHA secret key here from your manage reCAPTCHA API Keys panel.', 'give' ),
726 'default' => '',
727 'type' => 'text',
728 ),
729 array(
730 'name' => __( 'Data Control', 'give' ),
731 'desc' => '',
732 'id' => 'give_title_data_control_2',
733 'type' => 'give_title',
734 ),
735 array(
736 'name' => __( 'Remove All Data on Uninstall?', 'give' ),
737 'desc' => __( 'When the plugin is deleted, completely remove all Give data.', 'give' ),
738 'id' => 'uninstall_on_delete',
739 'type' => 'checkbox',
740 ),
741 array(
742 'name' => __( 'Filter Control', 'give' ),
743 'desc' => '',
744 'id' => 'give_title_filter_control',
745 'type' => 'give_title',
746 ),
747 array(
748 /* translators: %s: the_content */
749 'name' => sprintf( __( 'Disable %s filter', 'give' ), '<code>the_content</code>' ),
750 /* translators: 1: https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content 2: the_content */
751 'desc' => sprintf( __( 'If you are seeing extra social buttons, related posts, or other unwanted elements appearing within your forms then you can disable WordPress\' content filter. <a href="%1$s" target="_blank">Learn more</a> about %2$s filter.', 'give' ), esc_url( 'https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content' ), '<code>the_content</code>' ),
752 'id' => 'disable_the_content_filter',
753 'type' => 'checkbox',
754 ),
755 array(
756 'name' => __( 'Script Loading', 'give' ),
757 'desc' => '',
758 'id' => 'give_title_script_control',
759 'type' => 'give_title',
760 ),
761 array(
762 'name' => __( 'Load Scripts in Footer?', 'give' ),
763 'desc' => __( 'Check this box if you would like Give to load all frontend JavaScript files in the footer.', 'give' ),
764 'id' => 'scripts_footer',
765 'type' => 'checkbox',
766 ),
767 )
768 ),
769 ),
770 /** API Settings */
771 'api' => array(
772 'id' => 'api',
773 'give_title' => __( 'API', 'give' ),
774 'show_on' => array(
775 'key' => 'options-page',
776 'value' => array( $this->key ),
777 ),
778 'show_names' => false, // Hide field names on the left
779 'fields' => apply_filters(
780 'give_settings_system', array(
781 array(
782 'id' => 'api',
783 'name' => __( 'API', 'give' ),
784 'type' => 'api',
785 ),
786 )
787 ),
788 ),
789 /** Licenses Settings */
790 'system_info' => array(
791 'id' => 'system_info',
792 'give_title' => __( 'System Info', 'give' ),
793 'show_on' => array(
794 'key' => 'options-page',
795 'value' => array( $this->key ),
796 ),
797 'fields' => apply_filters(
798 'give_settings_system', array(
799 array(
800 'id' => 'system-info-textarea',
801 'name' => __( 'System Info', 'give' ),
802 'desc' => __( 'Please copy and paste this information in your ticket when contacting support.', 'give' ),
803 'type' => 'system_info',
804 ),
805 )
806 ),
807 ),
808 );
809
810 $give_settings = apply_filters( 'give_registered_settings', $give_settings );
811
812 // Return all settings array if no active tab
813 if ( empty( $active_tab ) || ! isset( $give_settings[ $active_tab ] ) ) {
814 return $give_settings;
815 }
816
817 // Add other tabs and settings fields as needed
818 return $give_settings[ $active_tab ];
819
820 }
821
822 /**
823 * Show Settings Notices
824 */
825 public function settings_notices() {
826
827 if ( ! isset( $_POST['give_settings_saved'] ) ) {
828 return;
829 }
830
831 add_settings_error( 'give-notices', 'global-settings-updated', __( 'Settings updated.', 'give' ), 'updated' );
832
833 }
834
835
836 /**
837 * Public getter method for retrieving protected/private variables
838 *
839 * @since 1.0
840 *
841 * @param string $field Field to retrieve
842 *
843 * @return mixed Field value or exception is thrown.
844 * @throws Exception Throws an exception if the field is invalid.
845 */
846 public function __get( $field ) {
847
848 // Allowed fields to retrieve
849 if ( in_array( $field, array( 'key', 'fields', 'give_title', 'options_page' ), true ) ) {
850 return $this->{$field};
851 }
852
853 throw new Exception( sprintf( __( 'Invalid property: %s', 'give' ), $field ) );
854 }
855
856
857 }
858
859 // Get it started
860 $Give_Settings = new Give_Plugin_Settings();
861
862 /**
863 * Helps get a single option from the give_get_settings() array.
864 *
865 * @since 0.1.0
866 *
867 * @param string $key Options array key
868 * @param string|bool $default The default option if the option isn't set
869 *
870 * @return mixed Option value
871 */
872 function give_get_option( $key = '', $default = false ) {
873 $give_options = give_get_settings();
874 $value = ! empty( $give_options[ $key ] ) ? $give_options[ $key ] : $default;
875 $value = apply_filters( 'give_get_option', $value, $key, $default );
876
877 return apply_filters( "give_get_option_{$key}", $value, $key, $default );
878 }
879
880
881 /**
882 * Update an option
883 *
884 * Updates an give setting value in both the db and the global variable.
885 * Warning: Passing in an empty, false or null string value will remove
886 * the key from the give_options array.
887 *
888 * @since 1.0
889 *
890 * @param string $key The Key to update
891 * @param string|bool|int $value The value to set the key to
892 *
893 * @return boolean True if updated, false if not.
894 */
895 function give_update_option( $key = '', $value = false ) {
896
897 // If no key, exit
898 if ( empty( $key ) ) {
899 return false;
900 }
901
902 if ( empty( $value ) ) {
903 $remove_option = give_delete_option( $key );
904
905 return $remove_option;
906 }
907
908 // First let's grab the current settings
909 $options = get_option( 'give_settings' );
910
911 // Let's let devs alter that value coming in
912 $value = apply_filters( 'give_update_option', $value, $key );
913
914 // Next let's try to update the value
915 $options[ $key ] = $value;
916 $did_update = update_option( 'give_settings', $options, false );
917
918 // If it updated, let's update the global variable
919 if ( $did_update ) {
920 global $give_options;
921 $give_options[ $key ] = $value;
922 }
923
924 return $did_update;
925 }
926
927 /**
928 * Remove an option
929 *
930 * Removes an give setting value in both the db and the global variable.
931 *
932 * @since 1.0
933 *
934 * @global $give_options
935 *
936 * @param string $key The Key to delete
937 *
938 * @return boolean True if updated, false if not.
939 */
940 function give_delete_option( $key = '' ) {
941
942 // If no key, exit
943 if ( empty( $key ) ) {
944 return false;
945 }
946
947 // First let's grab the current settings
948 $options = get_option( 'give_settings' );
949
950 // Next let's try to update the value
951 if ( isset( $options[ $key ] ) ) {
952 unset( $options[ $key ] );
953 }
954
955 $did_update = update_option( 'give_settings', $options, false );
956
957 // If it updated, let's update the global variable
958 if ( $did_update ) {
959 global $give_options;
960 $give_options = $options;
961 }
962
963 return $did_update;
964 }
965
966
967 /**
968 * Get Settings
969 *
970 * Retrieves all Give plugin settings
971 *
972 * @since 1.0
973 * @return array Give settings
974 */
975 function give_get_settings() {
976
977 $settings = get_option( 'give_settings' );
978
979 return (array) apply_filters( 'give_get_settings', $settings );
980
981 }
982
983
984 /**
985 * Give Settings Array Insert.
986 *
987 * Allows other Add-ons and plugins to insert Give settings at a desired position.
988 *
989 * @since 1.3.5
990 *
991 * @param $array
992 * @param $position |int|string Expects an array key or 'id' of the settings field to appear after
993 * @param $insert |array a valid array of options to insert
994 *
995 * @return array
996 */
997 function give_settings_array_insert( $array, $position, $insert ) {
998 if ( is_int( $position ) ) {
999 array_splice( $array, $position, 0, $insert );
1000 } else {
1001
1002 foreach ( $array as $index => $subarray ) {
1003 if ( isset( $subarray['id'] ) && $subarray['id'] == $position ) {
1004 $pos = $index;
1005 }
1006 }
1007
1008 if ( ! isset( $pos ) ) {
1009 return $array;
1010 }
1011
1012 $array = array_merge(
1013 array_slice( $array, 0, $pos ),
1014 $insert,
1015 array_slice( $array, $pos )
1016 );
1017 }
1018
1019 return $array;
1020 }
1021
1022
1023 /**
1024 * Gateways Callback
1025 *
1026 * Renders gateways fields.
1027 *
1028 * @since 1.0
1029 *
1030 * @param array $field_arr
1031 * @param array $saved_values
1032 *
1033 * @return void
1034 */
1035 function give_enabled_gateways_callback( $field_arr, $saved_values = array() ) {
1036 $saved_values = __give_validate_active_gateways( $saved_values );
1037 $id = $field_arr['id'];
1038 $gateways = give_get_ordered_payment_gateways( give_get_payment_gateways() );
1039
1040 echo '<ul class="give-checklist-fields give-payment-gatways-list">';
1041
1042 foreach ( $gateways as $key => $option ) :
1043
1044 if ( is_array( $saved_values ) && array_key_exists( $key, $saved_values ) ) {
1045 $enabled = '1';
1046 } else {
1047 $enabled = null;
1048 }
1049
1050 echo '<li><span class="give-drag-handle"><span class="dashicons dashicons-menu"></span></span><input name="' . $id . '[' . $key . ']" id="' . $id . '[' . $key . ']" type="checkbox" value="1" ' . checked( '1', $enabled, false ) . '/>&nbsp;';
1051 echo '<label for="' . $id . '[' . $key . ']">' . $option['admin_label'] . '</label></li>';
1052
1053 endforeach;
1054
1055 echo '</ul>';
1056 }
1057
1058 /**
1059 * Gateways Callback (drop down)
1060 *
1061 * Renders gateways select menu
1062 *
1063 * @since 1.0
1064 *
1065 * @param array $field_arr
1066 * @param array $saved_value
1067 *
1068 * @return void
1069 */
1070 function give_default_gateway_callback( $field_arr, $saved_value ) {
1071 $id = $field_arr['id'];
1072 $gateways = give_get_enabled_payment_gateways();
1073 $saved_value = give_get_default_gateway( null );
1074
1075 echo '<select class="give-select" name="' . $id . '" id="' . $id . '">';
1076
1077 foreach ( $gateways as $key => $option ) :
1078 $selected = isset( $saved_value ) ? selected( $key, $saved_value, false ) : '';
1079 echo '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
1080 endforeach;
1081
1082 echo '</select>';
1083
1084 }
1085
1086 /**
1087 * Give Title
1088 *
1089 * Renders custom section titles output; Really only an because CMB2's output is a bit funky
1090 *
1091 * @since 1.0
1092 *
1093 * @param $field_object , $escaped_value, $object_id, $object_type, $field_type_object
1094 *
1095 * @return void
1096 */
1097 function give_title_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
1098
1099 $id = $field_type_object->field->args['id'];
1100 $title = $field_type_object->field->args['name'];
1101 $field_description = $field_type_object->field->args['desc'];
1102
1103 echo '<hr>' . $field_description;
1104
1105 }
1106
1107 /**
1108 * Give Description
1109 *
1110 * Renders custom description text which any plugin can use to output content, html, php, etc.
1111 *
1112 * @since 1.3.5
1113 *
1114 * @param $field_object , $escaped_value, $object_id, $object_type, $field_type_object
1115 *
1116 * @return void
1117 */
1118 function give_description_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
1119
1120 $id = $field_type_object->field->args['id'];
1121 $title = $field_type_object->field->args['name'];
1122 $field_description = $field_type_object->field->args['desc'];
1123
1124 echo $field_description;
1125
1126 }
1127
1128 /**
1129 * Gets a number of posts and displays them as options
1130 *
1131 * @param array $query_args Optional. Overrides defaults.
1132 * @param bool $force Force the pages to be loaded even if not on settings
1133 *
1134 * @see: https://github.com/WebDevStudios/CMB2/wiki/Adding-your-own-field-types
1135 * @return array An array of options that matches the CMB2 options array
1136 */
1137 function give_cmb2_get_post_options( $query_args, $force = false ) {
1138
1139 $post_options = array( '' => '' ); // Blank option
1140
1141 if ( ( ! isset( $_GET['page'] ) || 'give-settings' != $_GET['page'] ) && ! $force ) {
1142 return $post_options;
1143 }
1144
1145 $args = wp_parse_args(
1146 $query_args, array(
1147 'post_type' => 'page',
1148 'numberposts' => 10,
1149 )
1150 );
1151
1152 $posts = get_posts( $args );
1153
1154 if ( $posts ) {
1155 foreach ( $posts as $post ) {
1156
1157 $post_options[ $post->ID ] = $post->post_title;
1158
1159 }
1160 }
1161
1162 return $post_options;
1163 }
1164
1165
1166 /**
1167 * Featured Image Sizes
1168 *
1169 * Outputs an array for the "Featured Image Size" option found under Settings > Display Options.
1170 *
1171 * @since 1.4
1172 *
1173 * @global $_wp_additional_image_sizes
1174 *
1175 * @return array $sizes
1176 */
1177 function give_get_featured_image_sizes() {
1178 global $_wp_additional_image_sizes;
1179
1180 $sizes = array();
1181 $get_sizes = get_intermediate_image_sizes();
1182 $core_image_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' );
1183
1184 // This will help us to filter special characters from a string
1185 $filter_slug_items = array( '_', '-' );
1186
1187 foreach ( $get_sizes as $_size ) {
1188
1189 // Converting image size slug to title case
1190 $sizes[ $_size ] = give_slug_to_title( $_size, $filter_slug_items );
1191
1192 if ( in_array( $_size, $core_image_sizes ) ) {
1193 $sizes[ $_size ] .= ' (' . get_option( "{$_size}_size_w" ) . 'x' . get_option( "{$_size}_size_h" );
1194 } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
1195 $sizes[ $_size ] .= " ({$_wp_additional_image_sizes[ $_size ]['width']} x {$_wp_additional_image_sizes[ $_size ]['height']}";
1196 }
1197
1198 // Based on the above image height check, label the respective resolution as responsive
1199 if ( ( array_key_exists( $_size, $_wp_additional_image_sizes ) && ! $_wp_additional_image_sizes[ $_size ]['crop'] ) || ( in_array( $_size, $core_image_sizes ) && ! get_option( "{$_size}_crop" ) ) ) {
1200 $sizes[ $_size ] .= ' - responsive';
1201 }
1202
1203 $sizes[ $_size ] .= ')';
1204
1205 }
1206
1207 return apply_filters( 'give_get_featured_image_sizes', $sizes );
1208 }
1209
1210
1211 /**
1212 * Slug to Title
1213 *
1214 * Converts a string with hyphen(-) or underscores(_) or any special character to a string with Title case
1215 *
1216 * @since 1.8.8
1217 *
1218 * @params $string text
1219 * @params $filter array
1220 *
1221 * @return text $string
1222 */
1223 function give_slug_to_title( $string, $filters = array() ) {
1224
1225 foreach ( $filters as $filter_item ) {
1226 $string = str_replace( $filter_item, ' ', $string );
1227 }
1228
1229 // Return updated string after converting it to title case
1230 return ucwords( $string );
1231
1232 }
1233
1234
1235 /**
1236 * Give License Key Callback
1237 *
1238 * Registers the license field callback for EDD's Software Licensing.
1239 *
1240 * @since 1.0
1241 *
1242 * @param array $field_object , $escaped_value, $object_id, $object_type, $field_type_object Arguments passed by CMB2
1243 *
1244 * @return void
1245 */
1246 function give_license_key_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
1247 /* @var CMB2_Types $field_type_object */
1248
1249 $id = $field_type_object->field->args['id'];
1250 $field_description = $field_type_object->field->args['desc'];
1251 $license = $field_type_object->field->args['options']['license'];
1252 $license_key = $escaped_value;
1253 $is_license_key = apply_filters( 'give_is_license_key', ( is_object( $license ) && ! empty( $license ) ) );
1254 $is_valid_license = apply_filters( 'give_is_valid_license', ( $is_license_key && property_exists( $license, 'license' ) && 'valid' === $license->license ) );
1255 $shortname = $field_type_object->field->args['options']['shortname'];
1256 $field_classes = 'regular-text give-license-field';
1257 $type = empty( $escaped_value ) || ! $is_valid_license ? 'text' : 'password';
1258 $custom_html = '';
1259 $messages = array();
1260 $class = '';
1261 $account_page_link = $field_type_object->field->args['options']['account_url'];
1262 $checkout_page_link = $field_type_object->field->args['options']['checkout_url'];
1263 $addon_name = $field_type_object->field->args['options']['item_name'];
1264 $license_status = null;
1265 $is_in_subscription = null;
1266
1267 // By default query on edd api url will return license object which contain status and message property, this can break below functionality.
1268 // To combat that check if status is set to error or not, if yes then set $is_license_key to false.
1269 if ( $is_license_key && property_exists( $license, 'status' ) && 'error' === $license->status ) {
1270 $is_license_key = false;
1271 }
1272
1273 // Check if current license is part of subscription or not.
1274 $subscriptions = get_option( 'give_subscriptions' );
1275
1276 if ( $is_license_key && $subscriptions ) {
1277 foreach ( $subscriptions as $subscription ) {
1278 if ( in_array( $license_key, $subscription['licenses'] ) ) {
1279 $is_in_subscription = $subscription['id'];
1280 break;
1281 }
1282 }
1283 }
1284
1285 if ( $is_license_key ) {
1286
1287 if ( empty( $license->success ) && property_exists( $license, 'error' ) ) {
1288
1289 // activate_license 'invalid' on anything other than valid, so if there was an error capture it
1290 switch ( $license->error ) {
1291 case 'expired':
1292 $class = $license->error;
1293 $messages[] = sprintf(
1294 __( 'Your license key expired on %1$s. Please <a href="%2$s" target="_blank" title="Renew your license key">renew your license key</a>.', 'give' ),
1295 date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1296 $checkout_page_link . '?edd_license_key=' . $license_key . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
1297 );
1298 $license_status = 'license-' . $class;
1299 break;
1300
1301 case 'missing':
1302 $class = $license->error;
1303 $messages[] = sprintf(
1304 __( 'Invalid license. Please <a href="%s" target="_blank" title="Visit account page">visit your account page</a> and verify it.', 'give' ),
1305 $account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=missing'
1306 );
1307 $license_status = 'license-' . $class;
1308 break;
1309
1310 case 'invalid':
1311 $class = $license->error;
1312 $messages[] = sprintf(
1313 __( 'Your %1$s is not active for this URL. Please <a href="%2$s" target="_blank" title="Visit account page">visit your account page</a> to manage your license key URLs.', 'give' ),
1314 $addon_name,
1315 $account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1316 );
1317 $license_status = 'license-' . $class;
1318 break;
1319
1320 case 'site_inactive':
1321 $class = $license->error;
1322 $messages[] = sprintf(
1323 __( 'Your %1$s is not active for this URL. Please <a href="%2$s" target="_blank" title="Visit account page">visit your account page</a> to manage your license key URLs.', 'give' ),
1324 $addon_name,
1325 $account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1326 );
1327 $license_status = 'license-' . $class;
1328 break;
1329
1330 case 'item_name_mismatch':
1331 $class = $license->error;
1332 $messages[] = sprintf( __( 'This license %1$s does not belong to %2$s.', 'give' ), $license_key, $addon_name );
1333 $license_status = 'license-' . $class;
1334 break;
1335
1336 case 'no_activations_left':
1337 $class = $license->error;
1338 $messages[] = sprintf( __( 'Your license key has reached it\'s activation limit. <a href="%s">View possible upgrades</a> now.', 'give' ), $account_page_link );
1339 $license_status = 'license-' . $class;
1340 break;
1341
1342 default:
1343 $class = $license->error;
1344 $messages[] = sprintf(
1345 __( 'Your license is not activated. Please <a href="%3$s" target="_blank" title="Visit account page">visit your account page</a> to manage your license key URLs. %2$sError Code: %1$s.', 'give' ),
1346 $license->error,
1347 '<br/>',
1348 "{$account_page_link}?utm_campaign=admin&utm_source=licenses&utm_medium={$license->error}"
1349 );
1350 $license_status = 'license-error';
1351 break;
1352 }
1353 } elseif ( $is_in_subscription ) {
1354
1355 $subscription_expires = strtotime( $subscriptions[ $is_in_subscription ]['expires'] );
1356 $subscription_status = __( 'renew', 'give' );
1357
1358 if ( ( 'active' !== $subscriptions[ $is_in_subscription ]['status'] ) ) {
1359 $subscription_status = __( 'expire', 'give' );
1360 }
1361
1362 if ( $subscription_expires < current_time( 'timestamp', 1 ) ) {
1363 $messages[] = sprintf(
1364 __( 'Your subscription (<a href="%1$s" target="_blank">#%2$d</a>) expired. Please <a href="%3$s" target="_blank" title="Renew your license key">renew your license key</a>', 'give' ),
1365 urldecode( $subscriptions[ $is_in_subscription ]['invoice_url'] ),
1366 $subscriptions[ $is_in_subscription ]['payment_id'],
1367 $checkout_page_link . '?edd_license_key=' . $subscriptions[ $is_in_subscription ]['license_key'] . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
1368 );
1369 $license_status = 'license-expired';
1370 } elseif ( strtotime( '- 7 days', $subscription_expires ) < current_time( 'timestamp', 1 ) ) {
1371 $messages[] = sprintf(
1372 __( 'Your subscription (<a href="%1$s" target="_blank">#%2$d</a>) will %3$s in %4$s.', 'give' ),
1373 urldecode( $subscriptions[ $is_in_subscription ]['invoice_url'] ),
1374 $subscriptions[ $is_in_subscription ]['payment_id'],
1375 $subscription_status,
1376 human_time_diff( current_time( 'timestamp', 1 ), strtotime( $subscriptions[ $is_in_subscription ]['expires'] ) )
1377 );
1378 $license_status = 'license-expires-soon';
1379 } else {
1380 $messages[] = sprintf(
1381 __( 'Your subscription (<a href="%1$s" target="_blank">#%2$d</a>) will %3$s on %4$s.', 'give' ),
1382 urldecode( $subscriptions[ $is_in_subscription ]['invoice_url'] ),
1383 $subscriptions[ $is_in_subscription ]['payment_id'],
1384 $subscription_status,
1385 date_i18n( get_option( 'date_format' ), strtotime( $subscriptions[ $is_in_subscription ]['expires'], current_time( 'timestamp' ) ) )
1386 );
1387 $license_status = 'license-expiration-date';
1388 }
1389 } elseif ( empty( $license->success ) ) {
1390 $class = 'invalid';
1391 $messages[] = sprintf(
1392 __( 'Your %1$s is not active for this URL. Please <a href="%2$s" target="_blank" title="Visit account page">visit your account page</a> to manage your license key URLs.', 'give' ),
1393 $addon_name,
1394 $account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1395 );
1396 $license_status = 'license-' . $class;
1397
1398 } else {
1399 switch ( $license->license ) {
1400 case 'valid':
1401 default:
1402 $class = 'valid';
1403 $now = current_time( 'timestamp' );
1404 $expiration = strtotime( $license->expires, current_time( 'timestamp' ) );
1405
1406 if ( 'lifetime' === $license->expires ) {
1407 $messages[] = __( 'License key never expires.', 'give' );
1408 $license_status = 'license-lifetime-notice';
1409 } elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
1410 $messages[] = sprintf(
1411 __( 'Your license key expires soon! It expires on %1$s. <a href="%2$s" target="_blank" title="Renew license">Renew your license key</a>.', 'give' ),
1412 date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1413 $checkout_page_link . '?edd_license_key=' . $license_key . '&utm_campaign=admin&utm_source=licenses&utm_medium=renew'
1414 );
1415 $license_status = 'license-expires-soon';
1416 } else {
1417 $messages[] = sprintf(
1418 __( 'Your license key expires on %s.', 'give' ),
1419 date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
1420 );
1421 $license_status = 'license-expiration-date';
1422 }
1423 break;
1424 }
1425 }
1426 } else {
1427 $messages[] = sprintf(
1428 __( 'To receive updates, please enter your valid %s license key.', 'give' ),
1429 $addon_name
1430 );
1431 $license_status = 'inactive';
1432 }
1433
1434 // Add class for input field if license is active.
1435 if ( $is_valid_license ) {
1436 $field_classes .= ' give-license-active';
1437 }
1438
1439 // Get input field html.
1440 $input_field_html = "<input type=\"{$type}\" name=\"{$id}\" class=\"{$field_classes}\" value=\"{$license_key}\">";
1441
1442 // If license is active so show deactivate button.
1443 if ( $is_valid_license ) {
1444 // Get input field html.
1445 $input_field_html = "<input type=\"{$type}\" name=\"{$id}\" class=\"{$field_classes}\" value=\"{$license_key}\" readonly=\"readonly\">";
1446
1447 $custom_html = '<input type="submit" class="button button-small give-license-deactivate" name="' . $id . '_deactivate" value="' . esc_attr__( 'Deactivate License', 'give' ) . '"/>';
1448
1449 }
1450
1451 // Field description.
1452 $custom_html .= '<label for="give_settings[' . $id . ']"> ' . $field_description . '</label>';
1453
1454 // If no messages found then inform user that to get updated in future register yourself.
1455 if ( empty( $messages ) ) {
1456 $messages[] = apply_filters( "{$shortname}_default_addon_notice", __( 'To receive updates, please enter your valid license key.', 'give' ) );
1457 }
1458
1459 foreach ( $messages as $message ) {
1460 $custom_html .= '<div class="give-license-status-notice give-' . $license_status . '">';
1461 $custom_html .= '<p>' . $message . '</p>';
1462 $custom_html .= '</div>';
1463 }
1464
1465 // Field html.
1466 $custom_html = apply_filters( 'give_license_key_field_html', $input_field_html . $custom_html, $field_type_object );
1467
1468 // Nonce.
1469 wp_nonce_field( $id . '-nonce', $id . '-nonce' );
1470
1471 // Print field html.
1472 echo "<div class=\"give-license-key\"><label for=\"{$id}\">{$addon_name }</label></div><div class=\"give-license-block\">{$custom_html}</div>";
1473 }
1474
1475
1476 /**
1477 * Display the API Keys
1478 *
1479 * @since 1.0
1480 * @return void
1481 */
1482 function give_api_callback() {
1483
1484 if ( ! current_user_can( 'manage_give_settings' ) ) {
1485 return;
1486 }
1487
1488 /**
1489 * Fires before displaying API keys.
1490 *
1491 * @since 1.0
1492 */
1493 do_action( 'give_tools_api_keys_before' );
1494
1495 require_once GIVE_PLUGIN_DIR . 'includes/admin/class-api-keys-table.php';
1496
1497 $api_keys_table = new Give_API_Keys_Table();
1498 $api_keys_table->prepare_items();
1499 $api_keys_table->display();
1500 ?>
1501 <span class="cmb2-metabox-description api-description">
1502 <?php
1503 echo sprintf(
1504 /* translators: 1: http://docs.givewp.com/api 2: http://docs.givewp.com/addon-zapier */
1505 __( 'You can create API keys for individual users within their profile edit screen. API keys allow users to use the <a href="%1$s" target="_blank">Give REST API</a> to retrieve donation data in JSON or XML for external applications or devices, such as <a href="%2$s" target="_blank">Zapier</a>.', 'give' ),
1506 esc_url( 'http://docs.givewp.com/api' ),
1507 esc_url( 'http://docs.givewp.com/addon-zapier' )
1508 );
1509 ?>
1510 </span>
1511 <?php
1512
1513 /**
1514 * Fires after displaying API keys.
1515 *
1516 * @since 1.0
1517 */
1518 do_action( 'give_tools_api_keys_after' );
1519 }
1520
1521 add_action( 'give_settings_tab_api_keys', 'give_api_callback' );
1522
1523 /**
1524 * Hook Callback
1525 *
1526 * Adds a do_action() hook in place of the field.
1527 *
1528 * @since 1.0
1529 *
1530 * @param array $args Arguments passed by the setting
1531 *
1532 * @return void
1533 */
1534 function give_hook_callback( $args ) {
1535
1536 $id = $args['id'];
1537
1538 /**
1539 * Fires in give field.
1540 *
1541 * @since 1.0
1542 */
1543 do_action( "give_{$id}" );
1544
1545 }
1546
1547
1548 /**
1549 * Check if radio(enabled/disabled) and checkbox(on) is active or not.
1550 *
1551 * @since 1.8
1552 *
1553 * @param mixed $value
1554 * @param string $compare_with
1555 *
1556 * @return bool
1557 */
1558 function give_is_setting_enabled( $value, $compare_with = null ) {
1559 if ( ! is_null( $compare_with ) ) {
1560
1561 if ( is_array( $compare_with ) ) {
1562 // Output.
1563 return in_array( $value, $compare_with );
1564 }
1565
1566 // Output.
1567 return ( $value === $compare_with );
1568 }
1569
1570 // Backward compatibility: From version 1.8 most of setting is modified to enabled/disabled
1571 // Output.
1572 return ( in_array( $value, array( 'enabled', 'on', 'yes' ) ) ? true : false );
1573 }
1574