[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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


Generated: Sat Nov 23 20:47:33 2019 Cross-referenced by PHPXref 0.7