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


Generated: Tue Oct 26 01:00:02 2021 Cross-referenced by PHPXref 0.7.1