1 <?php
2 3 4 5 6 7 8 9 10
11
12
13 if ( ! defined( 'ABSPATH' ) ) exit;
14
15 16 17 18 19 20 21 22 23 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 49 50 51 52 53 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 94 95 96 97 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 110 111 112 113 114
115 function edd_sort_downloads( $vars ) {
116
117 if ( isset( $vars['post_type'] ) && 'download' == $vars['post_type'] ) {
118
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
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
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 157 158 159 160 161 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 170 171 172 173 174 175
176 function edd_add_download_filters() {
177 global $typenow;
178
179
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 209 210 211 212 213 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 237 238 239 240 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 255 256 257 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' );