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  * Metabox Functions
  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 /** All Downloads *****************************************************************/
 16 
 17 /**
 18  * Register all the meta boxes for the Download custom post type
 19  *
 20  * @since 1.0
 21  * @return void
 22  */
 23 function edd_add_download_meta_box() {
 24     /** Download Configuration */
 25     add_meta_box( 'downloadinformation', sprintf( __( '%1$s Configuration', 'edd' ), edd_get_label_singular(), edd_get_label_plural() ),  'edd_render_download_meta_box', 'download', 'normal', 'default' );
 26 
 27     /** Product Notes */
 28     add_meta_box( 'edd_product_notes', __( 'Product Notes', 'edd' ), 'edd_render_product_notes_meta_box', 'download', 'normal', 'default' );
 29 
 30     if ( current_user_can( 'edit_product', get_the_ID() ) ) {
 31         /** Download Stats */
 32         add_meta_box( 'edd_download_stats', sprintf( __( '%1$s Stats', 'edd' ), edd_get_label_singular(), edd_get_label_plural() ), 'edd_render_stats_meta_box', 'download', 'side', 'high' );
 33     }
 34 }
 35 add_action( 'add_meta_boxes', 'edd_add_download_meta_box' );
 36 
 37 /**
 38  * Sabe post meta when the save_post action is called
 39  *
 40  * @since 1.0
 41  * @param int $post_id Download (Post) ID
 42  * @global array $post All the data of the the current post
 43  * @return void
 44  */
 45 function edd_download_meta_box_save( $post_id) {
 46     global $post;
 47 
 48     if ( ! isset( $_POST['edd_download_meta_box_nonce'] ) || ! wp_verify_nonce( $_POST['edd_download_meta_box_nonce'], basename( __FILE__ ) ) )
 49         return $post_id;
 50 
 51     if ( ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) return $post_id;
 52 
 53     if ( isset( $post->post_type ) && $post->post_type == 'revision' )
 54         return $post_id;
 55 
 56     if ( ! current_user_can( 'edit_pages', $post_id ) ) {
 57         return $post_id;
 58     }
 59 
 60     // The default fields that get saved
 61     $fields = apply_filters( 'edd_metabox_fields_save', array(
 62             'edd_price',
 63             '_variable_pricing',
 64             '_edd_price_options_mode',
 65             'edd_variable_prices',
 66             'edd_download_files',
 67             '_edd_purchase_text',
 68             '_edd_purchase_style',
 69             '_edd_purchase_color',
 70             '_edd_download_limit',
 71             '_edd_hide_purchase_link',
 72             'edd_product_notes'
 73         )
 74     );
 75 
 76     foreach ( $fields as $field ) {
 77         if ( isset( $_POST[ $field ] ) ) {
 78             if ( is_string( $_POST[ $field ] ) ) {
 79                 $new = esc_attr( $_POST[ $field ] );
 80             } else {
 81                 $new = $_POST[ $field ];
 82             }
 83 
 84             $new = apply_filters( 'edd_metabox_save_' . $field, $new );
 85 
 86             update_post_meta( $post_id, $field, $new );
 87         } else {
 88             delete_post_meta( $post_id, $field );
 89         }
 90     }
 91 }
 92 add_action( 'save_post', 'edd_download_meta_box_save' );
 93 
 94 /**
 95  * Sanitize the price before it is saved
 96  *
 97  * This is mostly for ensuring commas aren't saved in the price
 98  *
 99  * @since 1.3.2
100  * @param string $price Price before sanitization
101  * @return float $price Sanitized price
102  */
103 function edd_sanitize_price_save( $price ) {
104     global $edd_options;
105 
106     $thousands_sep = ! empty( $edd_options['thousands_separator'] ) ? $edd_options['thousands_separator'] : ',';
107     $decimal_sep   = ! empty( $edd_options['decimal_separator'] )   ? $edd_options['decimal_separator']     : '.';
108 
109     if ( $thousands_sep == ',' ) {
110         $price = str_replace( ',', '', $price );
111     }
112 
113     return $price;
114 }
115 add_filter( 'edd_metabox_save_edd_price', 'edd_sanitize_price_save' );
116 
117 /**
118  * Sanitize the variable prices
119  *
120  * Ensures prices are correctly mapped to an array starting with an index of 0
121  *
122  * @since 1.4.2
123  * @param array $prices Variable prices
124  * @return array $prices Array of the remapped variable prices
125  */
126 function edd_sanitize_variable_prices_save( $prices ) {
127     // Make sure all prices are rekeyed starting at 0
128     return array_values( $prices );
129 }
130 add_filter( 'edd_metabox_save_edd_variable_prices', 'edd_sanitize_variable_prices_save' );
131 
132 /**
133  * Sanitize the file downloads
134  *
135  * Ensures files are correctly mapped to an array starting with an index of 0
136  *
137  * @since 1.5.1
138  * @param array $files Array of all the file downloads
139  * @return array $files Array of the remapped file downloads
140  */
141 function edd_sanitize_files_save( $files ) {
142     // Make sure all files are rekeyed starting at 0
143     return array_values( $files );
144 }
145 add_filter( 'edd_metabox_save_edd_download_files', 'edd_sanitize_files_save' );
146 
147 
148 /** Download Configuration *****************************************************************/
149 
150 /**
151  * Download Metabox
152  *
153  * Extensions (as well as the core plugin) can add items to the main download
154  * configuration metabox via the `edd_meta_box_fields` action.
155  *
156  * @since 1.0
157  * @return void
158  */
159 function edd_render_download_meta_box() {
160     global $post, $edd_options;
161 
162     do_action( 'edd_meta_box_fields', $post->ID );
163     wp_nonce_field( basename( __FILE__ ), 'edd_download_meta_box_nonce' );
164 }
165 
166 /**
167  * Price Section
168  *
169  * If variable pricing is not enabled, simply output a single input box.
170  *
171  * If variable pricing is enabled, outputs a table of all current prices.
172  * Extensions can add column heads to the table via the `edd_download_file_table_head`
173  * hook, and actual columns via `edd_download_file_table_row`
174  *
175  * @since 1.0
176  * @see edd_render_price_row()
177  * @return void
178  */
179 function edd_render_price_field( $post_id ) {
180     global $edd_options;
181 
182     $price              = edd_get_download_price( $post_id );
183     $variable_pricing   = edd_has_variable_prices( $post_id );
184     $prices             = edd_get_variable_prices( $post_id );
185     $single_option_mode = edd_single_price_option_mode( $post_id );
186 
187     $price_display      = $variable_pricing ? ' style="display:none;"' : '';
188     $variable_display   = $variable_pricing ? '' : ' style="display:none;"';
189 ?>
190     <p>
191         <strong><?php echo apply_filters( 'edd_price_options_heading', __( 'Pricing Options:', 'edd' ) ); ?></strong>
192     </p>
193 
194     <p>
195         <label for="edd_variable_pricing">
196             <input type="checkbox" name="_variable_pricing" id="edd_variable_pricing" value="1" <?php checked( 1, $variable_pricing ); ?> />
197             <?php echo apply_filters( 'edd_variable_pricing_toggle_text', __( 'Enable variable pricing', 'edd' ) ); ?>
198         </label>
199     </p>
200 
201     <div id="edd_regular_price_field" class="edd_pricing_fields" <?php echo $price_display; ?>>
202         <?php if ( ! isset( $edd_options['currency_position'] ) || $edd_options['currency_position'] == 'before' ) : ?>
203             <?php echo edd_currency_filter( '' ); ?><input type="text" name="edd_price" id="edd_price" value="<?php echo isset( $price ) ? esc_attr( edd_format_amount( $price ) ) : ''; ?>" size="30" style="width: 80px;" placeholder="9.99"/>
204         <?php else : ?>
205             <input type="text" name="edd_price" id="edd_price" value="<?php echo isset( $price ) ? esc_attr( edd_format_amount( $price ) ) : ''; ?>" size="30" style="width: 80px;" placeholder="9.99"/><?php echo edd_currency_filter( '' ); ?>
206         <?php endif; ?>
207 
208         <?php do_action( 'edd_price_field', $post_id ); ?>
209     </div>
210 
211     <?php do_action( 'edd_after_price_field', $post_id ); ?>
212 
213     <div id="edd_variable_price_fields" class="edd_pricing_fields" <?php echo $variable_display; ?>>
214         <input type="hidden" id="edd_variable_prices" class="edd_variable_prices_name_field" value=""/>
215         <p>
216             <input type="checkbox" name="_edd_price_options_mode" id="edd_price_options_mode"<?php checked( 1, $single_option_mode ); ?> />
217             <label for="edd_price_options_mode"><?php apply_filters( 'edd_multi_option_purchase_text', _e( 'Enable multi option purchase mode. Leave unchecked to only permit a single price option to be purchased', 'edd' ) ); ?></label>
218         </p>
219         <div id="edd_price_fields" class="edd_meta_table_wrap">
220             <table class="widefat" width="100%" cellpadding="0" cellspacing="0">
221                 <thead>
222                     <tr>
223                         <th><?php _e( 'Option Name', 'edd' ); ?></th>
224                         <th style="width: 90px"><?php _e( 'Price', 'edd' ); ?></th>
225                         <?php do_action( 'edd_download_price_table_head', $post_id ); ?>
226                         <th style="width: 2%"></th>
227                     </tr>
228                 </thead>
229                 <tbody>
230                     <?php
231                         if ( ! empty( $prices ) ) :
232                             foreach ( $prices as $key => $value ) :
233                                 $name   = isset( $value['name'] ) ? $value['name'] : '';
234                                 $amount = isset( $value['amount'] ) ? $value['amount'] : '';
235 
236                                 $args = apply_filters( 'edd_price_row_args', compact( 'name', 'amount' ), $value );
237                     ?>
238                         <tr class="edd_variable_prices_wrapper">
239                             <?php do_action( 'edd_render_price_row', $key, $args, $post_id ); ?>
240                         </tr>
241                     <?php
242                             endforeach;
243                         else :
244                     ?>
245                         <tr class="edd_variable_prices_wrapper">
246                             <?php do_action( 'edd_render_price_row', 0, array(), $post_id ); ?>
247                         </tr>
248                     <?php endif; ?>
249 
250                     <tr>
251                         <td class="submit" colspan="4" style="float: none; clear:both; background:#fff;">
252                             <a class="button-secondary edd_add_repeatable" style="margin: 6px 0;"><?php _e( 'Add New Price', 'edd' ); ?></a>
253                         </td>
254                     </tr>
255                 </tbody>
256             </table>
257         </div>
258     </div><!--end #edd_variable_price_fields-->
259 <?php
260 }
261 add_action( 'edd_meta_box_fields', 'edd_render_price_field', 10 );
262 
263 /**
264  * Individual Price Row
265  *
266  * Used to output a table row for each price associated with a download.
267  * Can be called directly, or attached to an action.
268  *
269  * @since 1.2.2
270  * @return void
271  */
272 function edd_render_price_row( $key, $args = array(), $post_id ) {
273     global $edd_options;
274 
275     $defaults = array(
276         'name'   => null,
277         'amount' => null
278     );
279 
280     $args = wp_parse_args( $args, $defaults );
281     extract( $args, EXTR_SKIP );
282 ?>
283     <td>
284         <input type="text" class="edd_variable_prices_name" placeholder="<?php _e( 'Option Name', 'edd' ); ?>" name="edd_variable_prices[<?php echo $key; ?>][name]" id="edd_variable_prices[<?php echo $key; ?>][name]" value="<?php echo esc_attr( $name ); ?>" size="20" style="width:100%" />
285     </td>
286 
287     <td>
288         <?php if( ! isset( $edd_options['currency_position'] ) || $edd_options['currency_position'] == 'before' ) : ?>
289             <span><?php echo edd_currency_filter( '' ); ?></span> <input type="text" class="edd_variable_prices_amount text" value="<?php echo $amount; ?>" placeholder="9.99" name="edd_variable_prices[<?php echo $key; ?>][amount]" id="edd_variable_prices[<?php echo $key; ?>][amount]" size="30" style="width:80px;" />
290         <?php else : ?>
291             <input type="text" class="edd_variable_prices_amount text" value="<?php echo $amount; ?>" placeholder="9.99" name="edd_variable_prices[<?php echo $key; ?>][amount]" id="edd_variable_prices[<?php echo $key; ?>][amount]" size="30" style="width:80px;" /><?php echo edd_currency_filter( '' ); ?>
292         <?php endif; ?>
293     </td>
294 
295     <?php do_action( 'edd_download_price_table_row', $post_id, $key, $args ); ?>
296 
297     <td>
298         <a href="#" class="edd_remove_repeatable" data-type="price" style="background: url(<?php echo admin_url('/images/xit.gif'); ?>) no-repeat;">&times;</a>
299     </td>
300 <?php
301 }
302 add_action( 'edd_render_price_row', 'edd_render_price_row', 10, 3 );
303 
304 /**
305  * File Downloads section.
306  *
307  * Outputs a table of all current files. Extensions can add column heads to the table
308  * via the `edd_download_file_table_head` hook, and actual columns via
309  * `edd_download_file_table_row`
310  *
311  * @since 1.0
312  * @see edd_render_file_row()
313  * @param int $post_id Download (Post) ID
314  * @return void
315  */
316 function edd_render_files_field( $post_id ) {
317     $files          = edd_get_download_files( $post_id );
318     $variable_pricing   = edd_has_variable_prices( $post_id );
319     $variable_display   = $variable_pricing ? '' : 'display:none;';
320 ?>
321     <div id="edd_download_files">
322         <p>
323             <strong><?php _e( 'File Downloads:', 'edd' ); ?></strong>
324         </p>
325 
326         <input type="hidden" id="edd_download_files" class="edd_repeatable_upload_name_field" value=""/>
327 
328         <div id="edd_file_fields" class="edd_meta_table_wrap">
329             <table class="widefat" width="100%" cellpadding="0" cellspacing="0">
330                 <thead>
331                     <tr>
332                         <th style="width: 20%"><?php _e( 'File Name', 'edd' ); ?></th>
333                         <th><?php _e( 'File URL', 'edd' ); ?></th>
334                         <th class="pricing" style="width: 20%; <?php echo $variable_display; ?>"><?php _e( 'Price Assignment', 'edd' ); ?></th>
335                         <?php do_action( 'edd_download_file_table_head', $post_id ); ?>
336                         <th style="width: 2%"></th>
337                     </tr>
338                 </thead>
339                 <tbody>
340                 <?php
341                     if ( ! empty( $files ) ) :
342                         foreach ( $files as $key => $value ) :
343                             $name = isset( $value['name'] ) ? $value['name'] : '';
344                             $file = isset( $value['file'] ) ? $value['file'] : '';
345                             $condition = isset( $value['condition'] ) ? $value['condition'] : false;
346 
347                             $args = apply_filters( 'edd_file_row_args', compact( 'name', 'file', 'condition' ), $value );
348                 ?>
349                         <tr class="edd_repeatable_upload_wrapper">
350                             <?php do_action( 'edd_render_file_row', $key, $args, $post_id ); ?>
351                         </tr>
352                 <?php
353                         endforeach;
354                     else :
355                 ?>
356                     <tr class="edd_repeatable_upload_wrapper">
357                         <?php do_action( 'edd_render_file_row', 0, array(), $post_id ); ?>
358                     </tr>
359                 <?php endif; ?>
360                     <tr>
361                         <td class="submit" colspan="4" style="float: none; clear:both; background: #fff;">
362                             <a class="button-secondary edd_add_repeatable" style="margin: 6px 0;"><?php _e( 'Add New File', 'edd' ); ?></a>
363                         </td>
364                     </tr>
365                 </tbody>
366             </table>
367         </div>
368     </div>
369 <?php
370 }
371 add_action( 'edd_meta_box_fields', 'edd_render_files_field', 20 );
372 
373 /**
374  * Individual file row.
375  *
376  * Used to output a table row for each file associated with a download.
377  * Can be called directly, or attached to an action.
378  *
379  * @since 1.2.2
380  * @param string $key Array key
381  * @param array $args Array of all the arguments passed to the function
382  * @param int $post_id Download (Post) ID
383  * @return void
384  */
385 function edd_render_file_row( $key = '', $args = array(), $post_id ) {
386     $defaults = array(
387         'name'      => null,
388         'file'      => null,
389         'condition' => null
390     );
391 
392     $args = wp_parse_args( $args, $defaults );
393     extract( $args, EXTR_SKIP );
394 
395     $prices = edd_get_variable_prices( $post_id );
396 
397     $variable_pricing = edd_has_variable_prices( $post_id );
398     $variable_display = $variable_pricing ? '' : ' style="display:none;"';
399 ?>
400     <td>
401         <input type="text" class="edd_repeatable_name_field" name="edd_download_files[<?php echo $key; ?>][name]" id="edd_download_files[<?php echo $key; ?>][name]" value="<?php echo $name; ?>" placeholder="<?php _e( 'File Name', 'edd' ); ?>" style="width:100%" />
402     </td>
403 
404     <td>
405         <div class="edd_repeatable_upload_field_container">
406             <input type="text" class="edd_repeatable_upload_field edd_upload_field" name="edd_download_files[<?php echo $key; ?>][file]" id="edd_download_files[<?php echo $key; ?>][file]" value="<?php echo $file; ?>" placeholder="<?php _e( 'http://', 'edd' ); ?>" style="width:100%" />
407 
408             <span class="edd_upload_file">
409                 <a href="#" data-uploader_title="" data-uploader_button_text="<?php _e( 'Insert', 'edd' ); ?>" class="edd_upload_image_button" onclick="return false;"><?php _e( 'Upload a File', 'edd' ); ?></a>
410             </span>
411         </div>
412     </td>
413 
414     <td class="pricing"<?php echo $variable_display; ?>>
415         <select class="edd_repeatable_condition_field" name="edd_download_files[<?php echo $key; ?>][condition]" id="edd_download_files[<?php echo $key; ?>][condition]" <?php echo $variable_display; ?>>
416             <option value="all"><?php _e( 'All Prices', 'edd' ); ?></option>
417             <?php if ( $prices ) : foreach ( $prices as $price_key => $price ) : ?>
418                 <option value="<?php echo $price_key; ?>" <?php selected( $price_key, $condition ); ?>><?php echo $prices[ $price_key ]['name']; ?></option>
419             <?php endforeach; endif; ?>
420         </select>
421     </td>
422 
423     <?php do_action( 'edd_download_file_table_row', $post_id, $key, $args ); ?>
424 
425     <td>
426         <a href="#" class="edd_remove_repeatable" data-type="file" style="background: url(<?php echo admin_url('/images/xit.gif'); ?>) no-repeat;">&times;</a>
427     </td>
428 <?php
429 }
430 add_action( 'edd_render_file_row', 'edd_render_file_row', 10, 3 );
431 
432 /**
433  * File Download Limit Row
434  *
435  * The file download limit is the maximum number of times each file
436  * can be downloaded by the buyer
437  *
438  * @since 1.3.1
439  * @param int $post_id Download (Post) ID
440  * @return void
441  */
442 function edd_render_download_limit_row( $post_id ) {
443     global $edd_options;
444     $edd_download_limit = edd_get_file_download_limit( $post_id );
445 ?>
446     <p><strong><?php _e( 'File Download Limit:', 'edd' ); ?></strong></p>
447     <label for="edd_download_limit">
448         <input type="text" name="_edd_download_limit" id="edd_download_limit" value="<?php echo esc_attr( $edd_download_limit ); ?>" size="30" style="width: 80px;" placeholder="0"/>
449         <?php _e( 'The maximum number of times a buyer can download each file. Leave blank or set to 0 for unlimited', 'edd' ); ?>
450     </label>
451 <?php
452 }
453 add_action( 'edd_meta_box_fields', 'edd_render_download_limit_row', 20 );
454 
455 
456 /**
457  * Render Disable Button
458  *
459  * @since 1.0
460  * @param int $post_id Download (Post) ID
461  * @return void
462  */
463 function edd_render_disable_button( $post_id ) {
464     $hide_button = get_post_meta( $post_id, '_edd_hide_purchase_link', true ) ? true : false;
465 ?>
466     <p><strong><?php _e( 'Button Options:', 'edd' ); ?></strong></p>
467     <p>
468         <label for="_edd_hide_purchase_link">
469             <input type="checkbox" name="_edd_hide_purchase_link" id="_edd_hide_purchase_link" value="1" <?php checked( true, $hide_button ); ?> />
470             <?php _e( 'Disable the automatic output of the purchase button', 'edd' ); ?>
471         </label>
472     </p>
473 <?php
474 }
475 add_action( 'edd_meta_box_fields', 'edd_render_disable_button', 30 );
476 
477 /**
478  * Don't save blank rows.
479  *
480  * When saving, check the price and file table for blank rows.
481  * If the name of the price or file is empty, that row should not
482  * be saved.
483  *
484  * @since 1.2.2
485  * @param array $new Array of all the meta values
486  * @return array $new New meta value with empty keys removed
487  */
488 function edd_metabox_save_check_blank_rows( $new ) {
489     foreach ( $new as $key => $value ) {
490         if ( empty( $value['name'] ) && empty( $value['amount'] ) && empty( $value['file'] ) )
491             unset( $new[ $key ] );
492     }
493 
494     return $new;
495 }
496 add_filter( 'edd_metabox_save_edd_variable_prices', 'edd_metabox_save_check_blank_rows' );
497 add_filter( 'edd_metabox_save_edd_download_files', 'edd_metabox_save_check_blank_rows' );
498 
499 
500 /** Product Notes *****************************************************************/
501 
502 /**
503  * Product Notes Meta Box
504  *
505  * Renders the Product Notes meta box
506  *
507  * @since 1.2.1
508  * @global array $post Contains all the download data
509  * @global array $edd_options Contains all the options set for EDD
510  * @return void
511  */
512 function edd_render_product_notes_meta_box() {
513     global $post, $edd_options;
514 
515     do_action( 'edd_product_notes_meta_box_fields', $post->ID );
516 }
517 
518 /**
519  * Render Product Notes Field
520  *
521  * @since 1.2.1
522  * @param int $post_id Download (Post) ID
523  * @return void
524  */
525 function edd_render_product_notes_field( $post_id ) {
526     global $edd_options;
527 
528     $product_notes = edd_get_product_notes( $post_id );
529 ?>
530     <textarea rows="1" cols="40" class="large-texarea" name="edd_product_notes" id="edd_product_notes"><?php echo esc_textarea( $product_notes ); ?></textarea>
531     <p><?php _e( 'Special notes or instructions for this product. These notes will be added to the purchase receipt.', 'edd' ); ?></p>
532 <?php
533 }
534 add_action( 'edd_product_notes_meta_box_fields', 'edd_render_product_notes_field' );
535 
536 
537 /** Stats *****************************************************************/
538 
539 /**
540  * Render Stats Meta Box
541  *
542  * @since 1.0
543  * @global array $post Contains all the download data
544  * @return void
545  */
546 function edd_render_stats_meta_box() {
547     global $post;
548 
549     $earnings = edd_get_download_earnings_stats( $post->ID );
550     $sales    = edd_get_download_sales_stats( $post->ID );
551 
552     echo '<table class="form-table">';
553         echo '<tr>';
554             echo '<th style="width: 20%">' . __( 'Sales:', 'edd' ) . '</th>';
555             echo '<td class="edd_download_stats">';
556                 echo $sales . '&nbsp;&ndash;&nbsp;<a href="' . admin_url( '/edit.php?page=edd-reports&view=sales&post_type=download&tab=logs&download=' . $post->ID ) . '">' . __( 'View Sales Log', 'edd' ) . '</a>';
557             echo '</td>';
558         echo '</tr>';
559         echo '<tr>';
560             echo '<th style="width: 20%">' . __( 'Earnings:', 'edd' ) . '</th>';
561             echo '<td class="edd_download_stats">';
562                 echo edd_currency_filter( edd_format_amount( $earnings ) );
563             echo '</td>';
564         echo '</tr>';
565         echo '<tr>';
566             echo '<td colspan="2" class="edd_download_stats">';
567                 echo '<a href="' . admin_url( '/edit.php?page=edd-reports&view=file_downloads&post_type=download&tab=logs&download=' . $post->ID ) . '">' . __( 'View File Download Log', 'edd' ) . '</a>';
568             echo '</td>';
569         echo '</tr>';
570         do_action('edd_stats_meta_box');
571     echo '</table>';
572 }
Easy Digital Downloads API documentation generated by ApiGen 2.8.0