1 <?php
2 3 4 5 6 7 8 9 10
11
12
13 if ( !defined( 'ABSPATH' ) ) exit;
14
15 16 17 18 19 20 21 22
23 function edd_register_settings() {
24
25 $pages = get_pages();
26 $pages_options = array( 0 => '' );
27 if ( $pages ) {
28 foreach ( $pages as $page ) {
29 $pages_options[ $page->ID ] = $page->post_title;
30 }
31 }
32
33 34 35 36
37 $edd_settings = array(
38
39 'general' => apply_filters('edd_settings_general',
40 array(
41 'test_mode' => array(
42 'id' => 'test_mode',
43 'name' => __('Test Mode', 'edd'),
44 'desc' => __('While in test mode no live transactions are processed. To fully use test mode, you must have a sandbox (test) account for the payment gateway you are testing.', 'edd'),
45 'type' => 'checkbox'
46 ),
47 'purchase_page' => array(
48 'id' => 'purchase_page',
49 'name' => __('Checkout Page', 'edd'),
50 'desc' => __('This is the checkout page where buyers will complete their purchases. The [download_checkout] short code must be on this page.', 'edd'),
51 'type' => 'select',
52 'options' => $pages_options
53 ),
54 'success_page' => array(
55 'id' => 'success_page',
56 'name' => __('Success Page', 'edd'),
57 'desc' => __('This is the page buyers are sent to after completing their purchases. The [edd_receipt] short code should be on this page.', 'edd'),
58 'type' => 'select',
59 'options' => $pages_options
60 ),
61 'failure_page' => array(
62 'id' => 'failure_page',
63 'name' => __('Failed Transaction Page', 'edd'),
64 'desc' => __('This is the page buyers are sent to if their transaction is cancelled or fails', 'edd'),
65 'type' => 'select',
66 'options' => $pages_options
67 ),
68 'currency_settings' => array(
69 'id' => 'currency_settings',
70 'name' => '<strong>' . __('Currency Settings', 'edd') . '</strong>',
71 'desc' => __('Configure the currency options', 'edd'),
72 'type' => 'header'
73 ),
74 'currency' => array(
75 'id' => 'currency',
76 'name' => __('Currency', 'edd'),
77 'desc' => __('Choose your currency. Note that some payment gateways have currency restrictions.', 'edd'),
78 'type' => 'select',
79 'options' => edd_get_currencies()
80 ),
81 'currency_position' => array(
82 'id' => 'currency_position',
83 'name' => __('Currency Position', 'edd'),
84 'desc' => __('Choose the location of the currency sign.', 'edd'),
85 'type' => 'select',
86 'options' => array(
87 'before' => __('Before - $10', 'edd'),
88 'after' => __('After - 10$', 'edd')
89 )
90 ),
91 'thousands_separator' => array(
92 'id' => 'thousands_separator',
93 'name' => __('Thousands Separator', 'edd'),
94 'desc' => __('The symbol (usually , or .) to separate thousands', 'edd'),
95 'type' => 'text',
96 'size' => 'small',
97 'std' => ','
98 ),
99 'decimal_separator' => array(
100 'id' => 'decimal_separator',
101 'name' => __('Decimal Separator', 'edd'),
102 'desc' => __('The symbol (usually , or .) to separate decimal points', 'edd'),
103 'type' => 'text',
104 'size' => 'small',
105 'std' => '.'
106 ),
107 'tracking_settings' => array(
108 'id' => 'tracking_settings',
109 'name' => '<strong>' . __('Usage Tracking', 'edd') . '</strong>',
110 'desc' => '',
111 'type' => 'header'
112 ),
113 'presstrends' => array(
114 'id' => 'presstrends',
115 'name' => __('Enable Tracking', 'edd'),
116 'desc' => __('Check this box to allow Easy Digital Downloads to track how the plugin is used. No personal info is ever collected. This helps us better improve the plugin.', 'edd'),
117 'type' => 'checkbox'
118 ),
119 'api_settings' => array(
120 'id' => 'api_settings',
121 'name' => '<strong>' . __('API Settings', 'edd') . '</strong>',
122 'desc' => '',
123 'type' => 'header'
124 ),
125 'api_allow_user_keys' => array(
126 'id' => 'api_allow_user_keys',
127 'name' => __('Allow User Keys', 'edd') . '</strong>',
128 'desc' => __('Check this box to allow all users to generate API keys. Users with the \'manage_shop_settings\' capability are always allowed to generate keys.', 'edd'),
129 'type' => 'checkbox'
130 )
131 )
132 ),
133
134 'gateways' => apply_filters('edd_settings_gateways',
135 array(
136 'gateways' => array(
137 'id' => 'gateways',
138 'name' => __('Payment Gateways', 'edd'),
139 'desc' => __('Choose the payment gateways you want to enable.', 'edd'),
140 'type' => 'gateways',
141 'options' => edd_get_payment_gateways()
142 ),
143 'default_gateway' => array(
144 'id' => 'default_gateway',
145 'name' => __('Default Gateway', 'edd'),
146 'desc' => __('This gateway will be loaded automatically with the checkout page.', 'edd'),
147 'type' => 'gateway_select',
148 'options' => edd_get_payment_gateways()
149 ),
150 'accepted_cards' => array(
151 'id' => 'accepted_cards',
152 'name' => __('Accepted Payment Method Icons', 'edd'),
153 'desc' => __('Display icons for the selected payment methods', 'edd') . '<br/>' . __('You will also need to configure your gateway settings if you are accepting credit cards', 'edd'),
154 'type' => 'multicheck',
155 'options' => apply_filters('edd_accepted_payment_icons', array(
156 'mastercard' => 'Mastercard',
157 'visa' => 'Visa',
158 'americanexpress' => 'American Express',
159 'discover' => 'Discover',
160 'paypal' => 'PayPal'
161 )
162 )
163 ),
164 'paypal' => array(
165 'id' => 'paypal',
166 'name' => '<strong>' . __('PayPal Settings', 'edd') . '</strong>',
167 'desc' => __('Configure the PayPal settings', 'edd'),
168 'type' => 'header'
169 ),
170 'paypal_email' => array(
171 'id' => 'paypal_email',
172 'name' => __('PayPal Email', 'edd'),
173 'desc' => __('Enter your PayPal account\'s email', 'edd'),
174 'type' => 'text',
175 'size' => 'regular'
176 ),
177 'paypal_page_style' => array(
178 'id' => 'paypal_page_style',
179 'name' => __('PayPal Page Style', 'edd'),
180 'desc' => __('Enter the name of the page style to use, or leave blank for default', 'edd'),
181 'type' => 'text',
182 'size' => 'regular'
183 ),
184 'disable_paypal_verification' => array(
185 'id' => 'disable_paypal_verification',
186 'name' => __('Disable PayPal IPN Verification', 'edd'),
187 'desc' => __('If payments are not getting marked as complete, then check this box. This forces the site to use a slightly less secure method of verifying purchases.', 'edd'),
188 'type' => 'checkbox'
189 )
190 )
191 ),
192
193 'emails' => apply_filters('edd_settings_emails',
194 array(
195 'email_template' => array(
196 'id' => 'email_template',
197 'name' => __('Email Template', 'edd'),
198 'desc' => __('Choose a template. Click "Save Changes" then "Preview Purchase Receipt" to see the new template.', 'edd'),
199 'type' => 'select',
200 'options' => edd_get_email_templates()
201 ),
202 'email_settings' => array(
203 'id' => 'email_settings',
204 'name' => '',
205 'desc' => '',
206 'type' => 'hook',
207 ),
208 'from_name' => array(
209 'id' => 'from_name',
210 'name' => __('From Name', 'edd'),
211 'desc' => __('The name purchase receipts are said to come from. This should probably be your site or shop name.', 'edd'),
212 'type' => 'text'
213 ),
214 'from_email' => array(
215 'id' => 'from_email',
216 'name' => __('From Email', 'edd'),
217 'desc' => __('Email to send purchase receipts from. This will act as the "from" and "reply-to" address.', 'edd'),
218 'type' => 'text'
219 ),
220 'purchase_subject' => array(
221 'id' => 'purchase_subject',
222 'name' => __('Purchase Email Subject', 'edd'),
223 'desc' => __('Enter the subject line for the purchase receipt email', 'edd'),
224 'type' => 'text'
225 ),
226 'purchase_receipt' => array(
227 'id' => 'purchase_receipt',
228 'name' => __('Purchase Receipt', 'edd'),
229 'desc' => __('Enter the email that is sent to users after completing a successful purchase. HTML is accepted. Available template tags:', 'edd') . '<br/>' .
230 '{download_list} - ' . __('A list of download links for each download purchased', 'edd') . '<br/>' .
231 '{file_urls} - ' . __('A plain-text list of download URLs for each download purchased', 'edd') . '<br/>' .
232 '{name} - ' . __('The buyer\'s first name', 'edd') . '<br/>' .
233 '{fullname} - ' . __('The buyer\'s full name, first and last', 'edd') . '<br/>' .
234 '{username} - ' . __('The buyer\'s user name on the site, if they registered an account', 'edd') . '<br/>' .
235 '{date} - ' . __('The date of the purchase', 'edd') . '<br/>' .
236 '{subtotal} - ' . __('The price of the purchase before taxes', 'edd') . '<br/>' .
237 '{tax} - ' . __('The taxed amount of the purchase', 'edd') . '<br/>' .
238 '{price} - ' . __('The total price of the purchase', 'edd') . '<br/>' .
239 '{payment_id} - ' . __('The unique ID number for this purchase', 'edd') . '<br/>' .
240 '{receipt_id} - ' . __('The unique ID number for this purchase receipt', 'edd') . '<br/>' .
241 '{payment_method} - ' . __('The method of payment used for this purchase', 'edd') . '<br/>' .
242 '{sitename} - ' . __('Your site name', 'edd') . '<br/>' .
243 '{receipt_link} - ' . __( 'Adds a link so users can view their receipt directly on your website if they are unable to view it in the browser correctly.', 'edd' ),
244 'type' => 'rich_editor'
245 ),
246 'admin_notice_emails' => array(
247 'id' => 'admin_notice_emails',
248 'name' => __( 'Sale Notification Emails', 'edd' ),
249 'desc' => __( 'Enter the email address(es) that should receive a notification anytime a sale is made, one per line', 'edd' ),
250 'type' => 'textarea',
251 'std' => get_bloginfo( 'admin_email' )
252 )
253 )
254 ),
255
256 'styles' => apply_filters('edd_settings_styles',
257 array(
258 'disable_styles' => array(
259 'id' => 'disable_styles',
260 'name' => __('Disable Styles', 'edd'),
261 'desc' => __('Check this to disable all included styling of buttons, checkout fields, and all other elements.', 'edd'),
262 'type' => 'checkbox'
263 ),
264 'buton_header' => array(
265 'id' => 'buton_header',
266 'name' => '<strong>' . __('Buttons', 'edd') . '</strong>',
267 'desc' => __('Options for add to cart and purchase buttons', 'edd'),
268 'type' => 'header'
269 ),
270 'button_style' => array(
271 'id' => 'button_style',
272 'name' => __('Default Button Style', 'edd'),
273 'desc' => __('Choose the style you want to use for the buttons.', 'edd'),
274 'type' => 'select',
275 'options' => edd_get_button_styles()
276 ),
277 'checkout_color' => array(
278 'id' => 'checkout_color',
279 'name' => __('Default Button Color', 'edd'),
280 'desc' => __('Choose the color you want to use for the buttons.', 'edd'),
281 'type' => 'select',
282 'options' => edd_get_button_colors()
283 )
284 )
285 ),
286
287 'taxes' => apply_filters('edd_settings_taxes',
288 array(
289 'enable_taxes' => array(
290 'id' => 'enable_taxes',
291 'name' => __('Enable Taxes', 'edd'),
292 'desc' => __('Check this to enable taxes on purchases.', 'edd'),
293 'type' => 'checkbox',
294 'std' => 'no',
295 ),
296 'tax_rate' => array(
297 'id' => 'tax_rate',
298 'name' => __('Tax Rate', 'edd'),
299 'desc' => __('Enter a percentage, such as 6.5.', 'edd'),
300 'type' => 'text',
301 'size' => 'small'
302 ),
303 'prices_include_tax' => array(
304 'id' => 'prices_include_tax',
305 'name' => __('Prices entered with tax', 'edd'),
306 'desc' => __('This option affects how you enter prices.', 'edd'),
307 'type' => 'radio',
308 'std' => 'no',
309 'options' => array(
310 'yes' => __('Yes, I will enter prices inclusive of tax', 'edd'),
311 'no' => __('No, I will enter prices exclusive of tax', 'edd')
312 )
313 ),
314 'tax_condition' => array(
315 'id' => 'tax_condition',
316 'name' => __('Apply Taxes to:', 'edd'),
317 'desc' => __('Who should have tax added to their purchases?', 'edd'),
318 'type' => 'radio',
319 'std' => 'all',
320 'options' => array(
321 'all' => __('Everyone', 'edd'),
322 'local' => __('Local residents only', 'edd')
323 )
324 ),
325 'tax_location' => array(
326 'id' => 'tax_location',
327 'name' => __('Tax Opt-In', 'edd'),
328 'desc' => __('Customers will be given a checkbox to click if they reside in your local area. Please enter directions for them here. Customers <strong>must</strong> opt into this.', 'edd'),
329 'type' => 'text',
330 'size' => 'large'
331 ),
332 'checkout_include_tax' => array(
333 'id' => 'checkout_include_tax',
334 'name' => __('Display during checkout', 'edd'),
335 'desc' => __('Should prices on the checkout page be shown with or without tax?', 'edd'),
336 'type' => 'select',
337 'std' => 'no',
338 'options' => array(
339 'yes' => __('Including tax', 'edd'),
340 'no' => __('Excluding tax', 'edd')
341 )
342 ),
343 'taxes_after_discounts' => array(
344 'id' => 'taxes_after_discounts',
345 'name' => __('Calculate Tax After Discounts?', 'edd'),
346 'desc' => __('Check this if you would like taxes calculated after discounts. By default taxes are calculated before discounts are applied.', 'edd'),
347 'std' => 'no',
348 'type' => 'checkbox'
349 )
350 )
351 ),
352
353 'misc' => apply_filters('edd_settings_misc',
354 array(
355 'disable_ajax_cart' => array(
356 'id' => 'disable_ajax_cart',
357 'name' => __('Disable Ajax', 'edd'),
358 'desc' => __('Check this to disable AJAX for the shopping cart.', 'edd'),
359 'type' => 'checkbox'
360 ),
361 'redirect_on_add' => array(
362 'id' => 'redirect_on_add',
363 'name' => __('Redirect to Checkout', 'edd'),
364 'desc' => __('Immediately redirect to checkout after adding an item to the cart?', 'edd'),
365 'type' => 'checkbox'
366 ),
367 'live_cc_validation' => array(
368 'id' => 'live_cc_validation',
369 'name' => __('Disable Live Credit Card Validation', 'edd'),
370 'desc' => __('Live credit card validation means that that card type and number will be validated as the customer enters the number.', 'edd'),
371 'type' => 'checkbox'
372 ),
373 'logged_in_only' => array(
374 'id' => 'logged_in_only',
375 'name' => __('Disable Guest Checkout', 'edd'),
376 'desc' => __('Require that users be logged-in to purchase files.', 'edd'),
377 'type' => 'checkbox'
378 ),
379 'show_register_form' => array(
380 'id' => 'show_register_form',
381 'name' => __('Show Register / Login Form?', 'edd'),
382 'desc' => __('Display the registration and login forms on the checkout page for non-logged-in users.', 'edd'),
383 'type' => 'checkbox',
384 ),
385 'download_link_expiration' => array(
386 'id' => 'download_link_expiration',
387 'name' => __('Download Link Expiration', 'edd'),
388 'desc' => __('How long should download links be valid for? Default is 24 hours from the time they are generated. Enter a time in hours.', 'edd'),
389 'type' => 'text',
390 'size' => 'small'
391 ),
392 'disable_redownload' => array(
393 'id' => 'disable_redownload',
394 'name' => __('Disable Redownload?', 'edd'),
395 'desc' => __('Check this if you do not want to allow users to redownload items from their purchase history.', 'edd'),
396 'type' => 'checkbox',
397 ),
398 'symlink_file_downloads' => array(
399 'id' => 'symlink_file_downloads',
400 'name' => __('Symlink File Downloads?', 'edd'),
401 'desc' => __('Check this if you are delivering really large files or having problems with file downloads completing.', 'edd'),
402 'type' => 'checkbox',
403 ),
404 'terms' => array(
405 'id' => 'terms',
406 'name' => '<strong>' . __('Terms of Agreement', 'edd') . '</strong>',
407 'desc' => '',
408 'type' => 'header',
409 ),
410 'show_agree_to_terms' => array(
411 'id' => 'show_agree_to_terms',
412 'name' => __('Agree to Terms', 'edd'),
413 'desc' => __('Check this to show an agree to terms on the checkout that users must agree to before purchasing.', 'edd'),
414 'type' => 'checkbox',
415 ),
416 'agree_label' => array(
417 'id' => 'agree_label',
418 'name' => __('Agree to Terms Label', 'edd'),
419 'desc' => __('Label shown next to the agree to terms check box.', 'edd'),
420 'type' => 'text',
421 'size' => 'regular'
422 ),
423 'agree_text' => array(
424 'id' => 'agree_text',
425 'name' => __('Agreement Text', 'edd'),
426 'desc' => __('If Agree to Terms is checked, enter the agreement terms here.', 'edd'),
427 'type' => 'rich_editor',
428 ),
429 'checkout_label' => array(
430 'id' => 'checkout_label',
431 'name' => __('Complete Purchase Text', 'edd'),
432 'desc' => __('The button label for completing a purchase.', 'edd'),
433 'type' => 'text',
434 ),
435 'add_to_cart_text' => array(
436 'id' => 'add_to_cart_text',
437 'name' => __('Add to Cart Text', 'edd'),
438 'desc' => __('Text shown on the Add to Cart Buttons', 'edd'),
439 'type' => 'text'
440 )
441 )
442 )
443 );
444
445 if ( false == get_option( 'edd_settings_general' ) ) {
446 add_option( 'edd_settings_general' );
447 }
448
449 if ( false == get_option( 'edd_settings_gateways' ) ) {
450 add_option( 'edd_settings_gateways' );
451 }
452
453 if ( false == get_option( 'edd_settings_emails' ) ) {
454 add_option( 'edd_settings_emails' );
455 }
456
457 if ( false == get_option( 'edd_settings_styles' ) ) {
458 add_option( 'edd_settings_styles' );
459 }
460
461 if ( false == get_option( 'edd_settings_taxes' ) ) {
462 add_option( 'edd_settings_taxes' );
463 }
464
465 if ( false == get_option( 'edd_settings_misc' ) ) {
466 add_option( 'edd_settings_misc' );
467 }
468
469 add_settings_section(
470 'edd_settings_general',
471 __( 'General Settings', 'edd' ),
472 '__return_false',
473 'edd_settings_general'
474 );
475
476 foreach ( $edd_settings['general'] as $option ) {
477 add_settings_field(
478 'edd_settings_general[' . $option['id'] . ']',
479 $option['name'],
480 function_exists( 'edd_' . $option['type'] . '_callback' ) ? 'edd_' . $option['type'] . '_callback' : 'edd_missing_callback',
481 'edd_settings_general',
482 'edd_settings_general',
483 array(
484 'id' => $option['id'],
485 'desc' => $option['desc'],
486 'name' => $option['name'],
487 'section' => 'general',
488 'size' => isset( $option['size'] ) ? $option['size'] : null,
489 'options' => isset( $option['options'] ) ? $option['options'] : '',
490 'std' => isset( $option['std'] ) ? $option['std'] : ''
491 )
492 );
493 }
494
495 add_settings_section(
496 'edd_settings_gateways',
497 __( 'Payment Gateway Settings', 'edd' ),
498 '__return_false',
499 'edd_settings_gateways'
500 );
501
502 foreach ( $edd_settings['gateways'] as $option ) {
503 add_settings_field(
504 'edd_settings_gateways[' . $option['id'] . ']',
505 $option['name'],
506 function_exists( 'edd_' . $option['type'] . '_callback' ) ? 'edd_' . $option['type'] . '_callback' : 'edd_missing_callback',
507 'edd_settings_gateways',
508 'edd_settings_gateways',
509 array(
510 'id' => $option['id'],
511 'desc' => $option['desc'],
512 'name' => $option['name'],
513 'section' => 'gateways',
514 'size' => isset( $option['size'] ) ? $option['size'] : null,
515 'options' => isset( $option['options'] ) ? $option['options'] : '',
516 'std' => isset( $option['std'] ) ? $option['std'] : ''
517 )
518 );
519 }
520
521 add_settings_section(
522 'edd_settings_emails',
523 __( 'Email Settings', 'edd' ),
524 '__return_false',
525 'edd_settings_emails'
526 );
527
528 foreach ( $edd_settings['emails'] as $option ) {
529 add_settings_field(
530 'edd_settings_emails[' . $option['id'] . ']',
531 $option['name'],
532 function_exists( 'edd_' . $option['type'] . '_callback' ) ? 'edd_' . $option['type'] . '_callback' : 'edd_missing_callback',
533 'edd_settings_emails',
534 'edd_settings_emails',
535 array(
536 'id' => $option['id'],
537 'desc' => $option['desc'],
538 'name' => $option['name'],
539 'section' => 'emails',
540 'size' => isset( $option['size'] ) ? $option['size'] : null,
541 'options' => isset( $option['options'] ) ? $option['options'] : '',
542 'std' => isset( $option['std'] ) ? $option['std'] : ''
543 )
544 );
545 }
546
547 add_settings_section(
548 'edd_settings_styles',
549 __( 'Style Settings', 'edd' ),
550 '__return_false',
551 'edd_settings_styles'
552 );
553
554 foreach ( $edd_settings['styles'] as $option ) {
555 add_settings_field(
556 'edd_settings_styles[' . $option['id'] . ']',
557 $option['name'],
558 function_exists( 'edd_' . $option['type'] . '_callback' ) ? 'edd_' . $option['type'] . '_callback' : 'edd_missing_callback',
559 'edd_settings_styles',
560 'edd_settings_styles',
561 array(
562 'id' => $option['id'],
563 'desc' => $option['desc'],
564 'name' => $option['name'],
565 'section' => 'styles',
566 'size' => isset( $option['size'] ) ? $option['size'] : '' ,
567 'options' => isset( $option['options'] ) ? $option['options'] : '',
568 'std' => isset( $option['std'] ) ? $option['std'] : ''
569 )
570 );
571 }
572
573 add_settings_section(
574 'edd_settings_taxes',
575 __( 'Tax Settings', 'edd' ),
576 'edd_settings_taxes_description_callback',
577 'edd_settings_taxes'
578 );
579
580 foreach ( $edd_settings['taxes'] as $option ) {
581 add_settings_field(
582 'edd_settings_taxes[' . $option['id'] . ']',
583 $option['name'],
584 'edd_' . $option['type'] . '_callback',
585 'edd_settings_taxes',
586 'edd_settings_taxes',
587 array(
588 'id' => $option['id'],
589 'desc' => $option['desc'],
590 'name' => $option['name'],
591 'section' => 'taxes',
592 'size' => isset( $option['size'] ) ? $option['size'] : '' ,
593 'options' => isset( $option['options'] ) ? $option['options'] : '',
594 'std' => isset( $option['std'] ) ? $option['std'] : ''
595 )
596 );
597 }
598
599 add_settings_section(
600 'edd_settings_misc',
601 __( 'Misc Settings', 'edd' ),
602 '__return_false',
603 'edd_settings_misc'
604 );
605
606 foreach ( $edd_settings['misc'] as $option ) {
607 add_settings_field(
608 'edd_settings_misc[' . $option['id'] . ']',
609 $option['name'],
610 function_exists( 'edd_' . $option['type'] . '_callback' ) ? 'edd_' . $option['type'] . '_callback' : 'edd_missing_callback',
611 'edd_settings_misc',
612 'edd_settings_misc',
613 array(
614 'id' => $option['id'],
615 'desc' => $option['desc'],
616 'name' => $option['name'],
617 'section' => 'misc',
618 'size' => isset( $option['size'] ) ? $option['size'] : '' ,
619 'options' => isset( $option['options'] ) ? $option['options'] : '',
620 'std' => isset( $option['std'] ) ? $option['std'] : ''
621 )
622 );
623 }
624
625
626 register_setting( 'edd_settings_general', 'edd_settings_general', 'edd_settings_sanitize' );
627 register_setting( 'edd_settings_gateways', 'edd_settings_gateways', 'edd_settings_sanitize' );
628 register_setting( 'edd_settings_emails', 'edd_settings_emails', 'edd_settings_sanitize' );
629 register_setting( 'edd_settings_styles', 'edd_settings_styles', 'edd_settings_sanitize' );
630 register_setting( 'edd_settings_taxes', 'edd_settings_taxes', 'edd_settings_sanitize' );
631 register_setting( 'edd_settings_misc', 'edd_settings_misc', 'edd_settings_sanitize' );
632 }
633 add_action('admin_init', 'edd_register_settings');
634
635 636 637 638 639 640 641 642
643 function edd_settings_taxes_description_callback() {
644 echo __( 'These settings will let you configure simple tax rules for purchases.', 'edd' );
645 }
646
647 648 649 650 651 652 653 654 655
656 function ( $args ) {
657 echo '';
658 }
659
660 661 662 663 664 665 666 667 668 669
670 function edd_checkbox_callback( $args ) {
671 global $edd_options;
672
673 $checked = isset($edd_options[$args['id']]) ? checked(1, $edd_options[$args['id']], false) : '';
674 $html = '<input type="checkbox" id="edd_settings_' . $args['section'] . '[' . $args['id'] . ']" name="edd_settings_' . $args['section'] . '[' . $args['id'] . ']" value="1" ' . $checked . '/>';
675 $html .= '<label for="edd_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
676
677 echo $html;
678 }
679
680 681 682 683 684 685 686 687 688 689
690 function edd_multicheck_callback( $args ) {
691 global $edd_options;
692
693 foreach( $args['options'] as $key => $option ):
694 if( isset( $edd_options[$args['id']][$key] ) ) { $enabled = $option; } else { $enabled = NULL; }
695 echo '<input name="edd_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']"" id="edd_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" type="checkbox" value="' . $option . '" ' . checked($option, $enabled, false) . '/> ';
696 echo '<label for="edd_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']">' . $option . '</label><br/>';
697 endforeach;
698 echo '<p class="description">' . $args['desc'] . '</p>';
699 }
700
701 702 703 704 705 706 707 708 709 710
711 function edd_radio_callback( $args ) {
712 global $edd_options;
713
714 foreach ( $args['options'] as $key => $option ) :
715 $checked = false;
716
717 if ( isset( $edd_options[ $args['id'] ] ) && $edd_options[ $args['id'] ] == $key )
718 $checked = true;
719
720 echo '<input name="edd_settings_' . $args['section'] . '[' . $args['id'] . ']"" id="edd_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" type="radio" value="' . $key . '" ' . checked(true, $checked, false) . '/> ';
721 echo '<label for="edd_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']">' . $option . '</label><br/>';
722 endforeach;
723
724 echo '<p class="description">' . $args['desc'] . '</p>';
725 }
726
727 728 729 730 731 732 733 734 735 736
737 function edd_gateways_callback( $args ) {
738 global $edd_options;
739
740 foreach ( $args['options'] as $key => $option ) :
741 if ( isset( $edd_options['gateways'][ $key ] ) )
742 $enabled = '1';
743 else
744 $enabled = null;
745
746 echo '<input name="edd_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']"" id="edd_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> ';
747 echo '<label for="edd_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']">' . $option['admin_label'] . '</label><br/>';
748 endforeach;
749 }
750
751 752 753 754 755 756 757 758 759 760
761 function edd_gateway_select_callback($args) {
762 global $edd_options;
763
764 echo '<select name="edd_settings_' . $args['section'] . '[' . $args['id'] . ']"" id="edd_settings_' . $args['section'] . '[' . $args['id'] . ']">';
765
766 foreach ( $args['options'] as $key => $option ) :
767 $selected = isset( $edd_options[ $args['id'] ] ) ? selected( $key, $edd_options[$args['id']], false ) : '';
768 echo '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
769 endforeach;
770
771 echo '</select>';
772 echo '<label for="edd_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
773 }
774
775 776 777 778 779 780 781 782 783 784
785 function edd_text_callback( $args ) {
786 global $edd_options;
787
788 if ( isset( $edd_options[ $args['id'] ] ) )
789 $value = $edd_options[ $args['id'] ];
790 else
791 $value = isset( $args['std'] ) ? $args['std'] : '';
792
793 $size = isset( $args['size'] ) && !is_null($args['size']) ? $args['size'] : 'regular';
794 $html = '<input type="text" class="' . $args['size'] . '-text" id="edd_settings_' . $args['section'] . '[' . $args['id'] . ']" name="edd_settings_' . $args['section'] . '[' . $args['id'] . ']" value="' . esc_attr( $value ) . '"/>';
795 $html .= '<label for="edd_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
796
797 echo $html;
798 }
799
800 801 802 803 804 805 806 807 808 809
810 function edd_textarea_callback( $args ) {
811 global $edd_options;
812
813 if ( isset( $edd_options[ $args['id'] ] ) )
814 $value = $edd_options[ $args['id'] ];
815 else
816 $value = isset( $args['std'] ) ? $args['std'] : '';
817
818 $size = isset( $args['size'] ) && !is_null($args['size']) ? $args['size'] : 'regular';
819 $html = '<textarea class="large-text" cols="50" rows="5" id="edd_settings_' . $args['section'] . '[' . $args['id'] . ']" name="edd_settings_' . $args['section'] . '[' . $args['id'] . ']">' . esc_textarea( $value ) . '</textarea>';
820 $html .= '<label for="edd_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
821
822 echo $html;
823 }
824
825 826 827 828 829 830 831 832 833 834
835 function edd_password_callback( $args ) {
836 global $edd_options;
837
838 if ( isset( $edd_options[ $args['id'] ] ) )
839 $value = $edd_options[ $args['id'] ];
840 else
841 $value = isset( $args['std'] ) ? $args['std'] : '';
842
843 $size = isset( $args['size'] ) && !is_null($args['size']) ? $args['size'] : 'regular';
844 $html = '<input type="password" class="' . $args['size'] . '-text" id="edd_settings_' . $args['section'] . '[' . $args['id'] . ']" name="edd_settings_' . $args['section'] . '[' . $args['id'] . ']" value="' . esc_attr( $value ) . '"/>';
845 $html .= '<label for="edd_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
846
847 echo $html;
848 }
849
850 851 852 853 854 855 856 857 858
859 function edd_missing_callback($args) {
860 printf( __( 'The callback function used for the <strong>%s</strong> setting is missing.', 'edd' ), $args['id'] );
861 }
862
863 864 865 866 867 868 869 870 871 872
873 function edd_select_callback($args) {
874 global $edd_options;
875
876 $html = '<select id="edd_settings_' . $args['section'] . '[' . $args['id'] . ']" name="edd_settings_' . $args['section'] . '[' . $args['id'] . ']"/>';
877
878 foreach ( $args['options'] as $option => $name ) :
879 $selected = isset( $edd_options[ $args['id'] ] ) ? selected( $option, $edd_options[$args['id']], false ) : '';
880 $html .= '<option value="' . $option . '" ' . $selected . '>' . $name . '</option>';
881 endforeach;
882
883 $html .= '</select>';
884 $html .= '<label for="edd_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
885
886 echo $html;
887 }
888
889 890 891 892 893 894 895 896 897 898
899 function edd_rich_editor_callback( $args ) {
900 global $edd_options, $wp_version;
901
902 if ( isset( $edd_options[ $args['id'] ] ) )
903 $value = $edd_options[ $args['id'] ];
904 else
905 $value = isset( $args['std'] ) ? $args['std'] : '';
906
907 if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
908 $html = wp_editor( $value, 'edd_settings_' . $args['section'] . '[' . $args['id'] . ']', array( 'textarea_name' => 'edd_settings_' . $args['section'] . '[' . $args['id'] . ']' ) );
909 } else {
910 $html = '<textarea class="large-text" rows="10" id="edd_settings_' . $args['section'] . '[' . $args['id'] . ']" name="edd_settings_' . $args['section'] . '[' . $args['id'] . ']">' . esc_textarea( $value ) . '</textarea>';
911 }
912
913 $html .= '<br/><label for="edd_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
914
915 echo $html;
916 }
917
918 919 920 921 922 923 924 925 926 927
928 function edd_upload_callback($args) {
929 global $edd_options;
930
931 if ( isset( $edd_options[ $args['id'] ] ) )
932 $value = $edd_options[$args['id']];
933 else
934 $value = isset($args['std']) ? $args['std'] : '';
935
936 $size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
937
938 $html = '<input type="text" class="' . $args['size'] . '-text edd_upload_field" id="edd_settings_' . $args['section'] . '[' . $args['id'] . ']" name="edd_settings_' . $args['section'] . '[' . $args['id'] . ']" value="' . esc_attr( $value ) . '"/>';
939 $html .= '<span> <input type="button" class="edd_upload_image_button button-secondary" value="' . __( 'Upload File', 'edd' ) . '"/></span>';
940 $html .= '<label for="edd_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
941
942 echo $html;
943 }
944
945 946 947 948 949 950 951 952
953 if ( ! function_exists( 'edd_license_key_callback' ) ) {
954 function edd_license_key_callback( $args ) {
955 global $edd_options;
956
957 if ( isset( $edd_options[ $args['id'] ] ) )
958 $value = $edd_options[ $args['id'] ];
959 else
960 $value = isset( $args['std'] ) ? $args['std'] : '';
961
962 $size = isset( $args['size'] ) && !is_null($args['size']) ? $args['size'] : 'regular';
963
964 $html = '<input type="text" class="' . $args['size'] . '-text" id="edd_settings_' . $args['section'] . '[' . $args['id'] . ']" name="edd_settings_' . $args['section'] . '[' . $args['id'] . ']" value="' . esc_attr( $value ) . '"/>';
965
966 if ( 'valid' == get_option( $args['options']['is_valid_license_option'] ) ) {
967 $html .= wp_nonce_field( $args['id'] . '_nonce', $args['id'] . '_nonce', false );
968 $html .= '<input type="submit" class="button-secondary" name="' . $args['id'] . '_deactivate" value="' . __( 'Deactivate License', 'edd' ) . '"/>';
969 }
970
971 $html .= '<label for="edd_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
972
973 echo $html;
974 }
975 }
976
977 978 979 980 981 982 983 984 985
986 function edd_hook_callback( $args ) {
987 do_action( 'edd_' . $args['id'] );
988 }
989
990 991 992 993 994 995 996 997 998 999
1000 function edd_settings_sanitize( $input ) {
1001 add_settings_error( 'edd-notices', '', __('Settings Updated', 'edd'), 'updated' );
1002 return $input;
1003 }
1004
1005 1006 1007 1008 1009 1010 1011 1012
1013 function edd_get_settings() {
1014 $general_settings = is_array( get_option( 'edd_settings_general' ) ) ? get_option( 'edd_settings_general' ) : array();
1015 $gateway_settings = is_array( get_option( 'edd_settings_gateways' ) ) ? get_option( 'edd_settings_gateways' ) : array();
1016 $email_settings = is_array( get_option( 'edd_settings_emails' ) ) ? get_option( 'edd_settings_emails' ) : array();
1017 $style_settings = is_array( get_option( 'edd_settings_styles' ) ) ? get_option( 'edd_settings_styles' ) : array();
1018 $tax_settings = is_array( get_option( 'edd_settings_taxes' ) ) ? get_option( 'edd_settings_taxes' ) : array();
1019 $misc_settings = is_array( get_option( 'edd_settings_misc' ) ) ? get_option( 'edd_settings_misc' ) : array();
1020
1021 return array_merge( $general_settings, $gateway_settings, $email_settings, $style_settings, $tax_settings, $misc_settings );
1022 }