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  * Post Type 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  * Registers and sets up the Downloads custom post type
 17  *
 18  * @since 1.0
 19  * @return void
 20  */
 21 function edd_setup_edd_post_types() {
 22     $archives = true;
 23     if ( defined( 'EDD_DISABLE_ARCHIVE' ) && EDD_DISABLE_ARCHIVE == true ) {
 24         $archives = false;
 25     }
 26 
 27     $slug = 'downloads';
 28     if ( defined( 'EDD_SLUG' ) ) {
 29         $slug = EDD_SLUG;
 30     }
 31 
 32     $rewrite = array('slug' => $slug, 'with_front' => false);
 33     if ( defined( 'EDD_DISABLE_REWRITE' ) && EDD_DISABLE_REWRITE == true ) {
 34         $rewrite = false;
 35     }
 36 
 37     $download_labels =  apply_filters( 'edd_download_labels', array(
 38         'name'              => '%2$s',
 39         'singular_name'     => '%1$s',
 40         'add_new'           => __( 'Add New', 'edd' ),
 41         'add_new_item'      => __( 'Add New %1$s', 'edd' ),
 42         'edit_item'         => __( 'Edit %1$s', 'edd' ),
 43         'new_item'          => __( 'New %1$s', 'edd' ),
 44         'all_items'         => __( 'All %2$s', 'edd' ),
 45         'view_item'         => __( 'View %1$s', 'edd' ),
 46         'search_items'      => __( 'Search %2$s', 'edd' ),
 47         'not_found'         => __( 'No %2$s found', 'edd' ),
 48         'not_found_in_trash'=> __( 'No %2$s found in Trash', 'edd' ),
 49         'parent_item_colon' => '',
 50         'menu_name'         => __( '%2$s', 'edd' )
 51     ) );
 52 
 53     foreach ( $download_labels as $key => $value ) {
 54        $download_labels[ $key ] = sprintf( $value, edd_get_label_singular(), edd_get_label_plural() );
 55     }
 56 
 57     $download_args = array(
 58         'labels'            => $download_labels,
 59         'public'            => true,
 60         'publicly_queryable'=> true,
 61         'show_ui'           => true,
 62         'show_in_menu'      => true,
 63         'query_var'         => true,
 64         'rewrite'           => $rewrite,
 65         'capability_type'   => 'product',
 66         'map_meta_cap'      => true,
 67         'has_archive'       => $archives,
 68         'hierarchical'      => false,
 69         'supports'          => apply_filters( 'edd_download_supports', array( 'title', 'editor', 'thumbnail', 'excerpt' ) ),
 70     );
 71     register_post_type( 'download', apply_filters( 'edd_download_post_type_args', $download_args ) );
 72 
 73 
 74     /** Payment Post Type */
 75     $payment_labels = array(
 76         'name'              => _x('Payments', 'post type general name', 'edd' ),
 77         'singular_name'     => _x('Payment', 'post type singular name', 'edd' ),
 78         'add_new'           => __( 'Add New', 'edd' ),
 79         'add_new_item'      => __( 'Add New Payment', 'edd' ),
 80         'edit_item'         => __( 'Edit Payment', 'edd' ),
 81         'new_item'          => __( 'New Payment', 'edd' ),
 82         'all_items'         => __( 'All Payments', 'edd' ),
 83         'view_item'         => __( 'View Payment', 'edd' ),
 84         'search_items'      => __( 'Search Payments', 'edd' ),
 85         'not_found'         =>  __( 'No Payments found', 'edd' ),
 86         'not_found_in_trash'=> __( 'No Payments found in Trash', 'edd' ),
 87         'parent_item_colon' => '',
 88         'menu_name'         => __( 'Payment History', 'edd' )
 89     );
 90 
 91     $payment_args = array(
 92         'labels'            => apply_filters( 'edd_payment_labels', $payment_labels ),
 93         'public'            => false,
 94         'query_var'         => false,
 95         'rewrite'           => false,
 96         'capability_type'   => 'shop_payment',
 97         'map_meta_cap'      => true,
 98         'supports'          => array( 'title' ),
 99         'can_export'        => true
100     );
101     register_post_type( 'edd_payment', $payment_args );
102 
103 
104     /** Discounts Post Type */
105     $discount_labels = array(
106         'name'              => _x( 'Discounts', 'post type general name', 'edd' ),
107         'singular_name'     => _x( 'Discount', 'post type singular name', 'edd' ),
108         'add_new'           => __( 'Add New', 'edd' ),
109         'add_new_item'      => __( 'Add New Discount', 'edd' ),
110         'edit_item'         => __( 'Edit Discount', 'edd' ),
111         'new_item'          => __( 'New Discount', 'edd' ),
112         'all_items'         => __( 'All Discounts', 'edd' ),
113         'view_item'         => __( 'View Discount', 'edd' ),
114         'search_items'      => __( 'Search Discounts', 'edd' ),
115         'not_found'         => __( 'No Discounts found', 'edd' ),
116         'not_found_in_trash'=> __( 'No Discounts found in Trash', 'edd' ),
117         'parent_item_colon' => '',
118         'menu_name'         => __( 'Discounts', 'edd' )
119     );
120 
121     $discount_args = array(
122         'labels'            => apply_filters( 'edd_discount_labels', $discount_labels ),
123         'public'            => false,
124         'query_var'         => false,
125         'rewrite'           => false,
126         'show_ui'           => false,
127         'capability_type'   => 'shop_discount',
128         'map_meta_cap'      => true,
129         'supports'          => array( 'title' ),
130         'can_export'        => true
131     );
132     register_post_type( 'edd_discount', $discount_args );
133 }
134 add_action( 'init', 'edd_setup_edd_post_types', 100 );
135 
136 /**
137  * Get Default Labels
138  *
139  * @since 1.0.8.3
140  * @return array $defaults Default labels
141  */
142 function edd_get_default_labels() {
143     $defaults = array(
144        'singular' => __( 'Download', 'edd' ),
145        'plural' => __( 'Downloads', 'edd')
146     );
147     return apply_filters( 'edd_default_downloads_name', $defaults );
148 }
149 
150 /**
151  * Get Singular Label
152  *
153  * @since 1.0.8.3
154  * @return string $defaults['singular'] Singular label
155  */ 
156 function edd_get_label_singular( $lowercase = false ) {
157     $defaults = edd_get_default_labels();
158     return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular'];
159 }
160 
161 /**
162  * Get Plural Label
163  *
164  * @since 1.0.8.3
165  * @return string $defaults['plural'] Plural label
166  */
167 function edd_get_label_plural( $lowercase = false ) {
168     $defaults = edd_get_default_labels();
169     return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural'];
170 }
171 
172 /**
173  * Change default "Enter title here" input
174  *
175  * @since 1.4.0.2
176  * @param string $title Default title placeholder text
177  * @return string $title New placeholder text
178  */
179 function edd_change_default_title( $title ) {
180      $screen = get_current_screen();
181 
182      if  ( 'download' == $screen->post_type ) {
183         $label = edd_get_label_singular();
184         $title = sprintf( __( 'Enter %s title here', 'edd' ), $label );
185      }
186 
187      return $title;
188 }
189 add_filter( 'enter_title_here', 'edd_change_default_title' );
190 
191 /**
192  * Registers the custom taxonomies for the downloads custom post type
193  *
194  * @since 1.0
195  * @return void
196 */
197 function edd_setup_download_taxonomies() {
198     $slug = 'downloads';
199 
200     if ( defined( 'EDD_SLUG' ) ) {
201         $slug = EDD_SLUG;
202     }
203 
204     /** Categories */
205     $category_labels = array(
206         'name'              => _x( 'Categories', 'taxonomy general name', 'edd' ),
207         'singular_name'     => _x( 'Category', 'taxonomy singular name', 'edd' ),
208         'search_items'      => __( 'Search Categories', 'edd'  ),
209         'all_items'         => __( 'All Categories', 'edd'  ),
210         'parent_item'       => __( 'Parent Category', 'edd'  ),
211         'parent_item_colon' => __( 'Parent Category:', 'edd'  ),
212         'edit_item'         => __( 'Edit Category', 'edd'  ),
213         'update_item'       => __( 'Update Category', 'edd'  ),
214         'add_new_item'      => __( 'Add New Category', 'edd'  ),
215         'new_item_name'     => __( 'New Category Name', 'edd'  ),
216         'menu_name'         => __( 'Categories', 'edd'  ),
217     );
218 
219     $category_args = apply_filters( 'edd_download_category_args', array(
220             'hierarchical'  => true,
221             'labels'        => apply_filters('edd_download_category_labels', $category_labels),
222             'show_ui'       => true,
223             'query_var'     => 'download_category',
224             'rewrite'       => array('slug' => $slug . '/category', 'with_front' => false, 'hierarchical' => true ),
225             'capabilities'  => array( 'manage_terms' => 'manage_product_terms','edit_terms' => 'edit_product_terms','assign_terms' => 'assign_product_terms','delete_terms' => 'delete_product_terms' )
226         )
227     );
228     register_taxonomy( 'download_category', array('download'), $category_args );
229 
230     /** Tags */
231     $tag_labels = array(
232         'name'              => _x( 'Tags', 'taxonomy general name', 'edd' ),
233         'singular_name'     => _x( 'Tag', 'taxonomy singular name', 'edd' ),
234         'search_items'      => __( 'Search Tags', 'edd'  ),
235         'all_items'         => __( 'All Tags', 'edd'  ),
236         'parent_item'       => __( 'Parent Tag', 'edd'  ),
237         'parent_item_colon' => __( 'Parent Tag:', 'edd'  ),
238         'edit_item'         => __( 'Edit Tag', 'edd'  ),
239         'update_item'       => __( 'Update Tag', 'edd'  ),
240         'add_new_item'      => __( 'Add New Tag', 'edd'  ),
241         'new_item_name'     => __( 'New Tag Name', 'edd'  ),
242         'menu_name'         => __( 'Tags', 'edd'  ),
243     );
244 
245     $tag_args = apply_filters( 'edd_download_tag_args', array(
246             'hierarchical'  => false,
247             'labels'        => apply_filters( 'edd_download_tag_labels', $tag_labels ),
248             'show_ui'       => true,
249             'query_var'     => 'download_tag',
250             'rewrite'       => array( 'slug' => $slug . '/tag', 'with_front' => false, 'hierarchical' => true  ),
251             'capabilities'  => array( 'manage_terms' => 'manage_product_terms','edit_terms' => 'edit_product_terms','assign_terms' => 'assign_product_terms','delete_terms' => 'delete_product_terms' )
252 
253         )
254     );
255     register_taxonomy( 'download_tag', array( 'download' ), $tag_args );
256 }
257 add_action( 'init', 'edd_setup_download_taxonomies', 10 );
258 
259 /**
260  * Registers Custom Post Statuses which are used by the Payments and Discount
261  * Codes
262  *
263  * @since 1.0.9.1
264  * @return void
265  */
266 function edd_register_post_type_statuses() {
267     // Payment Statuses
268     register_post_status( 'refunded', array(
269         'label'                     => _x( 'Refunded', 'Refunded payment status', 'edd' ),
270         'public'                    => true,
271         'exclude_from_search'       => false,
272         'show_in_admin_all_list'    => true,
273         'show_in_admin_status_list' => true,
274         'label_count'               => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'edd' )
275     ) );
276     register_post_status( 'failed', array(
277         'label'                     => _x( 'Failed', 'Failed payment status', 'edd' ),
278         'public'                    => true,
279         'exclude_from_search'       => false,
280         'show_in_admin_all_list'    => true,
281         'show_in_admin_status_list' => true,
282         'label_count'               => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'edd' )
283     )  );
284     register_post_status( 'revoked', array(
285         'label'                     => _x( 'Revoked', 'Revoked payment status', 'edd' ),
286         'public'                    => true,
287         'exclude_from_search'       => false,
288         'show_in_admin_all_list'    => true,
289         'show_in_admin_status_list' => true,
290         'label_count'               => _n_noop( 'Revoked <span class="count">(%s)</span>', 'Revoked <span class="count">(%s)</span>', 'edd' )
291     )  );
292 
293     // Discount Code Statuses
294     register_post_status( 'active', array(
295         'label'                     => _x( 'Active', 'Active discount code status', 'edd' ),
296         'public'                    => true,
297         'exclude_from_search'       => false,
298         'show_in_admin_all_list'    => true,
299         'show_in_admin_status_list' => true,
300         'label_count'               => _n_noop( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', 'edd' )
301     )  );
302     register_post_status( 'inactive', array(
303         'label'                     => _x( 'Inactive', 'Inactive discount code status', 'edd' ),
304         'public'                    => true,
305         'exclude_from_search'       => false,
306         'show_in_admin_all_list'    => true,
307         'show_in_admin_status_list' => true,
308         'label_count'               => _n_noop( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', 'edd' )
309     )  );
310 }
311 add_action( 'init', 'edd_register_post_type_statuses' );
312 
313 /**
314  * Updated Messages
315  *
316  * Returns an array of with all updated messages.
317  *
318  * @since 1.0
319  * @param array $messages Post updated message
320  * @return array $messages New post updated messages
321  */
322 function edd_updated_messages( $messages ) {
323     global $post, $post_ID;
324 
325     $url1 = '<a href="' . get_permalink( $post_ID ) . '">';
326     $url2 = edd_get_label_singular();
327     $url3 = '</a>';
328 
329     $messages['download'] = array(
330         1 => sprintf( __( '%2$s updated. %1$sView %2$s%3$s.', 'edd' ), $url1, $url2, $url3 ),
331         4 => sprintf( __( '%2$s updated. %1$sView %2$s%3$s.', 'edd' ), $url1, $url2, $url3 ),
332         6 => sprintf( __( '%2$s published. %1$sView %2$s%3$s.', 'edd' ), $url1, $url2, $url3 ),
333         7 => sprintf( __( '%2$s saved. %1$sView %2$s%3$s.', 'edd' ), $url1, $url2, $url3 ),
334         8 => sprintf( __( '%2$s submitted. %1$sView %2$s%3$s.', 'edd' ), $url1, $url2, $url3 )
335     );
336 
337     return $messages;
338 }
339 add_filter( 'post_updated_messages', 'edd_updated_messages' );
Easy Digital Downloads API documentation generated by ApiGen 2.8.0