[ 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 * @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 354 if ( post_type_supports( 'attachment', 'comments' ) ) { 355 $posts_columns['comments'] = sprintf( 356 '<span class="vers comment-grey-bubble" title="%1$s" aria-hidden="true"></span><span class="screen-reader-text">%2$s</span>', 357 esc_attr__( 'Comments' ), 358 __( 'Comments' ) 359 ); 360 } 361 } 362 363 /* translators: Column name. */ 364 $posts_columns['date'] = _x( 'Date', 'column name' ); 365 366 /** 367 * Filters the Media list table columns. 368 * 369 * @since 2.5.0 370 * 371 * @param string[] $posts_columns An array of columns displayed in the Media list table. 372 * @param bool $detached Whether the list table contains media not attached 373 * to any posts. Default true. 374 */ 375 return apply_filters( 'manage_media_columns', $posts_columns, $this->detached ); 376 } 377 378 /** 379 * @return array 380 */ 381 protected function get_sortable_columns() { 382 return array( 383 'title' => 'title', 384 'author' => 'author', 385 'parent' => 'parent', 386 'comments' => 'comment_count', 387 'date' => array( 'date', true ), 388 ); 389 } 390 391 /** 392 * Handles the checkbox column output. 393 * 394 * @since 4.3.0 395 * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support. 396 * 397 * @param WP_Post $item The current WP_Post object. 398 */ 399 public function column_cb( $item ) { 400 // Restores the more descriptive, specific name for use within this method. 401 $post = $item; 402 403 if ( current_user_can( 'edit_post', $post->ID ) ) { 404 ?> 405 <label class="screen-reader-text" for="cb-select-<?php echo $post->ID; ?>"> 406 <?php 407 /* translators: %s: Attachment title. */ 408 printf( __( 'Select %s' ), _draft_or_post_title() ); 409 ?> 410 </label> 411 <input type="checkbox" name="media[]" id="cb-select-<?php echo $post->ID; ?>" value="<?php echo $post->ID; ?>" /> 412 <?php 413 } 414 } 415 416 /** 417 * Handles the title column output. 418 * 419 * @since 4.3.0 420 * 421 * @param WP_Post $post The current WP_Post object. 422 */ 423 public function column_title( $post ) { 424 list( $mime ) = explode( '/', $post->post_mime_type ); 425 426 $title = _draft_or_post_title(); 427 $thumb = wp_get_attachment_image( $post->ID, array( 60, 60 ), true, array( 'alt' => '' ) ); 428 $link_start = ''; 429 $link_end = ''; 430 431 if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) { 432 $link_start = sprintf( 433 '<a href="%s" aria-label="%s">', 434 get_edit_post_link( $post->ID ), 435 /* translators: %s: Attachment title. */ 436 esc_attr( sprintf( __( '“%s” (Edit)' ), $title ) ) 437 ); 438 $link_end = '</a>'; 439 } 440 441 $class = $thumb ? ' class="has-media-icon"' : ''; 442 ?> 443 <strong<?php echo $class; ?>> 444 <?php 445 echo $link_start; 446 447 if ( $thumb ) : 448 ?> 449 <span class="media-icon <?php echo sanitize_html_class( $mime . '-icon' ); ?>"><?php echo $thumb; ?></span> 450 <?php 451 endif; 452 453 echo $title . $link_end; 454 455 _media_states( $post ); 456 ?> 457 </strong> 458 <p class="filename"> 459 <span class="screen-reader-text"><?php _e( 'File name:' ); ?> </span> 460 <?php 461 $file = get_attached_file( $post->ID ); 462 echo esc_html( wp_basename( $file ) ); 463 ?> 464 </p> 465 <?php 466 } 467 468 /** 469 * Handles the author column output. 470 * 471 * @since 4.3.0 472 * 473 * @param WP_Post $post The current WP_Post object. 474 */ 475 public function column_author( $post ) { 476 printf( 477 '<a href="%s">%s</a>', 478 esc_url( add_query_arg( array( 'author' => get_the_author_meta( 'ID' ) ), 'upload.php' ) ), 479 get_the_author() 480 ); 481 } 482 483 /** 484 * Handles the description column output. 485 * 486 * @since 4.3.0 487 * 488 * @param WP_Post $post The current WP_Post object. 489 */ 490 public function column_desc( $post ) { 491 echo has_excerpt() ? $post->post_excerpt : ''; 492 } 493 494 /** 495 * Handles the date column output. 496 * 497 * @since 4.3.0 498 * 499 * @param WP_Post $post The current WP_Post object. 500 */ 501 public function column_date( $post ) { 502 if ( '0000-00-00 00:00:00' === $post->post_date ) { 503 $h_time = __( 'Unpublished' ); 504 } else { 505 $time = get_post_timestamp( $post ); 506 $time_diff = time() - $time; 507 508 if ( $time && $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) { 509 /* translators: %s: Human-readable time difference. */ 510 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); 511 } else { 512 $h_time = get_the_time( __( 'Y/m/d' ), $post ); 513 } 514 } 515 516 /** 517 * Filters the published time of an attachment displayed in the Media list table. 518 * 519 * @since 6.0.0 520 * 521 * @param string $h_time The published time. 522 * @param WP_Post $post Attachment object. 523 * @param string $column_name The column name. 524 */ 525 echo apply_filters( 'media_date_column_time', $h_time, $post, 'date' ); 526 } 527 528 /** 529 * Handles the parent column output. 530 * 531 * @since 4.3.0 532 * 533 * @param WP_Post $post The current WP_Post object. 534 */ 535 public function column_parent( $post ) { 536 $user_can_edit = current_user_can( 'edit_post', $post->ID ); 537 538 if ( $post->post_parent > 0 ) { 539 $parent = get_post( $post->post_parent ); 540 } else { 541 $parent = false; 542 } 543 544 if ( $parent ) { 545 $title = _draft_or_post_title( $post->post_parent ); 546 $parent_type = get_post_type_object( $parent->post_type ); 547 548 if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $post->post_parent ) ) { 549 printf( '<strong><a href="%s">%s</a></strong>', get_edit_post_link( $post->post_parent ), $title ); 550 } elseif ( $parent_type && current_user_can( 'read_post', $post->post_parent ) ) { 551 printf( '<strong>%s</strong>', $title ); 552 } else { 553 _e( '(Private post)' ); 554 } 555 556 if ( $user_can_edit ) : 557 $detach_url = add_query_arg( 558 array( 559 'parent_post_id' => $post->post_parent, 560 'media[]' => $post->ID, 561 '_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] ), 562 ), 563 'upload.php' 564 ); 565 printf( 566 '<br /><a href="%s" class="hide-if-no-js detach-from-parent" aria-label="%s">%s</a>', 567 $detach_url, 568 /* translators: %s: Title of the post the attachment is attached to. */ 569 esc_attr( sprintf( __( 'Detach from “%s”' ), $title ) ), 570 __( 'Detach' ) 571 ); 572 endif; 573 } else { 574 _e( '(Unattached)' ); 575 ?> 576 <?php 577 if ( $user_can_edit ) { 578 $title = _draft_or_post_title( $post->post_parent ); 579 printf( 580 '<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>', 581 $post->ID, 582 /* translators: %s: Attachment title. */ 583 esc_attr( sprintf( __( 'Attach “%s” to existing content' ), $title ) ), 584 __( 'Attach' ) 585 ); 586 } 587 } 588 } 589 590 /** 591 * Handles the comments column output. 592 * 593 * @since 4.3.0 594 * 595 * @param WP_Post $post The current WP_Post object. 596 */ 597 public function column_comments( $post ) { 598 echo '<div class="post-com-count-wrapper">'; 599 600 if ( isset( $this->comment_pending_count[ $post->ID ] ) ) { 601 $pending_comments = $this->comment_pending_count[ $post->ID ]; 602 } else { 603 $pending_comments = get_pending_comments_num( $post->ID ); 604 } 605 606 $this->comments_bubble( $post->ID, $pending_comments ); 607 608 echo '</div>'; 609 } 610 611 /** 612 * Handles output for the default column. 613 * 614 * @since 4.3.0 615 * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support. 616 * 617 * @param WP_Post $item The current WP_Post object. 618 * @param string $column_name Current column name. 619 */ 620 public function column_default( $item, $column_name ) { 621 // Restores the more descriptive, specific name for use within this method. 622 $post = $item; 623 624 if ( 'categories' === $column_name ) { 625 $taxonomy = 'category'; 626 } elseif ( 'tags' === $column_name ) { 627 $taxonomy = 'post_tag'; 628 } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) { 629 $taxonomy = substr( $column_name, 9 ); 630 } else { 631 $taxonomy = false; 632 } 633 634 if ( $taxonomy ) { 635 $terms = get_the_terms( $post->ID, $taxonomy ); 636 637 if ( is_array( $terms ) ) { 638 $out = array(); 639 foreach ( $terms as $t ) { 640 $posts_in_term_qv = array(); 641 $posts_in_term_qv['taxonomy'] = $taxonomy; 642 $posts_in_term_qv['term'] = $t->slug; 643 644 $out[] = sprintf( 645 '<a href="%s">%s</a>', 646 esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ), 647 esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) ) 648 ); 649 } 650 echo implode( wp_get_list_item_separator(), $out ); 651 } else { 652 echo '<span aria-hidden="true">—</span><span class="screen-reader-text">' . get_taxonomy( $taxonomy )->labels->no_terms . '</span>'; 653 } 654 655 return; 656 } 657 658 /** 659 * Fires for each custom column in the Media list table. 660 * 661 * Custom columns are registered using the {@see 'manage_media_columns'} filter. 662 * 663 * @since 2.5.0 664 * 665 * @param string $column_name Name of the custom column. 666 * @param int $post_id Attachment ID. 667 */ 668 do_action( 'manage_media_custom_column', $column_name, $post->ID ); 669 } 670 671 /** 672 * @global WP_Post $post Global post object. 673 */ 674 public function display_rows() { 675 global $post, $wp_query; 676 677 $post_ids = wp_list_pluck( $wp_query->posts, 'ID' ); 678 reset( $wp_query->posts ); 679 680 $this->comment_pending_count = get_pending_comments_num( $post_ids ); 681 682 add_filter( 'the_title', 'esc_html' ); 683 684 while ( have_posts() ) : 685 the_post(); 686 687 if ( $this->is_trash && 'trash' !== $post->post_status 688 || ! $this->is_trash && 'trash' === $post->post_status 689 ) { 690 continue; 691 } 692 693 $post_owner = ( get_current_user_id() === (int) $post->post_author ) ? 'self' : 'other'; 694 ?> 695 <tr id="post-<?php echo $post->ID; ?>" class="<?php echo trim( ' author-' . $post_owner . ' status-' . $post->post_status ); ?>"> 696 <?php $this->single_row_columns( $post ); ?> 697 </tr> 698 <?php 699 endwhile; 700 } 701 702 /** 703 * Gets the name of the default primary column. 704 * 705 * @since 4.3.0 706 * 707 * @return string Name of the default primary column, in this case, 'title'. 708 */ 709 protected function get_default_primary_column_name() { 710 return 'title'; 711 } 712 713 /** 714 * @param WP_Post $post 715 * @param string $att_title 716 * @return array 717 */ 718 private function _get_row_actions( $post, $att_title ) { 719 $actions = array(); 720 721 if ( $this->detached ) { 722 if ( current_user_can( 'edit_post', $post->ID ) ) { 723 $actions['edit'] = sprintf( 724 '<a href="%s" aria-label="%s">%s</a>', 725 get_edit_post_link( $post->ID ), 726 /* translators: %s: Attachment title. */ 727 esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ), 728 __( 'Edit' ) 729 ); 730 } 731 732 if ( current_user_can( 'delete_post', $post->ID ) ) { 733 if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) { 734 $actions['trash'] = sprintf( 735 '<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>', 736 wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-post_' . $post->ID ), 737 /* translators: %s: Attachment title. */ 738 esc_attr( sprintf( __( 'Move “%s” to the Trash' ), $att_title ) ), 739 _x( 'Trash', 'verb' ) 740 ); 741 } else { 742 $delete_ays = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : ''; 743 $actions['delete'] = sprintf( 744 '<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>', 745 wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID ), 746 $delete_ays, 747 /* translators: %s: Attachment title. */ 748 esc_attr( sprintf( __( 'Delete “%s” permanently' ), $att_title ) ), 749 __( 'Delete Permanently' ) 750 ); 751 } 752 } 753 754 $actions['view'] = sprintf( 755 '<a href="%s" aria-label="%s" rel="bookmark">%s</a>', 756 get_permalink( $post->ID ), 757 /* translators: %s: Attachment title. */ 758 esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ), 759 __( 'View' ) 760 ); 761 762 if ( current_user_can( 'edit_post', $post->ID ) ) { 763 $actions['attach'] = sprintf( 764 '<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>', 765 $post->ID, 766 /* translators: %s: Attachment title. */ 767 esc_attr( sprintf( __( 'Attach “%s” to existing content' ), $att_title ) ), 768 __( 'Attach' ) 769 ); 770 } 771 } else { 772 if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) { 773 $actions['edit'] = sprintf( 774 '<a href="%s" aria-label="%s">%s</a>', 775 get_edit_post_link( $post->ID ), 776 /* translators: %s: Attachment title. */ 777 esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ), 778 __( 'Edit' ) 779 ); 780 } 781 782 if ( current_user_can( 'delete_post', $post->ID ) ) { 783 if ( $this->is_trash ) { 784 $actions['untrash'] = sprintf( 785 '<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>', 786 wp_nonce_url( "post.php?action=untrash&post=$post->ID", 'untrash-post_' . $post->ID ), 787 /* translators: %s: Attachment title. */ 788 esc_attr( sprintf( __( 'Restore “%s” from the Trash' ), $att_title ) ), 789 __( 'Restore' ) 790 ); 791 } elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) { 792 $actions['trash'] = sprintf( 793 '<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>', 794 wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-post_' . $post->ID ), 795 /* translators: %s: Attachment title. */ 796 esc_attr( sprintf( __( 'Move “%s” to the Trash' ), $att_title ) ), 797 _x( 'Trash', 'verb' ) 798 ); 799 } 800 801 if ( $this->is_trash || ! EMPTY_TRASH_DAYS || ! MEDIA_TRASH ) { 802 $delete_ays = ( ! $this->is_trash && ! MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : ''; 803 $actions['delete'] = sprintf( 804 '<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>', 805 wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID ), 806 $delete_ays, 807 /* translators: %s: Attachment title. */ 808 esc_attr( sprintf( __( 'Delete “%s” permanently' ), $att_title ) ), 809 __( 'Delete Permanently' ) 810 ); 811 } 812 } 813 814 if ( ! $this->is_trash ) { 815 $actions['view'] = sprintf( 816 '<a href="%s" aria-label="%s" rel="bookmark">%s</a>', 817 get_permalink( $post->ID ), 818 /* translators: %s: Attachment title. */ 819 esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ), 820 __( 'View' ) 821 ); 822 823 $actions['copy'] = sprintf( 824 '<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>', 825 esc_url( wp_get_attachment_url( $post->ID ) ), 826 /* translators: %s: Attachment title. */ 827 esc_attr( sprintf( __( 'Copy “%s” URL to clipboard' ), $att_title ) ), 828 __( 'Copy URL to clipboard' ), 829 __( 'Copied!' ) 830 ); 831 } 832 } 833 834 /** 835 * Filters the action links for each attachment in the Media list table. 836 * 837 * @since 2.8.0 838 * 839 * @param string[] $actions An array of action links for each attachment. 840 * Default 'Edit', 'Delete Permanently', 'View'. 841 * @param WP_Post $post WP_Post object for the current attachment. 842 * @param bool $detached Whether the list table contains media not attached 843 * to any posts. Default true. 844 */ 845 return apply_filters( 'media_row_actions', $actions, $post, $this->detached ); 846 } 847 848 /** 849 * Generates and displays row action links. 850 * 851 * @since 4.3.0 852 * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support. 853 * 854 * @param WP_Post $item Attachment being acted upon. 855 * @param string $column_name Current column name. 856 * @param string $primary Primary column name. 857 * @return string Row actions output for media attachments, or an empty string 858 * if the current column is not the primary column. 859 */ 860 protected function handle_row_actions( $item, $column_name, $primary ) { 861 if ( $primary !== $column_name ) { 862 return ''; 863 } 864 865 $att_title = _draft_or_post_title(); 866 $actions = $this->_get_row_actions( 867 $item, // WP_Post object for an attachment. 868 $att_title 869 ); 870 871 return $this->row_actions( $actions ); 872 } 873 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Fri Aug 19 08:20:02 2022 | Cross-referenced by PHPXref |