PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.4.3
GiveWP – Donation Plugin and Fundraising Platform v2.4.3
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 7 years ago add-ons.php 7 years ago admin-actions.php 7 years ago admin-filters.php 7 years ago admin-footer.php 7 years ago admin-pages.php 7 years ago class-addon-activation-banner.php 7 years ago class-admin-settings.php 7 years ago class-api-keys-table.php 7 years ago class-blank-slate.php 7 years ago class-give-admin.php 7 years ago class-give-html-elements.php 7 years ago class-give-settings.php 7 years ago class-i18n-module.php 8 years ago dashboard-widgets.php 7 years ago give-metabox-functions.php 7 years ago import-functions.php 7 years ago plugins.php 7 years ago setting-page-functions.php 7 years ago welcome.php 7 years ago
class-give-settings.php
1386 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 /**
864 * Gateways Callback
865 *
866 * Renders gateways fields.
867 *
868 * @since 1.0
869 *
870 * @param array $field_arr
871 * @param array $saved_values
872 *
873 * @return void
874 */
875 function give_enabled_gateways_callback( $field_arr, $saved_values = array() ) {
876 $saved_values = __give_validate_active_gateways( $saved_values );
877 $id = $field_arr['id'];
878 $gateways = give_get_ordered_payment_gateways( give_get_payment_gateways() );
879
880 echo '<ul class="give-checklist-fields give-payment-gatways-list">';
881
882 foreach ( $gateways as $key => $option ) :
883
884 if ( is_array( $saved_values ) && array_key_exists( $key, $saved_values ) ) {
885 $enabled = '1';
886 } else {
887 $enabled = null;
888 }
889
890 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;';
891 echo '<label for="' . $id . '[' . $key . ']">' . $option['admin_label'] . '</label></li>';
892
893 endforeach;
894
895 echo '</ul>';
896 }
897
898 /**
899 * Gateways Callback (drop down)
900 *
901 * Renders gateways select menu
902 *
903 * @since 1.0
904 *
905 * @param array $field_arr
906 * @param array $saved_value
907 *
908 * @return void
909 */
910 function give_default_gateway_callback( $field_arr, $saved_value ) {
911 $id = $field_arr['id'];
912 $gateways = give_get_enabled_payment_gateways();
913 $saved_value = give_get_default_gateway( null );
914
915 echo '<select class="give-select" name="' . $id . '" id="' . $id . '">';
916
917 foreach ( $gateways as $key => $option ) :
918 $selected = isset( $saved_value ) ? selected( $key, $saved_value, false ) : '';
919 echo '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
920 endforeach;
921
922 echo '</select>';
923
924 }
925
926 /**
927 * Give Title
928 *
929 * Renders custom section titles output; Really only an because CMB2's output is a bit funky
930 *
931 * @since 1.0
932 *
933 * @param $field_object , $escaped_value, $object_id, $object_type, $field_type_object
934 *
935 * @return void
936 */
937 function give_title_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
938
939 $id = $field_type_object->field->args['id'];
940 $title = $field_type_object->field->args['name'];
941 $field_description = $field_type_object->field->args['desc'];
942
943 echo '<hr>' . $field_description;
944
945 }
946
947 /**
948 * Give Description
949 *
950 * Renders custom description text which any plugin can use to output content, html, php, etc.
951 *
952 * @since 1.3.5
953 *
954 * @param $field_object , $escaped_value, $object_id, $object_type, $field_type_object
955 *
956 * @return void
957 */
958 function give_description_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
959
960 $id = $field_type_object->field->args['id'];
961 $title = $field_type_object->field->args['name'];
962 $field_description = $field_type_object->field->args['desc'];
963
964 echo $field_description;
965
966 }
967
968 /**
969 * Gets a number of posts and displays them as options
970 *
971 * @param array $query_args Optional. Overrides defaults.
972 * @param bool $force Force the pages to be loaded even if not on settings
973 *
974 * @see: https://github.com/WebDevStudios/CMB2/wiki/Adding-your-own-field-types
975 * @return array An array of options that matches the CMB2 options array
976 */
977 function give_cmb2_get_post_options( $query_args, $force = false ) {
978
979 $post_options = array( '' => '' ); // Blank option
980
981 if ( ( ! isset( $_GET['page'] ) || 'give-settings' != $_GET['page'] ) && ! $force ) {
982 return $post_options;
983 }
984
985 $args = wp_parse_args(
986 $query_args, array(
987 'post_type' => 'page',
988 'numberposts' => 10,
989 )
990 );
991
992 $posts = get_posts( $args );
993
994 if ( $posts ) {
995 foreach ( $posts as $post ) {
996
997 $post_options[ $post->ID ] = $post->post_title;
998
999 }
1000 }
1001
1002 return $post_options;
1003 }
1004
1005
1006 /**
1007 * Featured Image Sizes
1008 *
1009 * Outputs an array for the "Featured Image Size" option found under Settings > Display Options.
1010 *
1011 * @since 1.4
1012 *
1013 * @global $_wp_additional_image_sizes
1014 *
1015 * @return array $sizes
1016 */
1017 function give_get_featured_image_sizes() {
1018 global $_wp_additional_image_sizes;
1019
1020 $sizes = array();
1021 $get_sizes = get_intermediate_image_sizes();
1022 $core_image_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' );
1023
1024 // This will help us to filter special characters from a string
1025 $filter_slug_items = array( '_', '-' );
1026
1027 foreach ( $get_sizes as $_size ) {
1028
1029 // Converting image size slug to title case
1030 $sizes[ $_size ] = give_slug_to_title( $_size, $filter_slug_items );
1031
1032 if ( in_array( $_size, $core_image_sizes ) ) {
1033 $sizes[ $_size ] .= ' (' . get_option( "{$_size}_size_w" ) . 'x' . get_option( "{$_size}_size_h" );
1034 } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
1035 $sizes[ $_size ] .= " ({$_wp_additional_image_sizes[ $_size ]['width']} x {$_wp_additional_image_sizes[ $_size ]['height']}";
1036 }
1037
1038 // Based on the above image height check, label the respective resolution as responsive
1039 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" ) ) ) {
1040 $sizes[ $_size ] .= ' - responsive';
1041 }
1042
1043 $sizes[ $_size ] .= ')';
1044
1045 }
1046
1047 return apply_filters( 'give_get_featured_image_sizes', $sizes );
1048 }
1049
1050
1051 /**
1052 * Slug to Title
1053 *
1054 * Converts a string with hyphen(-) or underscores(_) or any special character to a string with Title case
1055 *
1056 * @since 1.8.8
1057 *
1058 * @params $string text
1059 * @params $filter array
1060 *
1061 * @return text $string
1062 */
1063 function give_slug_to_title( $string, $filters = array() ) {
1064
1065 foreach ( $filters as $filter_item ) {
1066 $string = str_replace( $filter_item, ' ', $string );
1067 }
1068
1069 // Return updated string after converting it to title case
1070 return ucwords( $string );
1071
1072 }
1073
1074
1075 /**
1076 * Give License Key Callback
1077 *
1078 * Registers the license field callback for EDD's Software Licensing.
1079 *
1080 * @since 1.0
1081 *
1082 * @param array $field_object , $escaped_value, $object_id, $object_type, $field_type_object Arguments passed by CMB2
1083 *
1084 * @return void
1085 */
1086 function give_license_key_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
1087 /* @var CMB2_Types $field_type_object */
1088
1089 $id = $field_type_object->field->args['id'];
1090 $field_description = $field_type_object->field->args['desc'];
1091 $license = $field_type_object->field->args['options']['license'];
1092 $license_key = $escaped_value;
1093 $is_license_key = apply_filters( 'give_is_license_key', ( is_object( $license ) && ! empty( $license ) ) );
1094 $is_valid_license = apply_filters( 'give_is_valid_license', ( $is_license_key && property_exists( $license, 'license' ) && 'valid' === $license->license ) );
1095 $shortname = $field_type_object->field->args['options']['shortname'];
1096 $field_classes = 'regular-text give-license-field';
1097 $type = empty( $escaped_value ) || ! $is_valid_license ? 'text' : 'password';
1098 $custom_html = '';
1099 $messages = array();
1100 $class = '';
1101 $account_page_link = $field_type_object->field->args['options']['account_url'];
1102 $checkout_page_link = $field_type_object->field->args['options']['checkout_url'];
1103 $addon_name = $field_type_object->field->args['options']['item_name'];
1104 $license_status = null;
1105 $is_in_subscription = null;
1106
1107 // By default query on edd api url will return license object which contain status and message property, this can break below functionality.
1108 // To combat that check if status is set to error or not, if yes then set $is_license_key to false.
1109 if ( $is_license_key && property_exists( $license, 'status' ) && 'error' === $license->status ) {
1110 $is_license_key = false;
1111 }
1112
1113 // Check if current license is part of subscription or not.
1114 $subscriptions = get_option( 'give_subscriptions' );
1115
1116 if ( $is_license_key && $subscriptions ) {
1117 foreach ( $subscriptions as $subscription ) {
1118 if ( in_array( $license_key, $subscription['licenses'] ) ) {
1119 $is_in_subscription = $subscription['id'];
1120 break;
1121 }
1122 }
1123 }
1124
1125 if ( $is_license_key ) {
1126
1127 if ( empty( $license->success ) && property_exists( $license, 'error' ) ) {
1128
1129 // activate_license 'invalid' on anything other than valid, so if there was an error capture it
1130 switch ( $license->error ) {
1131 case 'expired':
1132 $class = $license->error;
1133 $messages[] = sprintf(
1134 __( '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' ),
1135 date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1136 $checkout_page_link . '?edd_license_key=' . $license_key . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
1137 );
1138 $license_status = 'license-' . $class;
1139 break;
1140
1141 case 'missing':
1142 $class = $license->error;
1143 $messages[] = sprintf(
1144 __( 'Invalid license. Please <a href="%s" target="_blank" title="Visit account page">visit your account page</a> and verify it.', 'give' ),
1145 $account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=missing'
1146 );
1147 $license_status = 'license-' . $class;
1148 break;
1149
1150 case 'invalid':
1151 $class = $license->error;
1152 $messages[] = sprintf(
1153 __( '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' ),
1154 $addon_name,
1155 $account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1156 );
1157 $license_status = 'license-' . $class;
1158 break;
1159
1160 case 'site_inactive':
1161 $class = $license->error;
1162 $messages[] = sprintf(
1163 __( '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' ),
1164 $addon_name,
1165 $account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1166 );
1167 $license_status = 'license-' . $class;
1168 break;
1169
1170 case 'item_name_mismatch':
1171 $class = $license->error;
1172 $messages[] = sprintf( __( 'This license %1$s does not belong to %2$s.', 'give' ), $license_key, $addon_name );
1173 $license_status = 'license-' . $class;
1174 break;
1175
1176 case 'no_activations_left':
1177 $class = $license->error;
1178 $messages[] = sprintf( __( 'Your license key has reached it\'s activation limit. <a href="%s">View possible upgrades</a> now.', 'give' ), $account_page_link );
1179 $license_status = 'license-' . $class;
1180 break;
1181
1182 default:
1183 $class = $license->error;
1184 $messages[] = sprintf(
1185 __( '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' ),
1186 $license->error,
1187 '<br/>',
1188 "{$account_page_link}?utm_campaign=admin&utm_source=licenses&utm_medium={$license->error}"
1189 );
1190 $license_status = 'license-error';
1191 break;
1192 }
1193 } elseif ( $is_in_subscription ) {
1194
1195 $subscription_expires = strtotime( $subscriptions[ $is_in_subscription ]['expires'] );
1196 $subscription_status = __( 'renew', 'give' );
1197
1198 if ( ( 'active' !== $subscriptions[ $is_in_subscription ]['status'] ) ) {
1199 $subscription_status = __( 'expire', 'give' );
1200 }
1201
1202 if ( $subscription_expires < current_time( 'timestamp', 1 ) ) {
1203 $messages[] = sprintf(
1204 __( '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' ),
1205 urldecode( $subscriptions[ $is_in_subscription ]['invoice_url'] ),
1206 $subscriptions[ $is_in_subscription ]['payment_id'],
1207 $checkout_page_link . '?edd_license_key=' . $subscriptions[ $is_in_subscription ]['license_key'] . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
1208 );
1209 $license_status = 'license-expired';
1210 } elseif ( strtotime( '- 7 days', $subscription_expires ) < current_time( 'timestamp', 1 ) ) {
1211 $messages[] = sprintf(
1212 __( 'Your subscription (<a href="%1$s" target="_blank">#%2$d</a>) will %3$s in %4$s.', 'give' ),
1213 urldecode( $subscriptions[ $is_in_subscription ]['invoice_url'] ),
1214 $subscriptions[ $is_in_subscription ]['payment_id'],
1215 $subscription_status,
1216 human_time_diff( current_time( 'timestamp', 1 ), strtotime( $subscriptions[ $is_in_subscription ]['expires'] ) )
1217 );
1218 $license_status = 'license-expires-soon';
1219 } else {
1220 $messages[] = sprintf(
1221 __( 'Your subscription (<a href="%1$s" target="_blank">#%2$d</a>) will %3$s on %4$s.', 'give' ),
1222 urldecode( $subscriptions[ $is_in_subscription ]['invoice_url'] ),
1223 $subscriptions[ $is_in_subscription ]['payment_id'],
1224 $subscription_status,
1225 date_i18n( get_option( 'date_format' ), strtotime( $subscriptions[ $is_in_subscription ]['expires'], current_time( 'timestamp' ) ) )
1226 );
1227 $license_status = 'license-expiration-date';
1228 }
1229 } elseif ( empty( $license->success ) ) {
1230 $class = 'invalid';
1231 $messages[] = sprintf(
1232 __( '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' ),
1233 $addon_name,
1234 $account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1235 );
1236 $license_status = 'license-' . $class;
1237
1238 } else {
1239 switch ( $license->license ) {
1240 case 'valid':
1241 default:
1242 $class = 'valid';
1243 $now = current_time( 'timestamp' );
1244 $expiration = strtotime( $license->expires, current_time( 'timestamp' ) );
1245
1246 if ( 'lifetime' === $license->expires ) {
1247 $messages[] = __( 'License key never expires.', 'give' );
1248 $license_status = 'license-lifetime-notice';
1249 } elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
1250 $messages[] = sprintf(
1251 __( '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' ),
1252 date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1253 $checkout_page_link . '?edd_license_key=' . $license_key . '&utm_campaign=admin&utm_source=licenses&utm_medium=renew'
1254 );
1255 $license_status = 'license-expires-soon';
1256 } else {
1257 $messages[] = sprintf(
1258 __( 'Your license key expires on %s.', 'give' ),
1259 date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
1260 );
1261 $license_status = 'license-expiration-date';
1262 }
1263 break;
1264 }
1265 }
1266 } else {
1267 $messages[] = sprintf(
1268 __( 'To receive updates, please enter your valid %s license key.', 'give' ),
1269 $addon_name
1270 );
1271 $license_status = 'inactive';
1272 }
1273
1274 // Add class for input field if license is active.
1275 if ( $is_valid_license ) {
1276 $field_classes .= ' give-license-active';
1277 }
1278
1279 // Get input field html.
1280 $input_field_html = "<input type=\"{$type}\" name=\"{$id}\" class=\"{$field_classes}\" value=\"{$license_key}\">";
1281
1282 // If license is active so show deactivate button.
1283 if ( $is_valid_license ) {
1284 // Get input field html.
1285 $input_field_html = "<input type=\"{$type}\" name=\"{$id}\" class=\"{$field_classes}\" value=\"{$license_key}\" readonly=\"readonly\">";
1286
1287 $custom_html = '<input type="submit" class="button button-small give-license-deactivate" name="' . $id . '_deactivate" value="' . esc_attr__( 'Deactivate License', 'give' ) . '"/>';
1288
1289 }
1290
1291 // Field description.
1292 $custom_html .= '<label for="give_settings[' . $id . ']"> ' . $field_description . '</label>';
1293
1294 // If no messages found then inform user that to get updated in future register yourself.
1295 if ( empty( $messages ) ) {
1296 $messages[] = apply_filters( "{$shortname}_default_addon_notice", __( 'To receive updates, please enter your valid license key.', 'give' ) );
1297 }
1298
1299 foreach ( $messages as $message ) {
1300 $custom_html .= '<div class="give-license-status-notice give-' . $license_status . '">';
1301 $custom_html .= '<p>' . $message . '</p>';
1302 $custom_html .= '</div>';
1303 }
1304
1305 // Field html.
1306 $custom_html = apply_filters( 'give_license_key_field_html', $input_field_html . $custom_html, $field_type_object );
1307
1308 // Nonce.
1309 wp_nonce_field( $id . '-nonce', $id . '-nonce' );
1310
1311 // Print field html.
1312 echo "<div class=\"give-license-key\"><label for=\"{$id}\">{$addon_name }</label></div><div class=\"give-license-block\">{$custom_html}</div>";
1313 }
1314
1315
1316 /**
1317 * Display the API Keys
1318 *
1319 * @since 1.0
1320 * @return void
1321 */
1322 function give_api_callback() {
1323
1324 if ( ! current_user_can( 'manage_give_settings' ) ) {
1325 return;
1326 }
1327
1328 /**
1329 * Fires before displaying API keys.
1330 *
1331 * @since 1.0
1332 */
1333 do_action( 'give_tools_api_keys_before' );
1334
1335 require_once GIVE_PLUGIN_DIR . 'includes/admin/class-api-keys-table.php';
1336
1337 $api_keys_table = new Give_API_Keys_Table();
1338 $api_keys_table->prepare_items();
1339 $api_keys_table->display();
1340 ?>
1341 <span class="cmb2-metabox-description api-description">
1342 <?php
1343 echo sprintf(
1344 /* translators: 1: http://docs.givewp.com/api 2: http://docs.givewp.com/addon-zapier */
1345 __( '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' ),
1346 esc_url( 'http://docs.givewp.com/api' ),
1347 esc_url( 'http://docs.givewp.com/addon-zapier' )
1348 );
1349 ?>
1350 </span>
1351 <?php
1352
1353 /**
1354 * Fires after displaying API keys.
1355 *
1356 * @since 1.0
1357 */
1358 do_action( 'give_tools_api_keys_after' );
1359 }
1360
1361 add_action( 'give_settings_tab_api_keys', 'give_api_callback' );
1362
1363 /**
1364 * Hook Callback
1365 *
1366 * Adds a do_action() hook in place of the field.
1367 *
1368 * @since 1.0
1369 *
1370 * @param array $args Arguments passed by the setting
1371 *
1372 * @return void
1373 */
1374 function give_hook_callback( $args ) {
1375
1376 $id = $args['id'];
1377
1378 /**
1379 * Fires in give field.
1380 *
1381 * @since 1.0
1382 */
1383 do_action( "give_{$id}" );
1384
1385 }
1386