[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

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


Generated : Thu Sep 24 08:20:02 2020 Cross-referenced by PHPXref