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