[ Index ]

PHP Cross Reference of WordPress

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="screen-reader-text"><?php esc_html_e( 'Search Media' ); ?></label>
 274          <input type="search" placeholder="<?php esc_attr_e( 'Search media items...' ); ?>" id="media-search-input" class="search" name="s" value="<?php _admin_search_query(); ?>"></div>
 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              $m_time = $post->post_date;
 456              $time   = get_post_time( 'G', true, $post, false );
 457              $t_diff = time() - $time;
 458              if ( ( abs( $t_diff ) ) < DAY_IN_SECONDS ) {
 459                  if ( $t_diff < 0 ) {
 460                      /* translators: %s: Human-readable time difference. */
 461                      $h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) );
 462                  } else {
 463                      /* translators: %s: Human-readable time difference. */
 464                      $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
 465                  }
 466              } else {
 467                  $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
 468              }
 469          }
 470  
 471          echo $h_time;
 472      }
 473  
 474      /**
 475       * Handles the parent column output.
 476       *
 477       * @since 4.3.0
 478       *
 479       * @param WP_Post $post The current WP_Post object.
 480       */
 481  	public function column_parent( $post ) {
 482          $user_can_edit = current_user_can( 'edit_post', $post->ID );
 483  
 484          if ( $post->post_parent > 0 ) {
 485              $parent = get_post( $post->post_parent );
 486          } else {
 487              $parent = false;
 488          }
 489  
 490          if ( $parent ) {
 491              $title       = _draft_or_post_title( $post->post_parent );
 492              $parent_type = get_post_type_object( $parent->post_type );
 493  
 494              if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $post->post_parent ) ) {
 495                  ?>
 496                  <strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>">
 497                      <?php echo $title; ?></a></strong>
 498                                  <?php
 499              } elseif ( $parent_type && current_user_can( 'read_post', $post->post_parent ) ) {
 500                  ?>
 501                  <strong><?php echo $title; ?></strong>
 502                                      <?php
 503              } else {
 504                  _e( '(Private post)' );
 505              }
 506  
 507              if ( $user_can_edit ) :
 508                  $detach_url = add_query_arg(
 509                      array(
 510                          'parent_post_id' => $post->post_parent,
 511                          'media[]'        => $post->ID,
 512                          '_wpnonce'       => wp_create_nonce( 'bulk-' . $this->_args['plural'] ),
 513                      ),
 514                      'upload.php'
 515                  );
 516                  printf(
 517                      '<br /><a href="%s" class="hide-if-no-js detach-from-parent" aria-label="%s">%s</a>',
 518                      $detach_url,
 519                      /* translators: %s: Title of the post the attachment is attached to. */
 520                      esc_attr( sprintf( __( 'Detach from &#8220;%s&#8221;' ), $title ) ),
 521                      __( 'Detach' )
 522                  );
 523              endif;
 524          } else {
 525              _e( '(Unattached)' );
 526              ?>
 527              <?php
 528              if ( $user_can_edit ) {
 529                  $title = _draft_or_post_title( $post->post_parent );
 530                  printf(
 531                      '<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>',
 532                      $post->ID,
 533                      /* translators: %s: Attachment title. */
 534                      esc_attr( sprintf( __( 'Attach &#8220;%s&#8221; to existing content' ), $title ) ),
 535                      __( 'Attach' )
 536                  );
 537              }
 538          }
 539      }
 540  
 541      /**
 542       * Handles the comments column output.
 543       *
 544       * @since 4.3.0
 545       *
 546       * @param WP_Post $post The current WP_Post object.
 547       */
 548  	public function column_comments( $post ) {
 549          echo '<div class="post-com-count-wrapper">';
 550  
 551          if ( isset( $this->comment_pending_count[ $post->ID ] ) ) {
 552              $pending_comments = $this->comment_pending_count[ $post->ID ];
 553          } else {
 554              $pending_comments = get_pending_comments_num( $post->ID );
 555          }
 556  
 557          $this->comments_bubble( $post->ID, $pending_comments );
 558  
 559          echo '</div>';
 560      }
 561  
 562      /**
 563       * Handles output for the default column.
 564       *
 565       * @since 4.3.0
 566       *
 567       * @param WP_Post $post        The current WP_Post object.
 568       * @param string  $column_name Current column name.
 569       */
 570  	public function column_default( $post, $column_name ) {
 571          if ( 'categories' === $column_name ) {
 572              $taxonomy = 'category';
 573          } elseif ( 'tags' === $column_name ) {
 574              $taxonomy = 'post_tag';
 575          } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) {
 576              $taxonomy = substr( $column_name, 9 );
 577          } else {
 578              $taxonomy = false;
 579          }
 580  
 581          if ( $taxonomy ) {
 582              $terms = get_the_terms( $post->ID, $taxonomy );
 583              if ( is_array( $terms ) ) {
 584                  $out = array();
 585                  foreach ( $terms as $t ) {
 586                      $posts_in_term_qv             = array();
 587                      $posts_in_term_qv['taxonomy'] = $taxonomy;
 588                      $posts_in_term_qv['term']     = $t->slug;
 589  
 590                      $out[] = sprintf(
 591                          '<a href="%s">%s</a>',
 592                          esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ),
 593                          esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
 594                      );
 595                  }
 596                  /* translators: Used between list items, there is a space after the comma. */
 597                  echo join( __( ', ' ), $out );
 598              } else {
 599                  echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . get_taxonomy( $taxonomy )->labels->no_terms . '</span>';
 600              }
 601  
 602              return;
 603          }
 604  
 605          /**
 606           * Fires for each custom column in the Media list table.
 607           *
 608           * Custom columns are registered using the {@see 'manage_media_columns'} filter.
 609           *
 610           * @since 2.5.0
 611           *
 612           * @param string $column_name Name of the custom column.
 613           * @param int    $post_id     Attachment ID.
 614           */
 615          do_action( 'manage_media_custom_column', $column_name, $post->ID );
 616      }
 617  
 618      /**
 619       * @global WP_Post $post Global post object.
 620       */
 621  	public function display_rows() {
 622          global $post, $wp_query;
 623  
 624          $post_ids = wp_list_pluck( $wp_query->posts, 'ID' );
 625          reset( $wp_query->posts );
 626  
 627          $this->comment_pending_count = get_pending_comments_num( $post_ids );
 628  
 629          add_filter( 'the_title', 'esc_html' );
 630  
 631          while ( have_posts() ) :
 632              the_post();
 633              if (
 634                  ( $this->is_trash && $post->post_status != 'trash' )
 635                  || ( ! $this->is_trash && $post->post_status === 'trash' )
 636              ) {
 637                  continue;
 638              }
 639              $post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other';
 640              ?>
 641              <tr id="post-<?php echo $post->ID; ?>" class="<?php echo trim( ' author-' . $post_owner . ' status-' . $post->post_status ); ?>">
 642                  <?php $this->single_row_columns( $post ); ?>
 643              </tr>
 644              <?php
 645          endwhile;
 646      }
 647  
 648      /**
 649       * Gets the name of the default primary column.
 650       *
 651       * @since 4.3.0
 652       *
 653       * @return string Name of the default primary column, in this case, 'title'.
 654       */
 655  	protected function get_default_primary_column_name() {
 656          return 'title';
 657      }
 658  
 659      /**
 660       * @param WP_Post $post
 661       * @param string  $att_title
 662       *
 663       * @return array
 664       */
 665  	private function _get_row_actions( $post, $att_title ) {
 666          $actions = array();
 667  
 668          if ( $this->detached ) {
 669              if ( current_user_can( 'edit_post', $post->ID ) ) {
 670                  $actions['edit'] = sprintf(
 671                      '<a href="%s" aria-label="%s">%s</a>',
 672                      get_edit_post_link( $post->ID ),
 673                      /* translators: %s: Attachment title. */
 674                      esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ),
 675                      __( 'Edit' )
 676                  );
 677              }
 678              if ( current_user_can( 'delete_post', $post->ID ) ) {
 679                  if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
 680                      $actions['trash'] = sprintf(
 681                          '<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>',
 682                          wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID ),
 683                          /* translators: %s: Attachment title. */
 684                          esc_attr( sprintf( __( 'Move &#8220;%s&#8221; to the Trash' ), $att_title ) ),
 685                          _x( 'Trash', 'verb' )
 686                      );
 687                  } else {
 688                      $delete_ays        = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : '';
 689                      $actions['delete'] = sprintf(
 690                          '<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>',
 691                          wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID ),
 692                          $delete_ays,
 693                          /* translators: %s: Attachment title. */
 694                          esc_attr( sprintf( __( 'Delete &#8220;%s&#8221; permanently' ), $att_title ) ),
 695                          __( 'Delete Permanently' )
 696                      );
 697                  }
 698              }
 699              $actions['view'] = sprintf(
 700                  '<a href="%s" aria-label="%s" rel="bookmark">%s</a>',
 701                  get_permalink( $post->ID ),
 702                  /* translators: %s: Attachment title. */
 703                  esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ),
 704                  __( 'View' )
 705              );
 706  
 707              if ( current_user_can( 'edit_post', $post->ID ) ) {
 708                  $actions['attach'] = sprintf(
 709                      '<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>',
 710                      $post->ID,
 711                      /* translators: %s: Attachment title. */
 712                      esc_attr( sprintf( __( 'Attach &#8220;%s&#8221; to existing content' ), $att_title ) ),
 713                      __( 'Attach' )
 714                  );
 715              }
 716          } else {
 717              if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) {
 718                  $actions['edit'] = sprintf(
 719                      '<a href="%s" aria-label="%s">%s</a>',
 720                      get_edit_post_link( $post->ID ),
 721                      /* translators: %s: Attachment title. */
 722                      esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ),
 723                      __( 'Edit' )
 724                  );
 725              }
 726              if ( current_user_can( 'delete_post', $post->ID ) ) {
 727                  if ( $this->is_trash ) {
 728                      $actions['untrash'] = sprintf(
 729                          '<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>',
 730                          wp_nonce_url( "post.php?action=untrash&amp;post=$post->ID", 'untrash-post_' . $post->ID ),
 731                          /* translators: %s: Attachment title. */
 732                          esc_attr( sprintf( __( 'Restore &#8220;%s&#8221; from the Trash' ), $att_title ) ),
 733                          __( 'Restore' )
 734                      );
 735                  } elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
 736                      $actions['trash'] = sprintf(
 737                          '<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>',
 738                          wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID ),
 739                          /* translators: %s: Attachment title. */
 740                          esc_attr( sprintf( __( 'Move &#8220;%s&#8221; to the Trash' ), $att_title ) ),
 741                          _x( 'Trash', 'verb' )
 742                      );
 743                  }
 744                  if ( $this->is_trash || ! EMPTY_TRASH_DAYS || ! MEDIA_TRASH ) {
 745                      $delete_ays        = ( ! $this->is_trash && ! MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : '';
 746                      $actions['delete'] = sprintf(
 747                          '<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>',
 748                          wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID ),
 749                          $delete_ays,
 750                          /* translators: %s: Attachment title. */
 751                          esc_attr( sprintf( __( 'Delete &#8220;%s&#8221; permanently' ), $att_title ) ),
 752                          __( 'Delete Permanently' )
 753                      );
 754                  }
 755              }
 756              if ( ! $this->is_trash ) {
 757                  $actions['view'] = sprintf(
 758                      '<a href="%s" aria-label="%s" rel="bookmark">%s</a>',
 759                      get_permalink( $post->ID ),
 760                      /* translators: %s: Attachment title. */
 761                      esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ),
 762                      __( 'View' )
 763                  );
 764              }
 765          }
 766  
 767          /**
 768           * Filters the action links for each attachment in the Media list table.
 769           *
 770           * @since 2.8.0
 771           *
 772           * @param string[] $actions  An array of action links for each attachment.
 773           *                           Default 'Edit', 'Delete Permanently', 'View'.
 774           * @param WP_Post  $post     WP_Post object for the current attachment.
 775           * @param bool     $detached Whether the list table contains media not attached
 776           *                           to any posts. Default true.
 777           */
 778          return apply_filters( 'media_row_actions', $actions, $post, $this->detached );
 779      }
 780  
 781      /**
 782       * Generates and displays row action links.
 783       *
 784       * @since 4.3.0
 785       *
 786       * @param object $post        Attachment being acted upon.
 787       * @param string $column_name Current column name.
 788       * @param string $primary     Primary column name.
 789       * @return string Row actions output for media attachments.
 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          return $this->row_actions( $this->_get_row_actions( $post, $att_title ) );
 798      }
 799  }


Generated: Sat Sep 21 01:00:03 2019 Cross-referenced by PHPXref 0.7.1