35 'plural' => 'media', |
49 'plural' => 'media', |
36 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
50 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
37 ) ); |
51 ) ); |
38 } |
52 } |
39 |
53 |
|
54 /** |
|
55 * |
|
56 * @return bool |
|
57 */ |
40 public function ajax_user_can() { |
58 public function ajax_user_can() { |
41 return current_user_can('upload_files'); |
59 return current_user_can('upload_files'); |
42 } |
60 } |
43 |
61 |
|
62 /** |
|
63 * |
|
64 * @global WP_Query $wp_query |
|
65 * @global array $post_mime_types |
|
66 * @global array $avail_post_mime_types |
|
67 * @global string $mode |
|
68 */ |
44 public function prepare_items() { |
69 public function prepare_items() { |
45 global $wp_query, $post_mime_types, $avail_post_mime_types, $mode; |
70 global $wp_query, $post_mime_types, $avail_post_mime_types, $mode; |
46 |
71 |
47 list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $_REQUEST ); |
72 list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $_REQUEST ); |
48 |
73 |
49 $this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' == $_REQUEST['attachment-filter']; |
74 $this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter']; |
50 |
75 |
51 $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode']; |
76 $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode']; |
52 |
77 |
53 $this->set_pagination_args( array( |
78 $this->set_pagination_args( array( |
54 'total_items' => $wp_query->found_posts, |
79 'total_items' => $wp_query->found_posts, |
55 'total_pages' => $wp_query->max_num_pages, |
80 'total_pages' => $wp_query->max_num_pages, |
56 'per_page' => $wp_query->query_vars['posts_per_page'], |
81 'per_page' => $wp_query->query_vars['posts_per_page'], |
57 ) ); |
82 ) ); |
58 } |
83 } |
59 |
84 |
|
85 /** |
|
86 * @global array $post_mime_types |
|
87 * @global array $avail_post_mime_types |
|
88 * @return array |
|
89 */ |
60 protected function get_views() { |
90 protected function get_views() { |
61 global $wpdb, $post_mime_types, $avail_post_mime_types; |
91 global $post_mime_types, $avail_post_mime_types; |
62 |
92 |
63 $type_links = array(); |
93 $type_links = array(); |
64 $_num_posts = (array) wp_count_attachments(); |
94 |
65 $_total_posts = array_sum($_num_posts) - $_num_posts['trash']; |
95 $filter = empty( $_GET['attachment-filter'] ) ? '' : $_GET['attachment-filter']; |
66 $total_orphans = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" ); |
96 |
67 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); |
97 $type_links['all'] = sprintf( |
68 foreach ( $matches as $type => $reals ) |
98 '<option value=""%s>%s</option>', |
69 foreach ( $reals as $real ) |
99 selected( $filter, true, false ), |
70 $num_posts[$type] = ( isset( $num_posts[$type] ) ) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real]; |
100 __( 'All media items' ) |
71 |
101 ); |
72 $selected = empty( $_GET['attachment-filter'] ) ? ' selected="selected"' : ''; |
102 |
73 $type_links['all'] = "<option value=''$selected>" . sprintf( _nx( 'All (%s)', 'All (%s)', $_total_posts, 'uploaded files' ), number_format_i18n( $_total_posts ) ) . '</option>'; |
|
74 foreach ( $post_mime_types as $mime_type => $label ) { |
103 foreach ( $post_mime_types as $mime_type => $label ) { |
75 if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) |
104 if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) { |
76 continue; |
105 continue; |
77 |
106 } |
78 $selected = ''; |
107 |
79 if ( !empty( $_GET['attachment-filter'] ) && strpos( $_GET['attachment-filter'], 'post_mime_type:' ) === 0 && wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $_GET['attachment-filter'] ) ) ) |
108 $selected = selected( |
80 $selected = ' selected="selected"'; |
109 $filter && 0 === strpos( $filter, 'post_mime_type:' ) && |
81 if ( !empty( $num_posts[$mime_type] ) ) |
110 wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $filter ) ), |
82 $type_links[$mime_type] = '<option value="post_mime_type:' . esc_attr( $mime_type ) . '"' . $selected . '>' . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</option>'; |
111 true, |
83 } |
112 false |
84 $type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '>' . sprintf( _nx( 'Unattached (%s)', 'Unattached (%s)', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</option>'; |
113 ); |
85 |
114 |
86 if ( !empty($_num_posts['trash']) ) |
115 $type_links[$mime_type] = sprintf( |
87 $type_links['trash'] = '<option value="trash"' . ( (isset($_GET['attachment-filter']) && $_GET['attachment-filter'] == 'trash' ) ? ' selected="selected"' : '') . '>' . sprintf( _nx( 'Trash (%s)', 'Trash (%s)', $_num_posts['trash'], 'uploaded files' ), number_format_i18n( $_num_posts['trash'] ) ) . '</option>'; |
116 '<option value="post_mime_type:%s"%s>%s</option>', |
|
117 esc_attr( $mime_type ), |
|
118 $selected, |
|
119 $label[0] |
|
120 ); |
|
121 } |
|
122 |
|
123 $type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '>' . __( 'Unattached' ) . '</option>'; |
|
124 |
|
125 $type_links['mine'] = sprintf( |
|
126 '<option value="mine"%s>%s</option>', |
|
127 selected( 'mine' === $filter, true, false ), |
|
128 _x( 'Mine', 'media items' ) |
|
129 ); |
|
130 |
|
131 if ( $this->is_trash || ( defined( 'MEDIA_TRASH') && MEDIA_TRASH ) ) { |
|
132 $type_links['trash'] = sprintf( |
|
133 '<option value="trash"%s>%s</option>', |
|
134 selected( 'trash' === $filter, true, false ), |
|
135 _x( 'Trash', 'attachment filter' ) |
|
136 ); |
|
137 } |
88 |
138 |
89 return $type_links; |
139 return $type_links; |
90 } |
140 } |
91 |
141 |
|
142 /** |
|
143 * |
|
144 * @return array |
|
145 */ |
92 protected function get_bulk_actions() { |
146 protected function get_bulk_actions() { |
93 $actions = array(); |
147 $actions = array(); |
94 if ( MEDIA_TRASH ) { |
148 if ( MEDIA_TRASH ) { |
95 if ( $this->is_trash ) { |
149 if ( $this->is_trash ) { |
96 $actions['untrash'] = __( 'Restore' ); |
150 $actions['untrash'] = __( 'Restore' ); |
97 $actions['delete'] = __( 'Delete Permanently' ); |
151 $actions['delete'] = __( 'Delete Permanently' ); |
98 } else { |
152 } else { |
99 $actions['trash'] = __( 'Trash' ); |
153 $actions['trash'] = _x( 'Trash', 'verb' ); |
100 } |
154 } |
101 } else { |
155 } else { |
102 $actions['delete'] = __( 'Delete Permanently' ); |
156 $actions['delete'] = __( 'Delete Permanently' ); |
103 } |
157 } |
104 |
158 |
105 if ( $this->detached ) |
159 if ( $this->detached ) |
106 $actions['attach'] = __( 'Attach to a post' ); |
160 $actions['attach'] = __( 'Attach' ); |
107 |
161 |
108 return $actions; |
162 return $actions; |
109 } |
163 } |
110 |
164 |
111 /** |
165 /** |
196 ?> |
265 ?> |
197 </div> |
266 </div> |
198 |
267 |
199 <div class="search-form"> |
268 <div class="search-form"> |
200 <label for="media-search-input" class="screen-reader-text"><?php esc_html_e( 'Search Media' ); ?></label> |
269 <label for="media-search-input" class="screen-reader-text"><?php esc_html_e( 'Search Media' ); ?></label> |
201 <input type="search" placeholder="<?php esc_attr_e( 'Search' ) ?>" id="media-search-input" class="search" name="s" value="<?php _admin_search_query(); ?>"></div> |
270 <input type="search" placeholder="<?php esc_attr_e( 'Search media items...' ) ?>" id="media-search-input" class="search" name="s" value="<?php _admin_search_query(); ?>"></div> |
202 </div> |
271 </div> |
203 <?php |
272 <?php |
204 } |
273 } |
205 |
274 |
|
275 /** |
|
276 * |
|
277 * @return array |
|
278 */ |
206 public function get_columns() { |
279 public function get_columns() { |
207 $posts_columns = array(); |
280 $posts_columns = array(); |
208 $posts_columns['cb'] = '<input type="checkbox" />'; |
281 $posts_columns['cb'] = '<input type="checkbox" />'; |
209 $posts_columns['icon'] = ''; |
|
210 /* translators: column name */ |
282 /* translators: column name */ |
211 $posts_columns['title'] = _x( 'File', 'column name' ); |
283 $posts_columns['title'] = _x( 'File', 'column name' ); |
212 $posts_columns['author'] = __( 'Author' ); |
284 $posts_columns['author'] = __( 'Author' ); |
213 |
285 |
214 $taxonomies = get_taxonomies_for_attachments( 'objects' ); |
286 $taxonomies = get_taxonomies_for_attachments( 'objects' ); |
215 $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' ); |
287 $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' ); |
216 |
288 |
217 /** |
289 /** |
218 * Filter the taxonomy columns for attachments in the Media list table. |
290 * Filters the taxonomy columns for attachments in the Media list table. |
219 * |
291 * |
220 * @since 3.5.0 |
292 * @since 3.5.0 |
221 * |
293 * |
222 * @param array $taxonomies An array of registered taxonomies to show for attachments. |
294 * @param array $taxonomies An array of registered taxonomies to show for attachments. |
223 * @param string $post_type The post type. Default 'attachment'. |
295 * @param string $post_type The post type. Default 'attachment'. |
224 */ |
296 */ |
225 $taxonomies = apply_filters( 'manage_taxonomies_for_attachment_columns', $taxonomies, 'attachment' ); |
297 $taxonomies = apply_filters( 'manage_taxonomies_for_attachment_columns', $taxonomies, 'attachment' ); |
226 $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' ); |
298 $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' ); |
227 |
299 |
228 foreach ( $taxonomies as $taxonomy ) { |
300 foreach ( $taxonomies as $taxonomy ) { |
229 if ( 'category' == $taxonomy ) |
301 if ( 'category' === $taxonomy ) { |
230 $column_key = 'categories'; |
302 $column_key = 'categories'; |
231 elseif ( 'post_tag' == $taxonomy ) |
303 } elseif ( 'post_tag' === $taxonomy ) { |
232 $column_key = 'tags'; |
304 $column_key = 'tags'; |
233 else |
305 } else { |
234 $column_key = 'taxonomy-' . $taxonomy; |
306 $column_key = 'taxonomy-' . $taxonomy; |
235 |
307 } |
236 $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name; |
308 $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name; |
237 } |
309 } |
238 |
310 |
239 /* translators: column name */ |
311 /* translators: column name */ |
240 if ( !$this->detached ) { |
312 if ( !$this->detached ) { |
241 $posts_columns['parent'] = _x( 'Uploaded to', 'column name' ); |
313 $posts_columns['parent'] = _x( 'Uploaded to', 'column name' ); |
242 if ( post_type_supports( 'attachment', 'comments' ) ) |
314 if ( post_type_supports( 'attachment', 'comments' ) ) |
243 $posts_columns['comments'] = '<span class="vers"><span title="' . esc_attr__( 'Comments' ) . '" class="comment-grey-bubble"></span></span>'; |
315 $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>'; |
244 } |
316 } |
245 /* translators: column name */ |
317 /* translators: column name */ |
246 $posts_columns['date'] = _x( 'Date', 'column name' ); |
318 $posts_columns['date'] = _x( 'Date', 'column name' ); |
247 /** |
319 /** |
248 * Filter the Media list table columns. |
320 * Filters the Media list table columns. |
249 * |
321 * |
250 * @since 2.5.0 |
322 * @since 2.5.0 |
251 * |
323 * |
252 * @param array $posts_columns An array of columns displayed in the Media list table. |
324 * @param array $posts_columns An array of columns displayed in the Media list table. |
253 * @param bool $detached Whether the list table contains media not attached |
325 * @param bool $detached Whether the list table contains media not attached |
254 * to any posts. Default true. |
326 * to any posts. Default true. |
255 */ |
327 */ |
256 $posts_columns = apply_filters( 'manage_media_columns', $posts_columns, $this->detached ); |
328 return apply_filters( 'manage_media_columns', $posts_columns, $this->detached ); |
257 |
329 } |
258 return $posts_columns; |
330 |
259 } |
331 /** |
260 |
332 * |
|
333 * @return array |
|
334 */ |
261 protected function get_sortable_columns() { |
335 protected function get_sortable_columns() { |
262 return array( |
336 return array( |
263 'title' => 'title', |
337 'title' => 'title', |
264 'author' => 'author', |
338 'author' => 'author', |
265 'parent' => 'parent', |
339 'parent' => 'parent', |
266 'comments' => 'comment_count', |
340 'comments' => 'comment_count', |
267 'date' => array( 'date', true ), |
341 'date' => array( 'date', true ), |
268 ); |
342 ); |
269 } |
343 } |
270 |
344 |
271 public function display_rows() { |
345 /** |
272 global $post; |
346 * Handles the checkbox column output. |
273 |
347 * |
274 add_filter( 'the_title','esc_html' ); |
348 * @since 4.3.0 |
275 |
349 * |
276 while ( have_posts() ) : the_post(); |
350 * @param WP_Post $post The current WP_Post object. |
277 $user_can_edit = current_user_can( 'edit_post', $post->ID ); |
351 */ |
278 |
352 public function column_cb( $post ) { |
279 if ( $this->is_trash && $post->post_status != 'trash' |
353 if ( current_user_can( 'edit_post', $post->ID ) ) { ?> |
280 || !$this->is_trash && $post->post_status == 'trash' ) |
354 <label class="screen-reader-text" for="cb-select-<?php echo $post->ID; ?>"><?php |
281 continue; |
355 echo sprintf( __( 'Select %s' ), _draft_or_post_title() ); |
282 |
356 ?></label> |
283 $post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other'; |
357 <input type="checkbox" name="media[]" id="cb-select-<?php echo $post->ID; ?>" value="<?php echo $post->ID; ?>" /> |
284 $att_title = _draft_or_post_title(); |
358 <?php } |
285 ?> |
359 } |
286 <tr id="post-<?php echo $post->ID; ?>" class="<?php echo trim( ' author-' . $post_owner . ' status-' . $post->post_status ); ?>"> |
360 |
287 <?php |
361 /** |
288 |
362 * Handles the title column output. |
289 list( $columns, $hidden ) = $this->get_column_info(); |
363 * |
290 foreach ( $columns as $column_name => $column_display_name ) { |
364 * @since 4.3.0 |
291 $class = "class='$column_name column-$column_name'"; |
365 * |
292 |
366 * @param WP_Post $post The current WP_Post object. |
293 $style = ''; |
367 */ |
294 if ( in_array( $column_name, $hidden ) ) |
368 public function column_title( $post ) { |
295 $style = ' style="display:none;"'; |
|
296 |
|
297 $attributes = $class . $style; |
|
298 |
|
299 switch ( $column_name ) { |
|
300 |
|
301 case 'cb': |
|
302 ?> |
|
303 <th scope="row" class="check-column"> |
|
304 <?php if ( $user_can_edit ) { ?> |
|
305 <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php echo sprintf( __( 'Select %s' ), $att_title );?></label> |
|
306 <input type="checkbox" name="media[]" id="cb-select-<?php the_ID(); ?>" value="<?php the_ID(); ?>" /> |
|
307 <?php } ?> |
|
308 </th> |
|
309 <?php |
|
310 break; |
|
311 |
|
312 case 'icon': |
|
313 list( $mime ) = explode( '/', $post->post_mime_type ); |
369 list( $mime ) = explode( '/', $post->post_mime_type ); |
314 $attributes = 'class="column-icon media-icon ' . $mime . '-icon"' . $style; |
370 |
315 ?> |
371 $title = _draft_or_post_title(); |
316 <td <?php echo $attributes ?>><?php |
372 $thumb = wp_get_attachment_image( $post->ID, array( 60, 60 ), true, array( 'alt' => '' ) ); |
317 if ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) { |
373 $link_start = $link_end = ''; |
318 if ( $this->is_trash || ! $user_can_edit ) { |
374 |
319 echo $thumb; |
375 if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) { |
320 } else { |
376 $link_start = sprintf( |
321 ?> |
377 '<a href="%s" aria-label="%s">', |
322 <a href="<?php echo get_edit_post_link( $post->ID ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ); ?>"> |
378 get_edit_post_link( $post->ID ), |
323 <?php echo $thumb; ?> |
379 /* translators: %s: attachment title */ |
324 </a> |
380 esc_attr( sprintf( __( '“%s” (Edit)' ), $title ) ) |
325 |
|
326 <?php } |
|
327 } |
|
328 ?> |
|
329 </td> |
|
330 <?php |
|
331 break; |
|
332 |
|
333 case 'title': |
|
334 ?> |
|
335 <td <?php echo $attributes ?>><strong> |
|
336 <?php if ( $this->is_trash || ! $user_can_edit ) { |
|
337 echo $att_title; |
|
338 } else { ?> |
|
339 <a href="<?php echo get_edit_post_link( $post->ID ); ?>" |
|
340 title="<?php echo esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ); ?>"> |
|
341 <?php echo $att_title; ?></a> |
|
342 <?php }; |
|
343 _media_states( $post ); ?></strong> |
|
344 <p class="filename"><?php echo wp_basename( $post->guid ); ?></p> |
|
345 <?php |
|
346 echo $this->row_actions( $this->_get_row_actions( $post, $att_title ) ); |
|
347 ?> |
|
348 </td> |
|
349 <?php |
|
350 break; |
|
351 |
|
352 case 'author': |
|
353 ?> |
|
354 <td <?php echo $attributes ?>><?php |
|
355 printf( '<a href="%s">%s</a>', |
|
356 esc_url( add_query_arg( array( 'author' => get_the_author_meta('ID') ), 'upload.php' ) ), |
|
357 get_the_author() |
|
358 ); |
381 ); |
359 ?></td> |
382 $link_end = '</a>'; |
360 <?php |
383 } |
361 break; |
384 |
362 |
385 $class = $thumb ? ' class="has-media-icon"' : ''; |
363 case 'desc': |
386 ?> |
364 ?> |
387 <strong<?php echo $class; ?>> |
365 <td <?php echo $attributes ?>><?php echo has_excerpt() ? $post->post_excerpt : ''; ?></td> |
388 <?php |
366 <?php |
389 echo $link_start; |
367 break; |
390 if ( $thumb ) : ?> |
368 |
391 <span class="media-icon <?php echo sanitize_html_class( $mime . '-icon' ); ?>"><?php echo $thumb; ?></span> |
369 case 'date': |
392 <?php endif; |
370 if ( '0000-00-00 00:00:00' == $post->post_date ) { |
393 echo $title . $link_end; |
|
394 _media_states( $post ); |
|
395 ?> |
|
396 </strong> |
|
397 <p class="filename"> |
|
398 <span class="screen-reader-text"><?php _e( 'File name:' ); ?> </span> |
|
399 <?php |
|
400 $file = get_attached_file( $post->ID ); |
|
401 echo esc_html( wp_basename( $file ) ); |
|
402 ?> |
|
403 </p> |
|
404 <?php |
|
405 } |
|
406 |
|
407 /** |
|
408 * Handles the author column output. |
|
409 * |
|
410 * @since 4.3.0 |
|
411 * |
|
412 * @param WP_Post $post The current WP_Post object. |
|
413 */ |
|
414 public function column_author( $post ) { |
|
415 printf( '<a href="%s">%s</a>', |
|
416 esc_url( add_query_arg( array( 'author' => get_the_author_meta('ID') ), 'upload.php' ) ), |
|
417 get_the_author() |
|
418 ); |
|
419 } |
|
420 |
|
421 /** |
|
422 * Handles the description column output. |
|
423 * |
|
424 * @since 4.3.0 |
|
425 * |
|
426 * @param WP_Post $post The current WP_Post object. |
|
427 */ |
|
428 public function column_desc( $post ) { |
|
429 echo has_excerpt() ? $post->post_excerpt : ''; |
|
430 } |
|
431 |
|
432 /** |
|
433 * Handles the date column output. |
|
434 * |
|
435 * @since 4.3.0 |
|
436 * |
|
437 * @param WP_Post $post The current WP_Post object. |
|
438 */ |
|
439 public function column_date( $post ) { |
|
440 if ( '0000-00-00 00:00:00' === $post->post_date ) { |
371 $h_time = __( 'Unpublished' ); |
441 $h_time = __( 'Unpublished' ); |
372 } else { |
442 } else { |
373 $m_time = $post->post_date; |
443 $m_time = $post->post_date; |
374 $time = get_post_time( 'G', true, $post, false ); |
444 $time = get_post_time( 'G', true, $post, false ); |
375 if ( ( abs( $t_diff = time() - $time ) ) < DAY_IN_SECONDS ) { |
445 if ( ( abs( $t_diff = time() - $time ) ) < DAY_IN_SECONDS ) { |
376 if ( $t_diff < 0 ) |
446 if ( $t_diff < 0 ) { |
377 $h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) ); |
447 $h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) ); |
378 else |
448 } else { |
379 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); |
449 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); |
|
450 } |
380 } else { |
451 } else { |
381 $h_time = mysql2date( __( 'Y/m/d' ), $m_time ); |
452 $h_time = mysql2date( __( 'Y/m/d' ), $m_time ); |
382 } |
453 } |
383 } |
454 } |
384 ?> |
455 |
385 <td <?php echo $attributes ?>><?php echo $h_time ?></td> |
456 echo $h_time; |
386 <?php |
457 } |
387 break; |
458 |
388 |
459 /** |
389 case 'parent': |
460 * Handles the parent column output. |
390 if ( $post->post_parent > 0 ) |
461 * |
|
462 * @since 4.3.0 |
|
463 * |
|
464 * @param WP_Post $post The current WP_Post object. |
|
465 */ |
|
466 public function column_parent( $post ) { |
|
467 $user_can_edit = current_user_can( 'edit_post', $post->ID ); |
|
468 |
|
469 if ( $post->post_parent > 0 ) { |
391 $parent = get_post( $post->post_parent ); |
470 $parent = get_post( $post->post_parent ); |
392 else |
471 } else { |
393 $parent = false; |
472 $parent = false; |
|
473 } |
394 |
474 |
395 if ( $parent ) { |
475 if ( $parent ) { |
396 $title = _draft_or_post_title( $post->post_parent ); |
476 $title = _draft_or_post_title( $post->post_parent ); |
397 $parent_type = get_post_type_object( $parent->post_type ); |
477 $parent_type = get_post_type_object( $parent->post_type ); |
|
478 |
|
479 if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $post->post_parent ) ) { |
398 ?> |
480 ?> |
399 <td <?php echo $attributes ?>><strong> |
481 <strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"> |
400 <?php if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $post->post_parent ) ) { ?> |
482 <?php echo $title ?></a></strong><?php |
401 <a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"> |
483 } elseif ( $parent_type && current_user_can( 'read_post', $post->post_parent ) ) { |
402 <?php echo $title ?></a><?php |
484 ?> |
403 } else { |
485 <strong><?php echo $title ?></strong><?php |
404 echo $title; |
486 } else { |
405 } ?></strong>, |
487 _e( '(Private post)' ); |
406 <?php echo get_the_time( __( 'Y/m/d' ) ); ?><br /> |
488 } |
407 <?php |
489 |
408 if ( $user_can_edit ): |
490 if ( $user_can_edit ): |
409 $detach_url = add_query_arg( array( |
491 $detach_url = add_query_arg( array( |
410 'parent_post_id' => $post->post_parent, |
492 'parent_post_id' => $post->post_parent, |
411 'media[]' => $post->ID, |
493 'media[]' => $post->ID, |
412 '_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] ) |
494 '_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] ) |
413 ), 'upload.php' ); ?> |
495 ), 'upload.php' ); |
414 <a class="hide-if-no-js detach-from-parent" href="<?php echo $detach_url ?>"><?php _e( 'Detach' ); ?></a> |
496 printf( |
415 <?php endif; ?> |
497 '<br /><a href="%s" class="hide-if-no-js detach-from-parent" aria-label="%s">%s</a>', |
416 </td> |
498 $detach_url, |
417 <?php |
499 /* translators: %s: title of the post the attachment is attached to */ |
|
500 esc_attr( sprintf( __( 'Detach from “%s”' ), $title ) ), |
|
501 __( 'Detach' ) |
|
502 ); |
|
503 endif; |
418 } else { |
504 } else { |
419 ?> |
505 _e( '(Unattached)' ); ?> |
420 <td <?php echo $attributes ?>><?php _e( '(Unattached)' ); ?><br /> |
506 <?php if ( $user_can_edit ) { |
421 <?php if ( $user_can_edit ) { ?> |
507 $title = _draft_or_post_title( $post->post_parent ); |
422 <a class="hide-if-no-js" |
508 printf( |
423 onclick="findPosts.open( 'media[]','<?php echo $post->ID ?>' ); return false;" |
509 '<br /><a href="#the-list" onclick="findPosts.open( \'media[]\', \'%s\' ); return false;" class="hide-if-no-js aria-button-if-js" aria-label="%s">%s</a>', |
424 href="#the-list"> |
510 $post->ID, |
425 <?php _e( 'Attach' ); ?></a> |
511 /* translators: %s: attachment title */ |
426 <?php } ?></td> |
512 esc_attr( sprintf( __( 'Attach “%s” to existing content' ), $title ) ), |
427 <?php |
513 __( 'Attach' ) |
428 } |
514 ); |
429 break; |
515 } |
430 |
516 } |
431 case 'comments': |
517 } |
432 $attributes = 'class="comments column-comments num"' . $style; |
518 |
433 ?> |
519 /** |
434 <td <?php echo $attributes ?>> |
520 * Handles the comments column output. |
435 <div class="post-com-count-wrapper"> |
521 * |
436 <?php |
522 * @since 4.3.0 |
437 $pending_comments = get_pending_comments_num( $post->ID ); |
523 * |
|
524 * @param WP_Post $post The current WP_Post object. |
|
525 */ |
|
526 public function column_comments( $post ) { |
|
527 echo '<div class="post-com-count-wrapper">'; |
|
528 |
|
529 if ( isset( $this->comment_pending_count[ $post->ID ] ) ) { |
|
530 $pending_comments = $this->comment_pending_count[ $post->ID ]; |
|
531 } else { |
|
532 $pending_comments = get_pending_comments_num( $post->ID ); |
|
533 } |
438 |
534 |
439 $this->comments_bubble( $post->ID, $pending_comments ); |
535 $this->comments_bubble( $post->ID, $pending_comments ); |
440 ?> |
536 |
441 </div> |
537 echo '</div>'; |
442 </td> |
538 } |
443 <?php |
539 |
444 break; |
540 /** |
445 |
541 * Handles output for the default column. |
446 default: |
542 * |
447 if ( 'categories' == $column_name ) |
543 * @since 4.3.0 |
|
544 * |
|
545 * @param WP_Post $post The current WP_Post object. |
|
546 * @param string $column_name Current column name. |
|
547 */ |
|
548 public function column_default( $post, $column_name ) { |
|
549 if ( 'categories' === $column_name ) { |
448 $taxonomy = 'category'; |
550 $taxonomy = 'category'; |
449 elseif ( 'tags' == $column_name ) |
551 } elseif ( 'tags' === $column_name ) { |
450 $taxonomy = 'post_tag'; |
552 $taxonomy = 'post_tag'; |
451 elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) |
553 } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) { |
452 $taxonomy = substr( $column_name, 9 ); |
554 $taxonomy = substr( $column_name, 9 ); |
453 else |
555 } else { |
454 $taxonomy = false; |
556 $taxonomy = false; |
|
557 } |
455 |
558 |
456 if ( $taxonomy ) { |
559 if ( $taxonomy ) { |
457 echo '<td ' . $attributes . '>'; |
560 $terms = get_the_terms( $post->ID, $taxonomy ); |
458 if ( $terms = get_the_terms( $post->ID, $taxonomy ) ) { |
561 if ( is_array( $terms ) ) { |
459 $out = array(); |
562 $out = array(); |
460 foreach ( $terms as $t ) { |
563 foreach ( $terms as $t ) { |
461 $posts_in_term_qv = array(); |
564 $posts_in_term_qv = array(); |
462 $posts_in_term_qv['taxonomy'] = $taxonomy; |
565 $posts_in_term_qv['taxonomy'] = $taxonomy; |
463 $posts_in_term_qv['term'] = $t->slug; |
566 $posts_in_term_qv['term'] = $t->slug; |
468 ); |
571 ); |
469 } |
572 } |
470 /* translators: used between list items, there is a space after the comma */ |
573 /* translators: used between list items, there is a space after the comma */ |
471 echo join( __( ', ' ), $out ); |
574 echo join( __( ', ' ), $out ); |
472 } else { |
575 } else { |
473 echo '—'; |
576 echo '<span aria-hidden="true">—</span><span class="screen-reader-text">' . get_taxonomy( $taxonomy )->labels->no_terms . '</span>'; |
474 } |
577 } |
475 echo '</td>'; |
578 |
476 break; |
579 return; |
477 } |
580 } |
478 ?> |
581 |
479 <td <?php echo $attributes ?>><?php |
582 /** |
480 /** |
583 * Fires for each custom column in the Media list table. |
481 * Fires for each custom column in the Media list table. |
584 * |
482 * |
585 * Custom columns are registered using the {@see 'manage_media_columns'} filter. |
483 * Custom columns are registered using the 'manage_media_columns' filter. |
586 * |
484 * |
587 * @since 2.5.0 |
485 * @since 2.5.0 |
588 * |
486 * |
589 * @param string $column_name Name of the custom column. |
487 * @param string $column_name Name of the custom column. |
590 * @param int $post_id Attachment ID. |
488 * @param int $post_id Attachment ID. |
591 */ |
489 */ |
592 do_action( 'manage_media_custom_column', $column_name, $post->ID ); |
490 do_action( 'manage_media_custom_column', $column_name, $post->ID ); |
593 } |
491 ?></td> |
594 |
492 <?php |
595 /** |
493 break; |
596 * |
494 } |
597 * @global WP_Post $post |
495 } |
598 */ |
496 ?> |
599 public function display_rows() { |
497 </tr> |
600 global $post, $wp_query; |
498 <?php endwhile; |
601 |
|
602 $post_ids = wp_list_pluck( $wp_query->posts, 'ID' ); |
|
603 reset( $wp_query->posts ); |
|
604 |
|
605 $this->comment_pending_count = get_pending_comments_num( $post_ids ); |
|
606 |
|
607 add_filter( 'the_title','esc_html' ); |
|
608 |
|
609 while ( have_posts() ) : the_post(); |
|
610 if ( |
|
611 ( $this->is_trash && $post->post_status != 'trash' ) |
|
612 || ( ! $this->is_trash && $post->post_status === 'trash' ) |
|
613 ) { |
|
614 continue; |
|
615 } |
|
616 $post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other'; |
|
617 ?> |
|
618 <tr id="post-<?php echo $post->ID; ?>" class="<?php echo trim( ' author-' . $post_owner . ' status-' . $post->post_status ); ?>"> |
|
619 <?php $this->single_row_columns( $post ); ?> |
|
620 </tr> |
|
621 <?php |
|
622 endwhile; |
|
623 } |
|
624 |
|
625 /** |
|
626 * Gets the name of the default primary column. |
|
627 * |
|
628 * @since 4.3.0 |
|
629 * |
|
630 * @return string Name of the default primary column, in this case, 'title'. |
|
631 */ |
|
632 protected function get_default_primary_column_name() { |
|
633 return 'title'; |
499 } |
634 } |
500 |
635 |
501 /** |
636 /** |
502 * @param WP_Post $post |
637 * @param WP_Post $post |
503 * @param string $att_title |
638 * @param string $att_title |
|
639 * |
|
640 * @return array |
504 */ |
641 */ |
505 private function _get_row_actions( $post, $att_title ) { |
642 private function _get_row_actions( $post, $att_title ) { |
506 $actions = array(); |
643 $actions = array(); |
507 |
644 |
508 if ( $this->detached ) { |
645 if ( $this->detached ) { |
509 if ( current_user_can( 'edit_post', $post->ID ) ) |
646 if ( current_user_can( 'edit_post', $post->ID ) ) { |
510 $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID ) . '">' . __( 'Edit' ) . '</a>'; |
647 $actions['edit'] = sprintf( |
511 if ( current_user_can( 'delete_post', $post->ID ) ) |
648 '<a href="%s" aria-label="%s">%s</a>', |
|
649 get_edit_post_link( $post->ID ), |
|
650 /* translators: %s: attachment title */ |
|
651 esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ), |
|
652 __( 'Edit' ) |
|
653 ); |
|
654 } |
|
655 if ( current_user_can( 'delete_post', $post->ID ) ) { |
512 if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) { |
656 if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) { |
513 $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-post_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>"; |
657 $actions['trash'] = sprintf( |
|
658 '<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>', |
|
659 wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-post_' . $post->ID ), |
|
660 /* translators: %s: attachment title */ |
|
661 esc_attr( sprintf( __( 'Move “%s” to the Trash' ), $att_title ) ), |
|
662 _x( 'Trash', 'verb' ) |
|
663 ); |
514 } else { |
664 } else { |
515 $delete_ays = !MEDIA_TRASH ? " onclick='return showNotice.warn();'" : ''; |
665 $delete_ays = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : ''; |
516 $actions['delete'] = "<a class='submitdelete'$delete_ays href='" . wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID ) . "'>" . __( 'Delete Permanently' ) . "</a>"; |
666 $actions['delete'] = sprintf( |
|
667 '<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>', |
|
668 wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID ), |
|
669 $delete_ays, |
|
670 /* translators: %s: attachment title */ |
|
671 esc_attr( sprintf( __( 'Delete “%s” permanently' ), $att_title ) ), |
|
672 __( 'Delete Permanently' ) |
|
673 ); |
517 } |
674 } |
518 $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>'; |
675 } |
519 if ( current_user_can( 'edit_post', $post->ID ) ) |
676 $actions['view'] = sprintf( |
520 $actions['attach'] = '<a href="#the-list" onclick="findPosts.open( \'media[]\',\''.$post->ID.'\' );return false;" class="hide-if-no-js">'.__( 'Attach' ).'</a>'; |
677 '<a href="%s" aria-label="%s" rel="bookmark">%s</a>', |
|
678 get_permalink( $post->ID ), |
|
679 /* translators: %s: attachment title */ |
|
680 esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ), |
|
681 __( 'View' ) |
|
682 ); |
|
683 |
|
684 if ( current_user_can( 'edit_post', $post->ID ) ) { |
|
685 $actions['attach'] = sprintf( |
|
686 '<a href="#the-list" onclick="findPosts.open( \'media[]\', \'%s\' ); return false;" class="hide-if-no-js aria-button-if-js" aria-label="%s">%s</a>', |
|
687 $post->ID, |
|
688 /* translators: %s: attachment title */ |
|
689 esc_attr( sprintf( __( 'Attach “%s” to existing content' ), $att_title ) ), |
|
690 __( 'Attach' ) |
|
691 ); |
|
692 } |
521 } |
693 } |
522 else { |
694 else { |
523 if ( current_user_can( 'edit_post', $post->ID ) && !$this->is_trash ) |
695 if ( current_user_can( 'edit_post', $post->ID ) && !$this->is_trash ) { |
524 $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID ) . '">' . __( 'Edit' ) . '</a>'; |
696 $actions['edit'] = sprintf( |
|
697 '<a href="%s" aria-label="%s">%s</a>', |
|
698 get_edit_post_link( $post->ID ), |
|
699 /* translators: %s: attachment title */ |
|
700 esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ), |
|
701 __( 'Edit' ) |
|
702 ); |
|
703 } |
525 if ( current_user_can( 'delete_post', $post->ID ) ) { |
704 if ( current_user_can( 'delete_post', $post->ID ) ) { |
526 if ( $this->is_trash ) |
705 if ( $this->is_trash ) { |
527 $actions['untrash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=untrash&post=$post->ID", 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>"; |
706 $actions['untrash'] = sprintf( |
528 elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) |
707 '<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>', |
529 $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-post_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>"; |
708 wp_nonce_url( "post.php?action=untrash&post=$post->ID", 'untrash-post_' . $post->ID ), |
530 if ( $this->is_trash || !EMPTY_TRASH_DAYS || !MEDIA_TRASH ) { |
709 /* translators: %s: attachment title */ |
|
710 esc_attr( sprintf( __( 'Restore “%s” from the Trash' ), $att_title ) ), |
|
711 __( 'Restore' ) |
|
712 ); |
|
713 } elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) { |
|
714 $actions['trash'] = sprintf( |
|
715 '<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>', |
|
716 wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-post_' . $post->ID ), |
|
717 /* translators: %s: attachment title */ |
|
718 esc_attr( sprintf( __( 'Move “%s” to the Trash' ), $att_title ) ), |
|
719 _x( 'Trash', 'verb' ) |
|
720 ); |
|
721 } |
|
722 if ( $this->is_trash || ! EMPTY_TRASH_DAYS || ! MEDIA_TRASH ) { |
531 $delete_ays = ( !$this->is_trash && !MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : ''; |
723 $delete_ays = ( !$this->is_trash && !MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : ''; |
532 $actions['delete'] = "<a class='submitdelete'$delete_ays href='" . wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID ) . "'>" . __( 'Delete Permanently' ) . "</a>"; |
724 $actions['delete'] = sprintf( |
|
725 '<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>', |
|
726 wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID ), |
|
727 $delete_ays, |
|
728 /* translators: %s: attachment title */ |
|
729 esc_attr( sprintf( __( 'Delete “%s” permanently' ), $att_title ) ), |
|
730 __( 'Delete Permanently' ) |
|
731 ); |
533 } |
732 } |
534 } |
733 } |
535 if ( !$this->is_trash ) { |
734 if ( ! $this->is_trash ) { |
536 $title =_draft_or_post_title( $post->post_parent ); |
735 $actions['view'] = sprintf( |
537 $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>'; |
736 '<a href="%s" aria-label="%s" rel="bookmark">%s</a>', |
|
737 get_permalink( $post->ID ), |
|
738 /* translators: %s: attachment title */ |
|
739 esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ), |
|
740 __( 'View' ) |
|
741 ); |
538 } |
742 } |
539 } |
743 } |
540 |
744 |
541 /** |
745 /** |
542 * Filter the action links for each attachment in the Media list table. |
746 * Filters the action links for each attachment in the Media list table. |
543 * |
747 * |
544 * @since 2.8.0 |
748 * @since 2.8.0 |
545 * |
749 * |
546 * @param array $actions An array of action links for each attachment. |
750 * @param array $actions An array of action links for each attachment. |
547 * Default 'Edit', 'Delete Permanently', 'View'. |
751 * Default 'Edit', 'Delete Permanently', 'View'. |
548 * @param WP_Post $post WP_Post object for the current attachment. |
752 * @param WP_Post $post WP_Post object for the current attachment. |
549 * @param bool $detached Whether the list table contains media not attached |
753 * @param bool $detached Whether the list table contains media not attached |
550 * to any posts. Default true. |
754 * to any posts. Default true. |
551 */ |
755 */ |
552 $actions = apply_filters( 'media_row_actions', $actions, $post, $this->detached ); |
756 return apply_filters( 'media_row_actions', $actions, $post, $this->detached ); |
553 |
757 } |
554 return $actions; |
758 |
|
759 /** |
|
760 * Generates and displays row action links. |
|
761 * |
|
762 * @since 4.3.0 |
|
763 * |
|
764 * @param object $post Attachment being acted upon. |
|
765 * @param string $column_name Current column name. |
|
766 * @param string $primary Primary column name. |
|
767 * @return string Row actions output for media attachments. |
|
768 */ |
|
769 protected function handle_row_actions( $post, $column_name, $primary ) { |
|
770 if ( $primary !== $column_name ) { |
|
771 return ''; |
|
772 } |
|
773 |
|
774 $att_title = _draft_or_post_title(); |
|
775 return $this->row_actions( $this->_get_row_actions( $post, $att_title ) ); |
555 } |
776 } |
556 } |
777 } |