[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/includes/ -> class-wp-media-list-table.php (source)

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


Generated : Wed Apr 1 08:20:01 2020 Cross-referenced by PHPXref