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


Generated: Sat Jul 4 01:00:03 2020 Cross-referenced by PHPXref 0.7.1