Easy Digital Downloads
  • Package
  • Function
  • Tree

Packages

  • EDD
    • Admin
      • Actions
      • Add-ons
      • Dashboard
      • Discounts
      • Downloads
      • Export
      • Notices
      • Pages
      • Payments
      • Reports
      • Settings
      • System
      • Upgrades
      • Upload
      • Welcome
    • Cart
    • Checkout
    • Classes
      • API
      • Fees
      • HTML
      • Roles
      • Session
    • Emails
    • Functions
      • AJAX
      • Compatibility
      • Errors
      • Formatting
      • Install
      • Login
      • Taxes
      • Templates
    • Gateways
    • Logging
    • Payments
    • Shortcodes
    • Widgets

Functions

  • edd_checkbox_callback
  • edd_gateway_select_callback
  • edd_gateways_callback
  • edd_get_settings
  • edd_header_callback
  • edd_hook_callback
  • edd_license_key_callback
  • edd_missing_callback
  • edd_multicheck_callback
  • edd_options_page
  • edd_password_callback
  • edd_radio_callback
  • edd_register_settings
  • edd_rich_editor_callback
  • edd_select_callback
  • edd_settings_contextual_help
  • edd_settings_sanitize
  • edd_settings_taxes_description_callback
  • edd_text_callback
  • edd_textarea_callback
  • edd_upload_callback
   1 <?php
   2 /**
   3  * Register Settings
   4  *
   5  * @package     EDD
   6  * @subpackage  Admin/Settings
   7  * @copyright   Copyright (c) 2013, Pippin Williamson
   8  * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
   9  * @since       1.0
  10 */
  11 
  12 // Exit if accessed directly
  13 if ( !defined( 'ABSPATH' ) ) exit;
  14 
  15 /**
  16  * Registers all off the required EDD settings and provides hooks for extensions
  17  * to add their own settings to either the General, Gateways, Emails, Styles
  18  * or Misc Settings Pages
  19  *
  20  * @since 1.0
  21  * @return void
  22 */
  23 function edd_register_settings() {
  24     // Setup some default option sets
  25     $pages = get_pages();
  26     $pages_options = array( 0 => '' ); // Blank option
  27     if ( $pages ) {
  28         foreach ( $pages as $page ) {
  29             $pages_options[ $page->ID ] = $page->post_title;
  30         }
  31     }
  32 
  33     /**
  34      * 'Whitelisted' EDD settings, filters are provided for each settings
  35      * section to allow extensions and other plugins to add their own settings
  36      */
  37     $edd_settings = array(
  38         /** General Settings */
  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         /** Payment Gateways Settings */
 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         /** Emails Settings */
 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         /** Styles Settings */
 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         /** Taxes Settings */
 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         /** Misc Settings */
 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     // Creates our settings in the options table
 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  * Settings Taxes Description Callback
 637  *
 638  * Renders the taxes section description.
 639  *
 640  * @since 1.3.3
 641  * @return void
 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  * Header Callback
 649  *
 650  * Renders the header.
 651  *
 652  * @since 1.0
 653  * @param array $args Arguments passed by the setting
 654  * @return void
 655  */
 656 function edd_header_callback( $args ) {
 657     echo '';
 658 }
 659 
 660 /**
 661  * Checkbox Callback
 662  *
 663  * Renders checkboxes.
 664  *
 665  * @since 1.0
 666  * @param array $args Arguments passed by the setting
 667  * @global $edd_options Array of all the EDD Options
 668  * @return void
 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  * Multicheck Callback
 682  *
 683  * Renders multiple checkboxes.
 684  *
 685  * @since 1.0
 686  * @param array $args Arguments passed by the setting
 687  * @global $edd_options Array of all the EDD Options
 688  * @return void
 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) . '/>&nbsp;';
 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  * Radio Callback
 703  *
 704  * Renders radio boxes.
 705  *
 706  * @since 1.3.3
 707  * @param array $args Arguments passed by the setting
 708  * @global $edd_options Array of all the EDD Options
 709  * @return void
 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) . '/>&nbsp;';
 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  * Gateways Callback
 729  *
 730  * Renders gateways fields.
 731  *
 732  * @since 1.0
 733  * @param array $args Arguments passed by the setting
 734  * @global $edd_options Array of all the EDD Options
 735  * @return void
 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) . '/>&nbsp;';
 747         echo '<label for="edd_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']">' . $option['admin_label'] . '</label><br/>';
 748     endforeach;
 749 }
 750 
 751 /**
 752  * Gateways Callback (drop down)
 753  *
 754  * Renders gateways select menu
 755  *
 756  * @since 1.5
 757  * @param array $args Arguments passed by the setting
 758  * @global $edd_options Array of all the EDD Options
 759  * @return void
 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  * Text Callback
 777  *
 778  * Renders text fields.
 779  *
 780  * @since 1.0
 781  * @param array $args Arguments passed by the setting
 782  * @global $edd_options Array of all the EDD Options
 783  * @return void
 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  * Textarea Callback
 802  *
 803  * Renders textarea fields.
 804  *
 805  * @since 1.0
 806  * @param array $args Arguments passed by the setting
 807  * @global $edd_options Array of all the EDD Options
 808  * @return void
 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  * Password Callback
 827  *
 828  * Renders password fields.
 829  *
 830  * @since 1.3
 831  * @param array $args Arguments passed by the setting
 832  * @global $edd_options Array of all the EDD Options
 833  * @return void
 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  * Missing Callback
 852  *
 853  * If a function is missing for settings callbacks alert the user.
 854  *
 855  * @since 1.3.1
 856  * @param array $args Arguments passed by the setting
 857  * @return void
 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  * Select Callback
 865  *
 866  * Renders select fields.
 867  *
 868  * @since 1.0
 869  * @param array $args Arguments passed by the setting
 870  * @global $edd_options Array of all the EDD Options
 871  * @return void
 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  * Rich Editor Callback
 891  *
 892  * Renders rich editor fields.
 893  *
 894  * @since 1.0
 895  * @param array $args Arguments passed by the setting
 896  * @global $edd_options Array of all the EDD Options
 897  * @global $wp_version WordPress Version
 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  * Upload Callback
 920  *
 921  * Renders upload fields.
 922  *
 923  * @since 1.0
 924  * @param array $args Arguments passed by the setting
 925  * @global $edd_options Array of all the EDD Options
 926  * @return void
 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>&nbsp;<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  * Registers the license field callback for Software Licensing
 947  *
 948  * @since 1.5
 949  * @param array $args Arguments passed by the setting
 950  * @global $edd_options Array of all the EDD Options
 951  * @return void
 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  * Hook Callback
 979  *
 980  * Adds a do_action() hook in place of the field
 981  *
 982  * @since 1.0.8.2
 983  * @param array $args Arguments passed by the setting
 984  * @return void
 985  */
 986 function edd_hook_callback( $args ) {
 987     do_action( 'edd_' . $args['id'] );
 988 }
 989 
 990 /**
 991  * Settings Sanitization
 992  *
 993  * Adds a settings error (for the updated message)
 994  * At some point this will validate input
 995  *
 996  * @since 1.0.8.2
 997  * @param array $input The value inputted in the field
 998  * @return string $input Sanitizied value
 999  */
1000 function edd_settings_sanitize( $input ) {
1001     add_settings_error( 'edd-notices', '', __('Settings Updated', 'edd'), 'updated' );
1002     return $input;
1003 }
1004 
1005 /**
1006  * Get Settings
1007  *
1008  * Retrieves all plugin settings and returns them as a combined array.
1009  *
1010  * @since 1.0
1011  * @return array Merged array of all the EDD settings
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 }
Easy Digital Downloads API documentation generated by ApiGen 2.8.0