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