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_deprecated_function
  • edd_admin_downloads_icon
  • edd_allowed_mime_types
  • edd_block_attachments
  • edd_cart_discounts_html
  • edd_cart_has_discounts
  • edd_change_default_title
  • edd_cleanup_file_symlinks
  • edd_count_file_downloads_of_user
  • edd_count_purchases_of_customer
  • edd_decrease_earnings
  • edd_decrease_purchase_count
  • edd_deliver_download
  • edd_discount_exists
  • edd_discount_is_min_met
  • edd_discount_is_single_use
  • edd_discount_product_reqs_met
  • edd_display_cart_discount
  • edd_format_discount_rate
  • edd_get_actions
  • edd_get_average_monthly_download_earnings
  • edd_get_average_monthly_download_sales
  • edd_get_bundled_products
  • edd_get_cart_discounted_amount
  • edd_get_cart_discounts
  • edd_get_cart_discounts_html
  • edd_get_country_list
  • edd_get_currencies
  • edd_get_current_page_url
  • edd_get_default_labels
  • edd_get_discount
  • edd_get_discount_amount
  • edd_get_discount_by_code
  • edd_get_discount_code
  • edd_get_discount_expiration
  • edd_get_discount_id_by_code
  • edd_get_discount_max_uses
  • edd_get_discount_min_price
  • edd_get_discount_product_condition
  • edd_get_discount_product_reqs
  • edd_get_discount_start_date
  • edd_get_discount_type
  • edd_get_discount_uses
  • edd_get_discounted_amount
  • edd_get_discounts
  • edd_get_download
  • edd_get_download_earnings_stats
  • edd_get_download_file_url
  • edd_get_download_files
  • edd_get_download_final_price
  • edd_get_download_price
  • edd_get_download_sales_stats
  • edd_get_download_type
  • edd_get_file_ctype
  • edd_get_file_download_limit
  • edd_get_file_download_limit_override
  • edd_get_file_extension
  • edd_get_file_price_condition
  • edd_get_highest_price_option
  • edd_get_ip
  • edd_get_label_plural
  • edd_get_label_singular
  • edd_get_lowest_price_option
  • edd_get_php_arg_separator_output
  • edd_get_price_option_name
  • edd_get_product_notes
  • edd_get_provinces_list
  • edd_get_purchase_cc_info
  • edd_get_purchase_form_user
  • edd_get_states_list
  • edd_get_success_page_url
  • edd_get_symlink_dir
  • edd_get_symlink_url
  • edd_get_users_purchases
  • edd_get_variable_prices
  • edd_has_active_discounts
  • edd_has_purchases
  • edd_has_user_purchased
  • edd_has_variable_prices
  • edd_increase_discount_usage
  • edd_increase_earnings
  • edd_increase_purchase_count
  • edd_is_cc_verify_enabled
  • edd_is_discount_active
  • edd_is_discount_expired
  • edd_is_discount_maxed_out
  • edd_is_discount_not_global
  • edd_is_discount_started
  • edd_is_discount_used
  • edd_is_discount_valid
  • edd_is_file_at_download_limit
  • edd_is_func_disabled
  • edd_is_odd
  • edd_is_test_mode
  • edd_let_to_num
  • edd_load_admin_scripts
  • edd_load_scripts
  • edd_logged_in_only
  • edd_month_num_to_name
  • edd_no_guest_checkout
  • edd_no_redownload
  • edd_post_actions
  • edd_presstrends
  • edd_price
  • edd_price_range
  • edd_process_download
  • edd_process_purchase_form
  • edd_purchase_form_required_fields
  • edd_purchase_form_validate_agree_to_terms
  • edd_purchase_form_validate_cc
  • edd_purchase_form_validate_cc_zip
  • edd_purchase_form_validate_discounts
  • edd_purchase_form_validate_fields
  • edd_purchase_form_validate_gateway
  • edd_purchase_form_validate_guest_user
  • edd_purchase_form_validate_logged_in_user
  • edd_purchase_form_validate_new_user
  • edd_purchase_form_validate_user_login
  • edd_purchase_total_of_user
  • edd_query_vars
  • edd_readfile_chunked
  • edd_record_download_in_log
  • edd_record_sale_in_log
  • edd_register_and_login_new_user
  • edd_register_post_type_statuses
  • edd_register_styles
  • edd_remove_cart_discount
  • edd_remove_discount
  • edd_remove_download_logs_on_delete
  • edd_send_back_to_checkout
  • edd_send_to_success_page
  • edd_set_cart_discount
  • edd_set_file_download_limit_override
  • edd_setup_download_taxonomies
  • edd_setup_edd_post_types
  • edd_single_price_option_mode
  • edd_store_discount
  • edd_straight_to_checkout
  • edd_string_is_image_url
  • edd_unset_all_cart_discounts
  • edd_unset_cart_discount
  • edd_update_discount_status
  • edd_updated_messages
  • edd_validate_username
  • edd_verify_download_link
  • edd_version_in_header
  1 <?php
  2 /**
  3  * Misc Functions
  4  *
  5  * @package     EDD
  6  * @subpackage  Functions
  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  * Is Test Mode
 17  *
 18  * @since 1.0
 19  * @global $edd_options
 20  * @return bool $ret True if return mode is enabled, false otherwise
 21  */
 22 function edd_is_test_mode() {
 23     global $edd_options;
 24 
 25     if ( ! isset( $edd_options['test_mode'] ) || is_null( $edd_options['test_mode'] ) )
 26         $ret = false;
 27     else
 28         $ret = true;
 29 
 30     return (bool) apply_filters( 'edd_is_test_mode', $ret );
 31 }
 32 
 33 /**
 34  * Checks if Guest checkout is enabled
 35  *
 36  * @since 1.0
 37  * @global $edd_options
 38  * @return bool $ret True if guest checkout is enabled, false otherwise
 39  */
 40 function edd_no_guest_checkout() {
 41     global $edd_options;
 42 
 43     if ( isset( $edd_options['logged_in_only'] ) )
 44         $ret = true;
 45     else
 46         $ret = false;
 47 
 48     return (bool) apply_filters( 'edd_no_guest_checkout', $ret );
 49 }
 50 
 51 /**
 52  * Checks if users can only purchase downloads when logged in
 53  *
 54  * @since 1.0
 55  * @global $edd_options
 56  * @return bool $ret Wheter or not the logged_in_only setting is set
 57  */
 58 function edd_logged_in_only() {
 59     global $edd_options;
 60 
 61     if ( isset( $edd_options['logged_in_only'] ) )
 62         $ret = true;
 63     else
 64         $ret = false;
 65 
 66     return (bool) apply_filters( 'edd_logged_in_only', $ret );
 67 }
 68 
 69 /**
 70  * Redirect to checkout immediately after adding items to the cart?
 71  *
 72  * @since 1.4.2
 73  * @return bool $ret True is redirect is enabled, false otherwise
 74  */
 75 function edd_straight_to_checkout() {
 76     global $edd_options;
 77     $ret = isset( $edd_options['redirect_on_add'] );
 78     return (bool) apply_filters( 'edd_straight_to_checkout', $ret );
 79 }
 80 
 81 /**
 82  * Disable Redownload
 83  *
 84  * @access public
 85  * @since 1.0.8.2
 86  * @global $edd_options
 87  * @return bool True if redownloading of files is disabled, false otherwise
 88  */
 89 function edd_no_redownload() {
 90     global $edd_options;
 91 
 92     if ( isset( $edd_options['disable_redownload'] ) )
 93         return true;
 94 
 95     return (bool) apply_filters( 'edd_no_redownload', false );
 96 }
 97 
 98 /**
 99  * Verify credit card numbers live?
100  *
101  * @since 1.4
102  * @global $edd_options
103  * @return bool $ret True is verify credit cards is live
104  */
105 function edd_is_cc_verify_enabled() {
106     global $edd_options;
107 
108     $ret = true;
109 
110     /*
111      * Enable if use a single gateway other than PayPal or Manual. We have to assume it accepts cerdit cards
112      * Enable if using more than one gateway if they aren't both PayPal and manual, again assuming credit card usage
113      */
114 
115     $gateways = edd_get_enabled_payment_gateways();
116 
117     if ( count( $gateways ) == 1 && ! isset( $gateways['paypal'] ) && ! isset( $gateways['manual'] ) )
118         $ret = true;
119     else if ( count( $gateways ) == 1 )
120         $ret = false;
121     else if ( count( $gateways ) == 2 && isset( $gateways['paypal'] ) && isset( $gateways['manual'] ) )
122         $ret = false;
123 
124     if ( isset( $edd_options['edd_is_cc_verify_enabled'] ) )
125         $ret = false; // Global override
126 
127     return (bool) apply_filters( 'edd_verify_credit_cards', $ret );
128 }
129 
130 /**
131  * Is Odd
132  *
133  * Checks wether an integer is odd.
134  *
135  * @since 1.0
136  * @param int $int The integer to check
137  * @return bool Is the integer odd?
138  */
139 function edd_is_odd( $int ) {
140     return (bool) ( $int & 1 );
141 }
142 
143 /**
144  * Get File Extension
145  *
146  * Returns the file extension of a filename.
147  *
148  * @since 1.0
149  * @param string $string Filename
150  * @return string $parts File extension
151  */
152 function edd_get_file_extension( $str ) {
153    $parts = explode( '.', $str );
154    return end( $parts );
155 }
156 
157 /**
158  * Checks if the string (filename) provided is an image URL
159  *
160  * @since 1.0
161  * @param string $str Filename
162  * @return bool Whether or not the filename is an image
163  */
164 function edd_string_is_image_url( $str ) {
165     $ext = edd_get_file_extension( $str );
166 
167     switch( strtolower( $ext ) ) {
168         case 'jpg';
169             $return = true;
170             break;
171         case 'png';
172             $return = true;
173             break;
174         case 'gif';
175             $return = true;
176             break;
177         default:
178             $return = false;
179         break;
180     }
181 
182     return (bool) apply_filters( 'edd_string_is_image', $return, $str );
183 }
184 
185 /**
186  * Get User IP
187  *
188  * Returns the IP address of the current visitor
189  *
190  * @since 1.0.8.2
191  * @return string $ip User's IP address
192 */
193 function edd_get_ip() {
194     if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
195         //check ip from share internet
196       $ip = $_SERVER['HTTP_CLIENT_IP'];
197     } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
198         //to check ip is pass from proxy
199       $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
200     } else {
201       $ip = $_SERVER['REMOTE_ADDR'];
202     }
203     return apply_filters( 'edd_get_ip', $ip );
204 }
205 
206 /**
207  * Get Currencies
208  *
209  * @since 1.0
210  * @return array $currencies A list of the available currencies
211  */
212 function edd_get_currencies() {
213     $currencies = array(
214         'USD' => __('US Dollars (&#36;)', 'edd'),
215         'EUR' => __('Euros (&euro;)', 'edd'),
216         'GBP' => __('Pounds Sterling (&pound;)', 'edd'),
217         'AUD' => __('Australian Dollars (&#36;)', 'edd'),
218         'BRL' => __('Brazilian Real (R&#36;)', 'edd'),
219         'CAD' => __('Canadian Dollars (&#36;)', 'edd'),
220         'CZK' => __('Czech Koruna', 'edd'),
221         'DKK' => __('Danish Krone', 'edd'),
222         'HKD' => __('Hong Kong Dollar (&#36;)', 'edd'),
223         'HUF' => __('Hungarian Forint', 'edd'),
224         'ILS' => __('Israeli Shekel', 'edd'),
225         'JPY' => __('Japanese Yen (&yen;)', 'edd'),
226         'MYR' => __('Malaysian Ringgits', 'edd'),
227         'MXN' => __('Mexican Peso (&#36;)', 'edd'),
228         'NZD' => __('New Zealand Dollar (&#36;)', 'edd'),
229         'NOK' => __('Norwegian Krone', 'edd'),
230         'PHP' => __('Philippine Pesos', 'edd'),
231         'PLN' => __('Polish Zloty', 'edd'),
232         'SGD' => __('Singapore Dollar (&#36;)', 'edd'),
233         'SEK' => __('Swedish Krona', 'edd'),
234         'CHF' => __('Swiss Franc', 'edd'),
235         'TWD' => __('Taiwan New Dollars', 'edd'),
236         'THB' => __('Thai Baht', 'edd'),
237         'INR' => __('Indian Rupee', 'edd'),
238         'TRY' => __('Turkish Lira', 'edd'),
239         'RIAL' => __('Iranian Rial', 'edd')
240     );
241 
242     return apply_filters( 'edd_currencies', $currencies );
243 }
244 
245 /**
246  * Get Country List
247  *
248  * @since 1.0
249  * @return array $countries A list of the available countries
250  */
251 function edd_get_country_list() {
252     $countries = array(
253         'US' => 'United States',
254         'CA' => 'Canada',
255         'GB' => 'United Kingdom',
256         'AD' => 'Andorra',
257         'AE' => 'United Arab Emirates',
258         'AF' => 'Afghanistan',
259         'AG' => 'Antigua and Barbuda',
260         'AI' => 'Anguilla',
261         'AL' => 'Albania',
262         'AM' => 'Armenia',
263         'AN' => 'Netherlands Antilles',
264         'AO' => 'Angola',
265         'AQ' => 'Antarctica',
266         'AR' => 'Argentina',
267         'AS' => 'American Samoa',
268         'AT' => 'Austria',
269         'AU' => 'Australia',
270         'AW' => 'Aruba',
271         'AZ' => 'Azerbaijan',
272         'BA' => 'Bosnia and Herzegovina',
273         'BB' => 'Barbados',
274         'BD' => 'Bangladesh',
275         'BE' => 'Belgium',
276         'BF' => 'Burkina Faso',
277         'BG' => 'Bulgaria',
278         'BH' => 'Bahrain',
279         'BI' => 'Burundi',
280         'BJ' => 'Benin',
281         'BM' => 'Bermuda',
282         'BN' => 'Brunei Darrussalam',
283         'BO' => 'Bolivia',
284         'BR' => 'Brazil',
285         'BS' => 'Bahamas',
286         'BT' => 'Bhutan',
287         'BV' => 'Bouvet Island',
288         'BW' => 'Botswana',
289         'BY' => 'Belarus',
290         'BZ' => 'Belize',
291         'CC' => 'Cocos Islands',
292         'CD' => 'Congo, Democratic People\'s Republic',
293         'CF' => 'Central African Republic',
294         'CG' => 'Congo, Republic of',
295         'CH' => 'Switzerland',
296         'CI' => 'Cote d\'Ivoire',
297         'CK' => 'Cook Islands',
298         'CL' => 'Chile',
299         'CM' => 'Cameroon',
300         'CN' => 'China',
301         'CO' => 'Colombia',
302         'CR' => 'Costa Rica',
303         'CU' => 'Cuba',
304         'CV' => 'Cap Verde',
305         'CX' => 'Christmas Island',
306         'CY' => 'Cyprus Island',
307         'CZ' => 'Czech Republic',
308         'DE' => 'Germany',
309         'DJ' => 'Djibouti',
310         'DK' => 'Denmark',
311         'DM' => 'Dominica',
312         'DO' => 'Dominican Republic',
313         'DZ' => 'Algeria',
314         'EC' => 'Ecuador',
315         'EE' => 'Estonia',
316         'EG' => 'Egypt',
317         'EH' => 'Western Sahara',
318         'ER' => 'Eritrea',
319         'ES' => 'Spain',
320         'ET' => 'Ethiopia',
321         'FI' => 'Finland',
322         'FJ' => 'Fiji',
323         'FK' => 'Falkland Islands',
324         'FM' => 'Micronesia',
325         'FO' => 'Faroe Islands',
326         'FR' => 'France',
327         'GA' => 'Gabon',
328         'GD' => 'Grenada',
329         'GE' => 'Georgia',
330         'GF' => 'French Guiana',
331         'GG' => 'Guernsey',
332         'GH' => 'Ghana',
333         'GI' => 'Gibraltar',
334         'GL' => 'Greenland',
335         'GM' => 'Gambia',
336         'GN' => 'Guinea',
337         'GP' => 'Guadeloupe',
338         'GQ' => 'Equatorial Guinea',
339         'GR' => 'Greece',
340         'GS' => 'South Georgia',
341         'GT' => 'Guatemala',
342         'GU' => 'Guam',
343         'GW' => 'Guinea-Bissau',
344         'GY' => 'Guyana',
345         'HK' => 'Hong Kong',
346         'HM' => 'Heard and McDonald Islands',
347         'HN' => 'Honduras',
348         'HR' => 'Croatia/Hrvatska',
349         'HT' => 'Haiti',
350         'HU' => 'Hungary',
351         'ID' => 'Indonesia',
352         'IE' => 'Ireland',
353         'IL' => 'Israel',
354         'IM' => 'Isle of Man',
355         'IN' => 'India',
356         'IO' => 'British Indian Ocean Territory',
357         'IQ' => 'Iraq',
358         'IR' => 'Iran',
359         'IS' => 'Iceland',
360         'IT' => 'Italy',
361         'JE' => 'Jersey',
362         'JM' => 'Jamaica',
363         'JO' => 'Jordan',
364         'JP' => 'Japan',
365         'KE' => 'Kenya',
366         'KG' => 'Kyrgyzstan',
367         'KH' => 'Cambodia',
368         'KI' => 'Kiribati',
369         'KM' => 'Comoros',
370         'KN' => 'Saint Kitts and Nevis',
371         'KP' => 'South Korea',
372         'KR' => 'North Korea',
373         'KW' => 'Kuwait',
374         'KY' => 'Cayman Islands',
375         'KZ' => 'Kazakhstan',
376         'LA' => 'Lao People\'s Democratic Republic',
377         'LB' => 'Lebanon',
378         'LC' => 'Saint Lucia',
379         'LI' => 'Liechtenstein',
380         'LK' => 'Sri Lanka',
381         'LR' => 'Liberia',
382         'LS' => 'Lesotho',
383         'LT' => 'Lithuania',
384         'LU' => 'Luxembourgh',
385         'LV' => 'Latvia',
386         'LY' => 'Libyan Arab Jamahiriya',
387         'MA' => 'Morocco',
388         'MC' => 'Monaco',
389         'ME' => 'Montenegro',
390         'MD' => 'Moldova, Republic of',
391         'MG' => 'Madagascar',
392         'MH' => 'Marshall Islands',
393         'MK' => 'Macedonia',
394         'ML' => 'Mali',
395         'MM' => 'Myanmar',
396         'MN' => 'Mongolia',
397         'MO' => 'Macau',
398         'MP' => 'Northern Mariana Islands',
399         'MQ' => 'Martinique',
400         'MR' => 'Mauritania',
401         'MS' => 'Montserrat',
402         'MT' => 'Malta',
403         'MU' => 'Mauritius',
404         'Mv' => 'Maldives',
405         'MW' => 'malawi',
406         'MX' => 'Mexico',
407         'MY' => 'Malaysia',
408         'MZ' => 'Mozambique',
409         'NA' => 'Namibia',
410         'NC' => 'New Caledonia',
411         'NE' => 'Niger',
412         'NF' => 'Norfolk Island',
413         'NG' => 'Nigeria',
414         'NI' => 'Nicaragua',
415         'NL' => 'Netherlands',
416         'NO' => 'Norway',
417         'NP' => 'Nepal',
418         'NR' => 'Nauru',
419         'NU' => 'Niue',
420         'NZ' => 'New Zealand',
421         'OM' => 'Oman',
422         'PA' => 'Panama',
423         'PE' => 'Peru',
424         'PF' => 'French Polynesia',
425         'PG' => 'papua New Guinea',
426         'PH' => 'Phillipines',
427         'PK' => 'Pakistan',
428         'PL' => 'Poland',
429         'PM' => 'St. Pierre and Miquelon',
430         'PN' => 'Pitcairn Island',
431         'PR' => 'Puerto Rico',
432         'PS' => 'Palestinian Territories',
433         'PT' => 'Portugal',
434         'PW' => 'Palau',
435         'PY' => 'Paraguay',
436         'QA' => 'Qatar',
437         'RE' => 'Reunion Island',
438         'RO' => 'Romania',
439         'RS' => 'Serbia',
440         'RU' => 'Russian Federation',
441         'RW' => 'Rwanda',
442         'SA' => 'Saudi Arabia',
443         'SB' => 'Solomon Islands',
444         'SC' => 'Seychelles',
445         'SD' => 'Sudan',
446         'SE' => 'Sweden',
447         'SG' => 'Singapore',
448         'SH' => 'St. Helena',
449         'SI' => 'Slovenia',
450         'SJ' => 'Svalbard and Jan Mayen Islands',
451         'SK' => 'Slovak Republic',
452         'SL' => 'Sierra Leone',
453         'SM' => 'San Marino',
454         'SN' => 'Senegal',
455         'SO' => 'Somalia',
456         'SR' => 'Suriname',
457         'ST' => 'Sao Tome and Principe',
458         'SV' => 'El Salvador',
459         'SY' => 'Syrian Arab Republic',
460         'SZ' => 'Swaziland',
461         'TC' => 'Turks and Caicos Islands',
462         'TD' => 'Chad',
463         'TF' => 'French Southern Territories',
464         'TG' => 'Togo',
465         'TH' => 'Thailand',
466         'TJ' => 'Tajikistan',
467         'TK' => 'Tokelau',
468         'TM' => 'Turkmenistan',
469         'TN' => 'Tunisia',
470         'TO' => 'Tonga',
471         'TP' => 'East Timor',
472         'TR' => 'Turkey',
473         'TT' => 'Trinidad and Tobago',
474         'TV' => 'Tuvalu',
475         'TW' => 'Taiwan',
476         'TZ' => 'Tanzania',
477         'UA' => 'Ukraine',
478         'UG' => 'Uganda',
479         'UM' => 'US Minor Outlying Islands',
480         'UY' => 'Uruguay',
481         'UZ' => 'Uzbekistan',
482         'VA' => 'Holy See (City Vatican State)',
483         'VC' => 'Saint Vincent and the Grenadines',
484         'VE' => 'Venezuela',
485         'VG' => 'Virgin Islands (British)',
486         'VI' => 'Virgin Islands (USA)',
487         'VN' => 'Vietnam',
488         'VU' => 'Vanuatu',
489         'WF' => 'Wallis and Futuna Islands',
490         'WS' => 'Western Samoa',
491         'YE' => 'Yemen',
492         'YT' => 'Mayotte',
493         'YU' => 'Yugoslavia',
494         'ZA' => 'South Africa',
495         'ZM' => 'Zambia',
496         'ZW' => 'Zimbabwe'
497     );
498 
499     return apply_filters( 'edd_countries', $countries );
500 }
501 
502 /**
503  * Get States List
504  *
505  * @access      public
506  * @since       1.2
507  * @return      array
508  */
509 function edd_get_states_list() {
510     $states = array(
511         'AL' => 'Alabama',
512         'AK' => 'Alaska',
513         'AZ' => 'Arizona',
514         'AR' => 'Arkansas',
515         'CA' => 'California',
516         'CO' => 'Colorado',
517         'CT' => 'Connecticut',
518         'DE' => 'Delaware',
519         'DC' => 'District of Columbia',
520         'FL' => 'Florida',
521         'GA' => 'Georgia',
522         'HI' => 'Hawaii',
523         'ID' => 'Idaho',
524         'IL' => 'Illinois',
525         'IN' => 'Indiana',
526         'IA' => 'Iowa',
527         'KS' => 'Kansas',
528         'KY' => 'Kentucky',
529         'LA' => 'Louisiana',
530         'ME' => 'Maine',
531         'MD' => 'Maryland',
532         'MA' => 'Massachusetts',
533         'MI' => 'Michigan',
534         'MN' => 'Minnesota',
535         'MS' => 'Mississippi',
536         'MO' => 'Missouri',
537         'MT' => 'Montana',
538         'NE' => 'Nebraksa',
539         'NV' => 'Nevada',
540         'NH' => 'New Hampshire',
541         'NJ' => 'New Jersey',
542         'NM' => 'New Mexico',
543         'NY' => 'New York',
544         'NC' => 'North Carolina',
545         'ND' => 'North Dakota',
546         'OH' => 'Ohio',
547         'OK' => 'Oklahoma',
548         'OR' => 'Oregon',
549         'PA' => 'Pennsylvania',
550         'RI' => 'Rhode Island',
551         'SC' => 'South Carolina',
552         'SD' => 'South Dakota',
553         'TN' => 'Tennessee',
554         'TX' => 'Texas',
555         'UT' => 'Utah',
556         'VT' => 'Vermont',
557         'VA' => 'Virginia',
558         'WA' => 'Washington',
559         'WV' => 'West Virginia',
560         'WI' => 'Wisconsin',
561         'WY' => 'Wyoming',
562         'AS' => 'American Samoa',
563         'CZ' => 'Canal Zone',
564         'CM' => 'Commonwealth of the Northern Mariana Islands',
565         'FM' => 'Federated States of Micronesia',
566         'GU' => 'Guam',
567         'MH' => 'Marshall Islands',
568         'MP' => 'Northern Mariana Islands',
569         'PW' => 'Palau',
570         'PI' => 'Philippine Islands',
571         'PR' => 'Puerto Rico',
572         'TT' => 'Trust Territory of the Pacific Islands',
573         'VI' => 'Virgin Islands',
574         'AA' => 'Armed Forces - Americas',
575         'AE' => 'Armed Forces - Europe, Canada, Middle East, Africa',
576         'AP' => 'Armed Forces - Pacific'
577     );
578 
579     return apply_filters( 'edd_us_states', $states );
580 }
581 
582 /**
583  * Get Provinces List
584  *
585  * @access      public
586  * @since       1.2
587  * @return      array
588  */
589 function edd_get_provinces_list() {
590     $provinces = array(
591         'AB' => 'Alberta',
592         'BC' => 'British Columbia',
593         'MB' => 'Manitoba',
594         'NB' => 'New Brunswick',
595         'NL' => 'Newfoundland and Labrador',
596         'NS' => 'Nova Scotia',
597         'NT' => 'Northwest Territories',
598         'NU' => 'Nunavut',
599         'ON' => 'Ontario',
600         'PE' => 'Prince Edward Island',
601         'QC' => 'Quebec',
602         'SK' => 'Saskatchewan',
603         'YT' => 'Yukon'
604     );
605 
606     return apply_filters( 'edd_canada_provinces', $provinces );
607 }
608 
609 /**
610  * Month Num To Name
611  *
612  * Takes a month number and returns the name three letter name of it.
613  *
614  * @since 1.0
615  * @return string Short month name
616  */
617 function edd_month_num_to_name( $n ) {
618     $timestamp = mktime( 0, 0, 0, $n, 1, 2005 );
619 
620     return date_i18n( "M", $timestamp );
621 }
622 
623 /**
624  * Get PHP Arg Separator Ouput
625  *
626  * @since 1.0.8.3
627  * @return string Arg separator output
628 */
629 function edd_get_php_arg_separator_output() {
630     return ini_get('arg_separator.output');
631 }
632 
633 /**
634  * Get the current page URL
635  *
636  * @since 1.3
637  * @global $post
638  * @return string $page_url Current page URL
639  */
640 function edd_get_current_page_url() {
641     global $post;
642 
643     if ( is_front_page() ) :
644         $page_url = home_url();
645     else :
646         $page_url = 'http';
647 
648         if ( isset( $_SERVER["HTTPS"] ) && $_SERVER["HTTPS"] == "on" )
649             $page_url .= "s";
650 
651         $page_url .= "://";
652 
653         if ( $_SERVER["SERVER_PORT"] != "80" )
654             $page_url .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
655         else
656             $page_url .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
657     endif;
658 
659     return apply_filters( 'edd_get_current_page_url', esc_url( $page_url ) );
660 }
661 
662 /**
663  * Marks a function as deprecated and informs when it has been used.
664  *
665  * There is a hook edd_deprecated_function_run that will be called that can be used
666  * to get the backtrace up to what file and function called the deprecated
667  * function.
668  *
669  * The current behavior is to trigger a user error if WP_DEBUG is true.
670  *
671  * This function is to be used in every function that is deprecated.
672  *
673  * @uses do_action() Calls 'edd_deprecated_function_run' and passes the function name, what to use instead,
674  *   and the version the function was deprecated in.
675  * @uses apply_filters() Calls 'edd_deprecated_function_trigger_error' and expects boolean value of true to do
676  *   trigger or false to not trigger error.
677  *
678  * @param string $function The function that was called
679  * @param string $version The version of WordPress that deprecated the function
680  * @param string $replacement Optional. The function that should have been called
681  * @param array $backtrace Optional. Contains stack backtrace of deprecated function
682  */
683 function _edd_deprecated_function( $function, $version, $replacement = null, $backtrace = null ) {
684     do_action( 'edd_deprecated_function_run', $function, $replacement, $version );
685 
686     $show_errors = current_user_can( 'manage_options' );
687 
688     // Allow plugin to filter the output error trigger
689     if ( WP_DEBUG && apply_filters( 'edd_deprecated_function_trigger_error', $show_errors ) ) {
690         if ( ! is_null( $replacement ) ) {
691             trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since Easy Digital Downloads version %2$s! Use %3$s instead.', 'edd' ), $function, $version, $replacement ) );
692             trigger_error(  print_r( $backtrace ) ); // Limited to previous 1028 characters, but since we only need to move back 1 in stack that should be fine.
693             // Alernatively we could dump this to a file.
694         }
695         else {
696             trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since Easy Digital Downloads version %2$s with no alternative available.', 'edd'), $function, $version ) );
697             trigger_error( print_r($backtrace) );// Limited to previous 1028 characters, but since we only need to move back 1 in stack that should be fine.
698             // Alernatively we could dump this to a file.
699         }
700     }
701 }
702 
703 /**
704  * PressTrends Plugin API
705  *
706  * @since 1.3.2
707  * @global $edd_options
708  * @return void
709  */
710 function edd_presstrends() {
711     global $edd_options;
712 
713     if ( ! isset( $edd_options['presstrends'] ) )
714         return;
715 
716     // PressTrends Account API Key
717     $api_key = '5s8akq2i874z40j69yceyb54qodzg1ux3wtf';
718     $auth    = 'xz27f52esm948ogb5xah9bpk4x54usai8';
719 
720     // Start of Metrics
721     global $wpdb;
722 
723     $data = get_transient( 'presstrends_cache_data' );
724 
725     if ( ! $data || $data == '' ) {
726         $api_base = 'http://api.presstrends.io/index.php/api/pluginsites/update/auth/';
727         $url      = $api_base . $auth . '/api/' . $api_key . '/';
728 
729         $count_posts    = wp_count_posts();
730         $count_pages    = wp_count_posts( 'page' );
731         $comments_count = wp_count_comments();
732 
733         // Wp_get_theme was introduced in 3.4, for compatibility with older versions, let's do a workaround for now.
734         if ( function_exists( 'wp_get_theme' ) ) {
735             $theme_data = wp_get_theme();
736             $theme_name = urlencode( $theme_data->Name );
737         } else {
738             $theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' );
739             $theme_name = $theme_data['Name'];
740         }
741 
742         $plugin_name = '&';
743         foreach ( get_plugins() as $plugin_info ) {
744             $plugin_name .= $plugin_info['Name'] . '&';
745         }
746         // CHANGE __FILE__ PATH IF LOCATED OUTSIDE MAIN PLUGIN FILE
747         $plugin_data         = get_plugin_data( EDD_PLUGIN_FILE );
748         $posts_with_comments = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type='post' AND comment_count > 0" );
749         $data                = array(
750             'url'             => stripslashes( str_replace( array( 'http://', '/', ':' ), '', site_url() ) ),
751             'posts'           => $count_posts->publish,
752             'pages'           => $count_pages->publish,
753             'comments'        => $comments_count->total_comments,
754             'approved'        => $comments_count->approved,
755             'spam'            => $comments_count->spam,
756             'pingbacks'       => $wpdb->get_var( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_type = 'pingback'" ),
757             'post_conversion' => ( $count_posts->publish > 0 && $posts_with_comments > 0 ) ? number_format( ( $posts_with_comments / $count_posts->publish ) * 100, 0, '.', '' ) : 0,
758             'theme_version'   => $plugin_data['Version'],
759             'theme_name'      => $theme_name,
760             'site_name'       => str_replace( ' ', '', get_bloginfo( 'name' ) ),
761             'plugins'         => count( get_option( 'active_plugins' ) ),
762             'plugin'          => urlencode( $plugin_name ),
763             'wpversion'       => get_bloginfo( 'version' ),
764         );
765 
766         foreach ( $data as $k => $v ) {
767             $url .= $k . '/' . $v . '/';
768         }
769         wp_remote_get( $url );
770         set_transient( 'presstrends_cache_data', $data, 60 * 60 * 24 );
771     }
772 }
773 add_action( 'admin_init', 'edd_presstrends' );
774 
775 /**
776  * Checks whether function is disabled.
777  *
778  * @since 1.3.5
779  *
780  * @param string $function Name of the function.
781  * @return bool Whether or not function is disabled.
782  */
783 function edd_is_func_disabled( $function ) {
784     $disabled = explode( ',',  ini_get( 'disable_functions' ) );
785 
786     return in_array( $function, $disabled );
787 }
788 
789 /**
790  * EDD Let To Num
791  *
792  * Does Size Conversions
793  *
794  * @since 1.4
795  * @usedby edd_settings()
796  * @author Chris Christoff
797  * @return $ret
798  */
799 function edd_let_to_num( $v ) {
800     $l   = substr( $v, -1 );
801     $ret = substr( $v, 0, -1 );
802 
803     switch ( strtoupper( $l ) ) {
804         case 'P':
805             $ret *= 1024;
806         case 'T':
807             $ret *= 1024;
808         case 'G':
809             $ret *= 1024;
810         case 'M':
811             $ret *= 1024;
812         case 'K':
813             $ret *= 1024;
814             break;
815     }
816 
817     return $ret;
818 }
819 
820 /**
821  * Retrieve the URL of the symlink directory
822  *
823  * @since 1.5
824  * @return string $url URL of the symlink directory
825  */
826 function edd_get_symlink_url() {
827     $wp_upload_dir = wp_upload_dir();
828     wp_mkdir_p( $wp_upload_dir['basedir'] . '/edd/symlinks' );
829     $url = $wp_upload_dir['baseurl'] . '/edd/symlinks';
830 
831     return apply_filters( 'edd_get_symlink_url', $url );
832 }
833 
834 /**
835  * Retrieve the absolute path to the symlink directory
836  *
837  * @since  1.5
838  * @return string $path Absolute path to the symlink directory
839  */
840 function edd_get_symlink_dir() {
841     $wp_upload_dir = wp_upload_dir();
842     wp_mkdir_p( $wp_upload_dir['basedir'] . '/edd/symlinks' );
843     $path = $wp_upload_dir['basedir'] . '/edd/symlinks';
844 
845     return apply_filters( 'edd_get_symlink_dir', $path );
846 }
847 
848 /**
849  * Delete symbolic links afer they have been used
850  *
851  * @access public
852  * @since  1.5
853  * @return void
854  */
855 function edd_cleanup_file_symlinks() {
856     $path = edd_get_symlink_dir();
857     $dir = opendir( $path );
858 
859     while ( ( $file = readdir( $dir ) ) !== false ) {
860         if ( $file == '.' || $file == '..' )
861             continue;
862 
863         $transient = get_transient( md5( $file ) );
864         if ( $transient === false )
865             @unlink( $path . '/' . $file );
866     }
867 }
868 add_action( 'edd_cleanup_file_symlinks', 'edd_cleanup_file_symlinks' );
Easy Digital Downloads API documentation generated by ApiGen 2.8.0