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