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