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_add_download_filters
  • edd_add_download_meta_box
  • edd_download_columns
  • edd_download_load
  • edd_download_meta_box_save
  • edd_downloads_contextual_help
  • edd_metabox_save_check_blank_rows
  • edd_price_field_quick_edit
  • edd_price_save_quick_edit
  • edd_render_disable_button
  • edd_render_download_columns
  • edd_render_download_limit_row
  • edd_render_download_meta_box
  • edd_render_file_row
  • edd_render_files_field
  • edd_render_price_field
  • edd_render_price_row
  • edd_render_product_notes_field
  • edd_render_product_notes_meta_box
  • edd_render_stats_meta_box
  • edd_sanitize_files_save
  • edd_sanitize_price_save
  • edd_sanitize_variable_prices_save
  • edd_save_bulk_edit
  • edd_sort_downloads
  • edd_sortable_download_columns
  1 <?php
  2 /**
  3  * Dashboard Columns
  4  *
  5  * @package     EDD
  6  * @subpackage  Admin/Downloads
  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  * Download Columns
 17  *
 18  * Defines the custom columns and their order
 19  *
 20  * @since 1.0
 21  * @param array $download_columns Array of download columns
 22  * @return array $download_columns Updated array of download columns for Downloads
 23  *  Post Type List Table
 24  */
 25 function edd_download_columns( $download_columns ) {
 26     $download_columns = array(
 27         'cb'                => '<input type="checkbox"/>',
 28         'title'             => __( 'Name', 'edd' ),
 29         'download_category' => __( 'Categories', 'edd' ),
 30         'download_tag'      => __( 'Tags', 'edd' ),
 31         'price'             => __( 'Price', 'edd' ),
 32         'sales'             => __( 'Sales', 'edd' ),
 33         'earnings'          => __( 'Earnings', 'edd' ),
 34         'shortcode'         => __( 'Purchase Short Code', 'edd' ),
 35         'date'              => __( 'Date', 'edd' )
 36     );
 37 
 38     if ( ! current_user_can( 'view_shop_reports' ) ) {
 39         unset( $download_columns['sales'] );
 40         unset( $download_columns['earnings'] );
 41     }
 42 
 43     return $download_columns;
 44 }
 45 add_filter( 'manage_edit-download_columns', 'edd_download_columns' );
 46 
 47 /**
 48  * Render Download Columns
 49  *
 50  * @since 1.0
 51  * @param string $column_name Column name
 52  * @param int $post_id Download (Post) ID
 53  * @return void
 54  */
 55 function edd_render_download_columns( $column_name, $post_id ) {
 56     if ( get_post_type( $post_id ) == 'download' ) {
 57         global $edd_options;
 58 
 59         $style          = isset( $edd_options['button_style'] ) ? $edd_options['button_style'] : 'button';
 60         $color          = isset( $edd_options['checkout_color'] ) ? $edd_options['checkout_color'] : 'blue';
 61         $purchase_text  = isset( $edd_options['add_to_cart_text'] ) ? $edd_options['add_to_cart_text'] : __( 'Purchase', 'edd' );
 62 
 63         switch ( $column_name ) {
 64             case 'download_category':
 65                 echo get_the_term_list( $post_id, 'download_category', '', ', ', '');
 66                 break;
 67             case 'download_tag':
 68                 echo get_the_term_list( $post_id, 'download_tag', '', ', ', '');
 69                 break;
 70             case 'price':
 71                 if ( edd_has_variable_prices( $post_id ) ) {
 72                     echo edd_price_range( $post_id );
 73                 } else {
 74                     echo edd_price( $post_id, false );
 75                     echo '<input type="hidden" class="downloadprice-' . $post_id . '" value="' . edd_get_download_price( $post_id ) . '" />';
 76                 }
 77                 break;
 78             case 'sales':
 79                 echo edd_get_download_sales_stats( $post_id );
 80                 break;
 81             case 'earnings':
 82                 echo edd_currency_filter( edd_format_amount( edd_get_download_earnings_stats( $post_id ) ) );
 83                 break;
 84             case 'shortcode':
 85                 echo '[purchase_link id="' . absint( $post_id ) . '" text="' . esc_html( $purchase_text ) . '" style="' . $style . '" color="' . esc_attr( $color ) . '"]';
 86                 break;
 87         }
 88     }
 89 }
 90 add_action( 'manage_posts_custom_column', 'edd_render_download_columns', 10, 2 );
 91 
 92 /**
 93  * Registers the sortable columns in the list table
 94  *
 95  * @since 1.0
 96  * @param array $columns Array of the columns
 97  * @return array $columns Array of sortable columns
 98  */
 99 function edd_sortable_download_columns( $columns ) {
100     $columns['price'] = 'price';
101     $columns['sales'] = 'sales';
102     $columns['earnings'] = 'earnings';
103 
104     return $columns;
105 }
106 add_filter( 'manage_edit-download_sortable_columns', 'edd_sortable_download_columns' );
107 
108 /**
109  * Sorts Columns in the Downloads List Table
110  *
111  * @since 1.0
112  * @param array $vars Array of all the sort variables
113  * @return array $vars Array of all the sort variables
114  */
115 function edd_sort_downloads( $vars ) {
116     // Check if we're viewing the "download" post type
117     if ( isset( $vars['post_type'] ) && 'download' == $vars['post_type'] ) {
118         // Check if 'orderby' is set to "sales"
119         if ( isset( $vars['orderby'] ) && 'sales' == $vars['orderby'] ) {
120             $vars = array_merge(
121                 $vars,
122                 array(
123                     'meta_key' => '_edd_download_sales',
124                     'orderby'  => 'meta_value_num'
125                 )
126             );
127         }
128 
129         // Check if "orderby" is set to "earnings"
130         if ( isset( $vars['orderby'] ) && 'earnings' == $vars['orderby'] ) {
131             $vars = array_merge(
132                 $vars,
133                 array(
134                     'meta_key' => '_edd_download_earnings',
135                     'orderby' => 'meta_value_num'
136                 )
137             );
138         }
139 
140         // Check if "orderby" is set to "earnings"
141         if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) {
142             $vars = array_merge(
143                 $vars,
144                 array(
145                     'meta_key' => 'edd_price',
146                     'orderby' => 'meta_value_num'
147                 )
148             );
149         }
150     }
151 
152     return $vars;
153 }
154 
155 /**
156  * Download Load
157  *
158  * Sorts the downloads.
159  *
160  * @since 1.0
161  * @return void
162  */
163 function edd_download_load() {
164     add_filter( 'request', 'edd_sort_downloads' );
165 }
166 add_action( 'load-edit.php', 'edd_download_load', 9999 );
167 
168 /**
169  * Add Download Filters
170  *
171  * Adds taxonomy drop down filters for downloads.
172  *
173  * @since 1.0
174  * @return void
175  */
176 function edd_add_download_filters() {
177     global $typenow;
178 
179     // Checks if the current post type is 'download'
180     if ( $typenow == 'download') {
181         $terms = get_terms( 'download_category' );
182         if ( count( $terms ) > 0 ) {
183             echo "<select name='download_category' id='download_category' class='postform'>";
184                 echo "<option value=''>" . __( 'Show all categories', 'edd' ) . "</option>";
185                 foreach ( $terms as $term ) {
186                     $selected = isset( $_GET['download_category'] ) && $_GET['download_category'] == $term->slug ? ' selected="selected"' : '';
187                     echo '<option value="' . esc_attr( $term->slug ) . '"' . $selected . '>' . esc_html( $term->name ) .' (' . $term->count .')</option>';
188                 }
189             echo "</select>";
190         }
191 
192         $terms = get_terms( 'download_tag' );
193         if ( count( $terms ) > 0) {
194             echo "<select name='download_tag' id='download_tag' class='postform'>";
195                 echo "<option value=''>" . __( 'Show all tags', 'edd' ) . "</option>";
196                 foreach ( $terms as $term ) {
197                     $selected = isset( $_GET['download_tag']) && $_GET['download_tag'] == $term->slug ? ' selected="selected"' : '';
198                     echo '<option value="' . esc_attr( $term->slug ) . '"' . $selected . '>' . esc_html( $term->name ) .' (' . $term->count .')</option>';
199                 }
200             echo "</select>";
201         }
202     }
203 
204 }
205 add_action( 'restrict_manage_posts', 'edd_add_download_filters', 100 );
206 
207 /**
208  * Adds price field to Quick Edit options
209  *
210  * @since 1.1.3.4
211  * @param string $column_name Name of the column
212  * @param string $post_type Current Post Type (i.e. download)
213  * @return void
214  */
215 function edd_price_field_quick_edit( $column_name, $post_type ) {
216     if ( $column_name != 'price' || $post_type != 'download' ) return;
217     ?>
218     <fieldset class="inline-edit-col-left">
219         <div id="edd-download-data" class="inline-edit-col">
220             <h4><?php echo sprintf( __( '%s Configuration', 'edd' ), edd_get_label_singular() ); ?></h4>
221             <label>
222                 <span class="title"><?php _e( 'Price', 'edd' ); ?></span>
223                 <span class="input-text-wrap">
224                     <input type="text" name="_edd_regprice" class="text regprice" />
225                 </span>
226             </label>
227             <br class="clear" />
228         </div>
229     </fieldset>
230     <?php
231 }
232 add_action( 'quick_edit_custom_box', 'edd_price_field_quick_edit', 10, 2 );
233 add_action( 'bulk_edit_custom_box', 'edd_price_field_quick_edit', 10, 2 );
234 
235 /**
236  * Updates price when saving post
237  *
238  * @since 1.1.3.4
239  * @param int $post_id Download (Post) ID
240  * @return void
241  */
242 function edd_price_save_quick_edit( $post_id ) {
243     if ( ! isset( $_POST['post_type']) || 'download' !== $_POST['post_type'] ) return;
244     if ( ! current_user_can( 'edit_post', $post_id ) ) return $post_id;
245     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id;
246 
247     if ( isset( $_REQUEST['_edd_regprice'] ) ) {
248         update_post_meta( $post_id, 'edd_price', strip_tags( stripslashes( $_REQUEST['_edd_regprice'] ) ) );
249     }
250 }
251 add_action( 'save_post', 'edd_price_save_quick_edit' );
252 
253 /**
254  * Process bulk edit actions via AJAX
255  *
256  * @since 1.4.4
257  * @return void
258  */
259 function edd_save_bulk_edit() {
260     $post_ids = ( isset( $_POST[ 'post_ids' ] ) && ! empty( $_POST[ 'post_ids' ] ) ) ? $_POST[ 'post_ids' ] : array();
261 
262     if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
263         $price = isset( $_POST['price'] ) ? strip_tags( stripslashes( $_POST['price'] ) ) : 0;
264         foreach ( $post_ids as $post_id ) {
265             if ( ! empty( $price ) ) {
266                 update_post_meta( $post_id, 'edd_price', edd_sanitize_amount( $price ) );
267             }
268         }
269     }
270 
271     die();
272 }
273 add_action( 'wp_ajax_edd_save_bulk_edit', 'edd_save_bulk_edit' );
Easy Digital Downloads API documentation generated by ApiGen 2.8.0