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