class-wp-posts-list-table.php (59711B)
1 <?php 2 /** 3 * List Table API: WP_Posts_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 posts in a list table. 12 * 13 * @since 3.1.0 14 * @access private 15 * 16 * @see WP_List_Table 17 */ 18 class WP_Posts_List_Table extends WP_List_Table { 19 20 /** 21 * Whether the items should be displayed hierarchically or linearly. 22 * 23 * @since 3.1.0 24 * @var bool 25 */ 26 protected $hierarchical_display; 27 28 /** 29 * Holds the number of pending comments for each post. 30 * 31 * @since 3.1.0 32 * @var array 33 */ 34 protected $comment_pending_count; 35 36 /** 37 * Holds the number of posts for this user. 38 * 39 * @since 3.1.0 40 * @var int 41 */ 42 private $user_posts_count; 43 44 /** 45 * Holds the number of posts which are sticky. 46 * 47 * @since 3.1.0 48 * @var int 49 */ 50 private $sticky_posts_count = 0; 51 52 private $is_trash; 53 54 /** 55 * Current level for output. 56 * 57 * @since 4.3.0 58 * @var int 59 */ 60 protected $current_level = 0; 61 62 /** 63 * Constructor. 64 * 65 * @since 3.1.0 66 * 67 * @see WP_List_Table::__construct() for more information on default arguments. 68 * 69 * @global WP_Post_Type $post_type_object 70 * @global wpdb $wpdb WordPress database abstraction object. 71 * 72 * @param array $args An associative array of arguments. 73 */ 74 public function __construct( $args = array() ) { 75 global $post_type_object, $wpdb; 76 77 parent::__construct( 78 array( 79 'plural' => 'posts', 80 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, 81 ) 82 ); 83 84 $post_type = $this->screen->post_type; 85 $post_type_object = get_post_type_object( $post_type ); 86 87 $exclude_states = get_post_stati( 88 array( 89 'show_in_admin_all_list' => false, 90 ) 91 ); 92 93 $this->user_posts_count = (int) $wpdb->get_var( 94 $wpdb->prepare( 95 "SELECT COUNT( 1 ) 96 FROM $wpdb->posts 97 WHERE post_type = %s 98 AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' ) 99 AND post_author = %d", 100 $post_type, 101 get_current_user_id() 102 ) 103 ); 104 105 if ( $this->user_posts_count 106 && ! current_user_can( $post_type_object->cap->edit_others_posts ) 107 && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) 108 && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) 109 ) { 110 $_GET['author'] = get_current_user_id(); 111 } 112 113 $sticky_posts = get_option( 'sticky_posts' ); 114 115 if ( 'post' === $post_type && $sticky_posts ) { 116 $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) ); 117 118 $this->sticky_posts_count = (int) $wpdb->get_var( 119 $wpdb->prepare( 120 "SELECT COUNT( 1 ) 121 FROM $wpdb->posts 122 WHERE post_type = %s 123 AND post_status NOT IN ('trash', 'auto-draft') 124 AND ID IN ($sticky_posts)", 125 $post_type 126 ) 127 ); 128 } 129 } 130 131 /** 132 * Sets whether the table layout should be hierarchical or not. 133 * 134 * @since 4.2.0 135 * 136 * @param bool $display Whether the table layout should be hierarchical. 137 */ 138 public function set_hierarchical_display( $display ) { 139 $this->hierarchical_display = $display; 140 } 141 142 /** 143 * @return bool 144 */ 145 public function ajax_user_can() { 146 return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts ); 147 } 148 149 /** 150 * @global string $mode List table view mode. 151 * @global array $avail_post_stati 152 * @global WP_Query $wp_query WordPress Query object. 153 * @global int $per_page 154 */ 155 public function prepare_items() { 156 global $mode, $avail_post_stati, $wp_query, $per_page; 157 158 if ( ! empty( $_REQUEST['mode'] ) ) { 159 $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list'; 160 set_user_setting( 'posts_list_mode', $mode ); 161 } else { 162 $mode = get_user_setting( 'posts_list_mode', 'list' ); 163 } 164 165 // Is going to call wp(). 166 $avail_post_stati = wp_edit_posts_query(); 167 168 $this->set_hierarchical_display( 169 is_post_type_hierarchical( $this->screen->post_type ) 170 && 'menu_order title' === $wp_query->query['orderby'] 171 ); 172 173 $post_type = $this->screen->post_type; 174 $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' ); 175 176 /** This filter is documented in wp-admin/includes/post.php */ 177 $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type ); 178 179 if ( $this->hierarchical_display ) { 180 $total_items = $wp_query->post_count; 181 } elseif ( $wp_query->found_posts || $this->get_pagenum() === 1 ) { 182 $total_items = $wp_query->found_posts; 183 } else { 184 $post_counts = (array) wp_count_posts( $post_type, 'readable' ); 185 186 if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'], $avail_post_stati, true ) ) { 187 $total_items = $post_counts[ $_REQUEST['post_status'] ]; 188 } elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) { 189 $total_items = $this->sticky_posts_count; 190 } elseif ( isset( $_GET['author'] ) && get_current_user_id() === (int) $_GET['author'] ) { 191 $total_items = $this->user_posts_count; 192 } else { 193 $total_items = array_sum( $post_counts ); 194 195 // Subtract post types that are not included in the admin all list. 196 foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) { 197 $total_items -= $post_counts[ $state ]; 198 } 199 } 200 } 201 202 $this->is_trash = isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status']; 203 204 $this->set_pagination_args( 205 array( 206 'total_items' => $total_items, 207 'per_page' => $per_page, 208 ) 209 ); 210 } 211 212 /** 213 * @return bool 214 */ 215 public function has_items() { 216 return have_posts(); 217 } 218 219 /** 220 */ 221 public function no_items() { 222 if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) { 223 echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash; 224 } else { 225 echo get_post_type_object( $this->screen->post_type )->labels->not_found; 226 } 227 } 228 229 /** 230 * Determine if the current view is the "All" view. 231 * 232 * @since 4.2.0 233 * 234 * @return bool Whether the current view is the "All" view. 235 */ 236 protected function is_base_request() { 237 $vars = $_GET; 238 unset( $vars['paged'] ); 239 240 if ( empty( $vars ) ) { 241 return true; 242 } elseif ( 1 === count( $vars ) && ! empty( $vars['post_type'] ) ) { 243 return $this->screen->post_type === $vars['post_type']; 244 } 245 246 return 1 === count( $vars ) && ! empty( $vars['mode'] ); 247 } 248 249 /** 250 * Helper to create links to edit.php with params. 251 * 252 * @since 4.4.0 253 * 254 * @param string[] $args Associative array of URL parameters for the link. 255 * @param string $label Link text. 256 * @param string $class Optional. Class attribute. Default empty string. 257 * @return string The formatted link string. 258 */ 259 protected function get_edit_link( $args, $label, $class = '' ) { 260 $url = add_query_arg( $args, 'edit.php' ); 261 262 $class_html = ''; 263 $aria_current = ''; 264 265 if ( ! empty( $class ) ) { 266 $class_html = sprintf( 267 ' class="%s"', 268 esc_attr( $class ) 269 ); 270 271 if ( 'current' === $class ) { 272 $aria_current = ' aria-current="page"'; 273 } 274 } 275 276 return sprintf( 277 '<a href="%s"%s%s>%s</a>', 278 esc_url( $url ), 279 $class_html, 280 $aria_current, 281 $label 282 ); 283 } 284 285 /** 286 * @global array $locked_post_status This seems to be deprecated. 287 * @global array $avail_post_stati 288 * @return array 289 */ 290 protected function get_views() { 291 global $locked_post_status, $avail_post_stati; 292 293 $post_type = $this->screen->post_type; 294 295 if ( ! empty( $locked_post_status ) ) { 296 return array(); 297 } 298 299 $status_links = array(); 300 $num_posts = wp_count_posts( $post_type, 'readable' ); 301 $total_posts = array_sum( (array) $num_posts ); 302 $class = ''; 303 304 $current_user_id = get_current_user_id(); 305 $all_args = array( 'post_type' => $post_type ); 306 $mine = ''; 307 308 // Subtract post types that are not included in the admin all list. 309 foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) { 310 $total_posts -= $num_posts->$state; 311 } 312 313 if ( $this->user_posts_count && $this->user_posts_count !== $total_posts ) { 314 if ( isset( $_GET['author'] ) && ( $current_user_id === (int) $_GET['author'] ) ) { 315 $class = 'current'; 316 } 317 318 $mine_args = array( 319 'post_type' => $post_type, 320 'author' => $current_user_id, 321 ); 322 323 $mine_inner_html = sprintf( 324 /* translators: %s: Number of posts. */ 325 _nx( 326 'Mine <span class="count">(%s)</span>', 327 'Mine <span class="count">(%s)</span>', 328 $this->user_posts_count, 329 'posts' 330 ), 331 number_format_i18n( $this->user_posts_count ) 332 ); 333 334 $mine = $this->get_edit_link( $mine_args, $mine_inner_html, $class ); 335 336 $all_args['all_posts'] = 1; 337 $class = ''; 338 } 339 340 if ( empty( $class ) && ( $this->is_base_request() || isset( $_REQUEST['all_posts'] ) ) ) { 341 $class = 'current'; 342 } 343 344 $all_inner_html = sprintf( 345 /* translators: %s: Number of posts. */ 346 _nx( 347 'All <span class="count">(%s)</span>', 348 'All <span class="count">(%s)</span>', 349 $total_posts, 350 'posts' 351 ), 352 number_format_i18n( $total_posts ) 353 ); 354 355 $status_links['all'] = $this->get_edit_link( $all_args, $all_inner_html, $class ); 356 357 if ( $mine ) { 358 $status_links['mine'] = $mine; 359 } 360 361 foreach ( get_post_stati( array( 'show_in_admin_status_list' => true ), 'objects' ) as $status ) { 362 $class = ''; 363 364 $status_name = $status->name; 365 366 if ( ! in_array( $status_name, $avail_post_stati, true ) || empty( $num_posts->$status_name ) ) { 367 continue; 368 } 369 370 if ( isset( $_REQUEST['post_status'] ) && $status_name === $_REQUEST['post_status'] ) { 371 $class = 'current'; 372 } 373 374 $status_args = array( 375 'post_status' => $status_name, 376 'post_type' => $post_type, 377 ); 378 379 $status_label = sprintf( 380 translate_nooped_plural( $status->label_count, $num_posts->$status_name ), 381 number_format_i18n( $num_posts->$status_name ) 382 ); 383 384 $status_links[ $status_name ] = $this->get_edit_link( $status_args, $status_label, $class ); 385 } 386 387 if ( ! empty( $this->sticky_posts_count ) ) { 388 $class = ! empty( $_REQUEST['show_sticky'] ) ? 'current' : ''; 389 390 $sticky_args = array( 391 'post_type' => $post_type, 392 'show_sticky' => 1, 393 ); 394 395 $sticky_inner_html = sprintf( 396 /* translators: %s: Number of posts. */ 397 _nx( 398 'Sticky <span class="count">(%s)</span>', 399 'Sticky <span class="count">(%s)</span>', 400 $this->sticky_posts_count, 401 'posts' 402 ), 403 number_format_i18n( $this->sticky_posts_count ) 404 ); 405 406 $sticky_link = array( 407 'sticky' => $this->get_edit_link( $sticky_args, $sticky_inner_html, $class ), 408 ); 409 410 // Sticky comes after Publish, or if not listed, after All. 411 $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ), true ); 412 $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) ); 413 } 414 415 return $status_links; 416 } 417 418 /** 419 * @return array 420 */ 421 protected function get_bulk_actions() { 422 $actions = array(); 423 $post_type_obj = get_post_type_object( $this->screen->post_type ); 424 425 if ( current_user_can( $post_type_obj->cap->edit_posts ) ) { 426 if ( $this->is_trash ) { 427 $actions['untrash'] = __( 'Restore' ); 428 } else { 429 $actions['edit'] = __( 'Edit' ); 430 } 431 } 432 433 if ( current_user_can( $post_type_obj->cap->delete_posts ) ) { 434 if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) { 435 $actions['delete'] = __( 'Delete permanently' ); 436 } else { 437 $actions['trash'] = __( 'Move to Trash' ); 438 } 439 } 440 441 return $actions; 442 } 443 444 /** 445 * Displays a categories drop-down for filtering on the Posts list table. 446 * 447 * @since 4.6.0 448 * 449 * @global int $cat Currently selected category. 450 * 451 * @param string $post_type Post type slug. 452 */ 453 protected function categories_dropdown( $post_type ) { 454 global $cat; 455 456 /** 457 * Filters whether to remove the 'Categories' drop-down from the post list table. 458 * 459 * @since 4.6.0 460 * 461 * @param bool $disable Whether to disable the categories drop-down. Default false. 462 * @param string $post_type Post type slug. 463 */ 464 if ( false !== apply_filters( 'disable_categories_dropdown', false, $post_type ) ) { 465 return; 466 } 467 468 if ( is_object_in_taxonomy( $post_type, 'category' ) ) { 469 $dropdown_options = array( 470 'show_option_all' => get_taxonomy( 'category' )->labels->all_items, 471 'hide_empty' => 0, 472 'hierarchical' => 1, 473 'show_count' => 0, 474 'orderby' => 'name', 475 'selected' => $cat, 476 ); 477 478 echo '<label class="screen-reader-text" for="cat">' . get_taxonomy( 'category' )->labels->filter_by_item . '</label>'; 479 480 wp_dropdown_categories( $dropdown_options ); 481 } 482 } 483 484 /** 485 * Displays a formats drop-down for filtering items. 486 * 487 * @since 5.2.0 488 * @access protected 489 * 490 * @param string $post_type Post type slug. 491 */ 492 protected function formats_dropdown( $post_type ) { 493 /** 494 * Filters whether to remove the 'Formats' drop-down from the post list table. 495 * 496 * @since 5.2.0 497 * @since 5.5.0 The `$post_type` parameter was added. 498 * 499 * @param bool $disable Whether to disable the drop-down. Default false. 500 * @param string $post_type Post type slug. 501 */ 502 if ( apply_filters( 'disable_formats_dropdown', false, $post_type ) ) { 503 return; 504 } 505 506 // Return if the post type doesn't have post formats or if we're in the Trash. 507 if ( ! is_object_in_taxonomy( $post_type, 'post_format' ) || $this->is_trash ) { 508 return; 509 } 510 511 // Make sure the dropdown shows only formats with a post count greater than 0. 512 $used_post_formats = get_terms( 513 array( 514 'taxonomy' => 'post_format', 515 'hide_empty' => true, 516 ) 517 ); 518 519 // Return if there are no posts using formats. 520 if ( ! $used_post_formats ) { 521 return; 522 } 523 524 $displayed_post_format = isset( $_GET['post_format'] ) ? $_GET['post_format'] : ''; 525 ?> 526 <label for="filter-by-format" class="screen-reader-text"><?php _e( 'Filter by post format' ); ?></label> 527 <select name="post_format" id="filter-by-format"> 528 <option<?php selected( $displayed_post_format, '' ); ?> value=""><?php _e( 'All formats' ); ?></option> 529 <?php 530 foreach ( $used_post_formats as $used_post_format ) { 531 // Post format slug. 532 $slug = str_replace( 'post-format-', '', $used_post_format->slug ); 533 // Pretty, translated version of the post format slug. 534 $pretty_name = get_post_format_string( $slug ); 535 536 // Skip the standard post format. 537 if ( 'standard' === $slug ) { 538 continue; 539 } 540 ?> 541 <option<?php selected( $displayed_post_format, $slug ); ?> value="<?php echo esc_attr( $slug ); ?>"><?php echo esc_html( $pretty_name ); ?></option> 542 <?php 543 } 544 ?> 545 </select> 546 <?php 547 } 548 549 /** 550 * @param string $which 551 */ 552 protected function extra_tablenav( $which ) { 553 ?> 554 <div class="alignleft actions"> 555 <?php 556 if ( 'top' === $which ) { 557 ob_start(); 558 559 $this->months_dropdown( $this->screen->post_type ); 560 $this->categories_dropdown( $this->screen->post_type ); 561 $this->formats_dropdown( $this->screen->post_type ); 562 563 /** 564 * Fires before the Filter button on the Posts and Pages list tables. 565 * 566 * The Filter button allows sorting by date and/or category on the 567 * Posts list table, and sorting by date on the Pages list table. 568 * 569 * @since 2.1.0 570 * @since 4.4.0 The `$post_type` parameter was added. 571 * @since 4.6.0 The `$which` parameter was added. 572 * 573 * @param string $post_type The post type slug. 574 * @param string $which The location of the extra table nav markup: 575 * 'top' or 'bottom' for WP_Posts_List_Table, 576 * 'bar' for WP_Media_List_Table. 577 */ 578 do_action( 'restrict_manage_posts', $this->screen->post_type, $which ); 579 580 $output = ob_get_clean(); 581 582 if ( ! empty( $output ) ) { 583 echo $output; 584 submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); 585 } 586 } 587 588 if ( $this->is_trash && $this->has_items() 589 && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) 590 ) { 591 submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); 592 } 593 ?> 594 </div> 595 <?php 596 /** 597 * Fires immediately following the closing "actions" div in the tablenav for the posts 598 * list table. 599 * 600 * @since 4.4.0 601 * 602 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'. 603 */ 604 do_action( 'manage_posts_extra_tablenav', $which ); 605 } 606 607 /** 608 * @return string 609 */ 610 public function current_action() { 611 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) { 612 return 'delete_all'; 613 } 614 615 return parent::current_action(); 616 } 617 618 /** 619 * @global string $mode List table view mode. 620 * 621 * @return array 622 */ 623 protected function get_table_classes() { 624 global $mode; 625 626 $mode_class = esc_attr( 'table-view-' . $mode ); 627 628 return array( 629 'widefat', 630 'fixed', 631 'striped', 632 $mode_class, 633 is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts', 634 ); 635 } 636 637 /** 638 * @return array 639 */ 640 public function get_columns() { 641 $post_type = $this->screen->post_type; 642 643 $posts_columns = array(); 644 645 $posts_columns['cb'] = '<input type="checkbox" />'; 646 647 /* translators: Posts screen column name. */ 648 $posts_columns['title'] = _x( 'Title', 'column name' ); 649 650 if ( post_type_supports( $post_type, 'author' ) ) { 651 $posts_columns['author'] = __( 'Author' ); 652 } 653 654 $taxonomies = get_object_taxonomies( $post_type, 'objects' ); 655 $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' ); 656 657 /** 658 * Filters the taxonomy columns in the Posts list table. 659 * 660 * The dynamic portion of the hook name, `$post_type`, refers to the post 661 * type slug. 662 * 663 * Possible hook names include: 664 * 665 * - `manage_taxonomies_for_post_columns` 666 * - `manage_taxonomies_for_page_columns` 667 * 668 * @since 3.5.0 669 * 670 * @param string[] $taxonomies Array of taxonomy names to show columns for. 671 * @param string $post_type The post type. 672 */ 673 $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type ); 674 $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' ); 675 676 foreach ( $taxonomies as $taxonomy ) { 677 if ( 'category' === $taxonomy ) { 678 $column_key = 'categories'; 679 } elseif ( 'post_tag' === $taxonomy ) { 680 $column_key = 'tags'; 681 } else { 682 $column_key = 'taxonomy-' . $taxonomy; 683 } 684 685 $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name; 686 } 687 688 $post_status = ! empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all'; 689 690 if ( post_type_supports( $post_type, 'comments' ) 691 && ! in_array( $post_status, array( 'pending', 'draft', 'future' ), true ) 692 ) { 693 $posts_columns['comments'] = sprintf( 694 '<span class="vers comment-grey-bubble" title="%1$s"><span class="screen-reader-text">%2$s</span></span>', 695 esc_attr__( 'Comments' ), 696 __( 'Comments' ) 697 ); 698 } 699 700 $posts_columns['date'] = __( 'Date' ); 701 702 if ( 'page' === $post_type ) { 703 704 /** 705 * Filters the columns displayed in the Pages list table. 706 * 707 * @since 2.5.0 708 * 709 * @param string[] $post_columns An associative array of column headings. 710 */ 711 $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns ); 712 } else { 713 714 /** 715 * Filters the columns displayed in the Posts list table. 716 * 717 * @since 1.5.0 718 * 719 * @param string[] $post_columns An associative array of column headings. 720 * @param string $post_type The post type slug. 721 */ 722 $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type ); 723 } 724 725 /** 726 * Filters the columns displayed in the Posts list table for a specific post type. 727 * 728 * The dynamic portion of the hook name, `$post_type`, refers to the post type slug. 729 * 730 * Possible hook names include: 731 * 732 * - `manage_post_posts_columns` 733 * - `manage_page_posts_columns` 734 * 735 * @since 3.0.0 736 * 737 * @param string[] $post_columns An associative array of column headings. 738 */ 739 return apply_filters( "manage_{$post_type}_posts_columns", $posts_columns ); 740 } 741 742 /** 743 * @return array 744 */ 745 protected function get_sortable_columns() { 746 return array( 747 'title' => 'title', 748 'parent' => 'parent', 749 'comments' => 'comment_count', 750 'date' => array( 'date', true ), 751 ); 752 } 753 754 /** 755 * @global WP_Query $wp_query WordPress Query object. 756 * @global int $per_page 757 * @param array $posts 758 * @param int $level 759 */ 760 public function display_rows( $posts = array(), $level = 0 ) { 761 global $wp_query, $per_page; 762 763 if ( empty( $posts ) ) { 764 $posts = $wp_query->posts; 765 } 766 767 add_filter( 'the_title', 'esc_html' ); 768 769 if ( $this->hierarchical_display ) { 770 $this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page ); 771 } else { 772 $this->_display_rows( $posts, $level ); 773 } 774 } 775 776 /** 777 * @param array $posts 778 * @param int $level 779 */ 780 private function _display_rows( $posts, $level = 0 ) { 781 $post_type = $this->screen->post_type; 782 783 // Create array of post IDs. 784 $post_ids = array(); 785 786 foreach ( $posts as $a_post ) { 787 $post_ids[] = $a_post->ID; 788 } 789 790 if ( post_type_supports( $post_type, 'comments' ) ) { 791 $this->comment_pending_count = get_pending_comments_num( $post_ids ); 792 } 793 794 foreach ( $posts as $post ) { 795 $this->single_row( $post, $level ); 796 } 797 } 798 799 /** 800 * @global wpdb $wpdb WordPress database abstraction object. 801 * @global WP_Post $post Global post object. 802 * @param array $pages 803 * @param int $pagenum 804 * @param int $per_page 805 */ 806 private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) { 807 global $wpdb; 808 809 $level = 0; 810 811 if ( ! $pages ) { 812 $pages = get_pages( array( 'sort_column' => 'menu_order' ) ); 813 814 if ( ! $pages ) { 815 return; 816 } 817 } 818 819 /* 820 * Arrange pages into two parts: top level pages and children_pages 821 * children_pages is two dimensional array, eg. 822 * children_pages[10][] contains all sub-pages whose parent is 10. 823 * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations 824 * If searching, ignore hierarchy and treat everything as top level 825 */ 826 if ( empty( $_REQUEST['s'] ) ) { 827 $top_level_pages = array(); 828 $children_pages = array(); 829 830 foreach ( $pages as $page ) { 831 // Catch and repair bad pages. 832 if ( $page->post_parent === $page->ID ) { 833 $page->post_parent = 0; 834 $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) ); 835 clean_post_cache( $page ); 836 } 837 838 if ( $page->post_parent > 0 ) { 839 $children_pages[ $page->post_parent ][] = $page; 840 } else { 841 $top_level_pages[] = $page; 842 } 843 } 844 845 $pages = &$top_level_pages; 846 } 847 848 $count = 0; 849 $start = ( $pagenum - 1 ) * $per_page; 850 $end = $start + $per_page; 851 $to_display = array(); 852 853 foreach ( $pages as $page ) { 854 if ( $count >= $end ) { 855 break; 856 } 857 858 if ( $count >= $start ) { 859 $to_display[ $page->ID ] = $level; 860 } 861 862 $count++; 863 864 if ( isset( $children_pages ) ) { 865 $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display ); 866 } 867 } 868 869 // If it is the last pagenum and there are orphaned pages, display them with paging as well. 870 if ( isset( $children_pages ) && $count < $end ) { 871 foreach ( $children_pages as $orphans ) { 872 foreach ( $orphans as $op ) { 873 if ( $count >= $end ) { 874 break; 875 } 876 877 if ( $count >= $start ) { 878 $to_display[ $op->ID ] = 0; 879 } 880 881 $count++; 882 } 883 } 884 } 885 886 $ids = array_keys( $to_display ); 887 _prime_post_caches( $ids ); 888 889 if ( ! isset( $GLOBALS['post'] ) ) { 890 $GLOBALS['post'] = reset( $ids ); 891 } 892 893 foreach ( $to_display as $page_id => $level ) { 894 echo "\t"; 895 $this->single_row( $page_id, $level ); 896 } 897 } 898 899 /** 900 * Given a top level page ID, display the nested hierarchy of sub-pages 901 * together with paging support 902 * 903 * @since 3.1.0 (Standalone function exists since 2.6.0) 904 * @since 4.2.0 Added the `$to_display` parameter. 905 * 906 * @param array $children_pages 907 * @param int $count 908 * @param int $parent 909 * @param int $level 910 * @param int $pagenum 911 * @param int $per_page 912 * @param array $to_display List of pages to be displayed. Passed by reference. 913 */ 914 private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) { 915 if ( ! isset( $children_pages[ $parent ] ) ) { 916 return; 917 } 918 919 $start = ( $pagenum - 1 ) * $per_page; 920 $end = $start + $per_page; 921 922 foreach ( $children_pages[ $parent ] as $page ) { 923 if ( $count >= $end ) { 924 break; 925 } 926 927 // If the page starts in a subtree, print the parents. 928 if ( $count === $start && $page->post_parent > 0 ) { 929 $my_parents = array(); 930 $my_parent = $page->post_parent; 931 932 while ( $my_parent ) { 933 // Get the ID from the list or the attribute if my_parent is an object. 934 $parent_id = $my_parent; 935 936 if ( is_object( $my_parent ) ) { 937 $parent_id = $my_parent->ID; 938 } 939 940 $my_parent = get_post( $parent_id ); 941 $my_parents[] = $my_parent; 942 943 if ( ! $my_parent->post_parent ) { 944 break; 945 } 946 947 $my_parent = $my_parent->post_parent; 948 } 949 950 $num_parents = count( $my_parents ); 951 952 while ( $my_parent = array_pop( $my_parents ) ) { 953 $to_display[ $my_parent->ID ] = $level - $num_parents; 954 $num_parents--; 955 } 956 } 957 958 if ( $count >= $start ) { 959 $to_display[ $page->ID ] = $level; 960 } 961 962 $count++; 963 964 $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display ); 965 } 966 967 unset( $children_pages[ $parent ] ); // Required in order to keep track of orphans. 968 } 969 970 /** 971 * Handles the checkbox column output. 972 * 973 * @since 4.3.0 974 * 975 * @param WP_Post $post The current WP_Post object. 976 */ 977 public function column_cb( $post ) { 978 $show = current_user_can( 'edit_post', $post->ID ); 979 980 /** 981 * Filters whether to show the bulk edit checkbox for a post in its list table. 982 * 983 * By default the checkbox is only shown if the current user can edit the post. 984 * 985 * @since 5.7.0 986 * 987 * @param bool $show Whether to show the checkbox. 988 * @param WP_Post $post The current WP_Post object. 989 */ 990 if ( apply_filters( 'wp_list_table_show_post_checkbox', $show, $post ) ) : 991 ?> 992 <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"> 993 <?php 994 /* translators: %s: Post title. */ 995 printf( __( 'Select %s' ), _draft_or_post_title() ); 996 ?> 997 </label> 998 <input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" /> 999 <div class="locked-indicator"> 1000 <span class="locked-indicator-icon" aria-hidden="true"></span> 1001 <span class="screen-reader-text"> 1002 <?php 1003 printf( 1004 /* translators: %s: Post title. */ 1005 __( '“%s” is locked' ), 1006 _draft_or_post_title() 1007 ); 1008 ?> 1009 </span> 1010 </div> 1011 <?php 1012 endif; 1013 } 1014 1015 /** 1016 * @since 4.3.0 1017 * 1018 * @param WP_Post $post 1019 * @param string $classes 1020 * @param string $data 1021 * @param string $primary 1022 */ 1023 protected function _column_title( $post, $classes, $data, $primary ) { 1024 echo '<td class="' . $classes . ' page-title" ', $data, '>'; 1025 echo $this->column_title( $post ); 1026 echo $this->handle_row_actions( $post, 'title', $primary ); 1027 echo '</td>'; 1028 } 1029 1030 /** 1031 * Handles the title column output. 1032 * 1033 * @since 4.3.0 1034 * 1035 * @global string $mode List table view mode. 1036 * 1037 * @param WP_Post $post The current WP_Post object. 1038 */ 1039 public function column_title( $post ) { 1040 global $mode; 1041 1042 if ( $this->hierarchical_display ) { 1043 if ( 0 === $this->current_level && (int) $post->post_parent > 0 ) { 1044 // Sent level 0 by accident, by default, or because we don't know the actual level. 1045 $find_main_page = (int) $post->post_parent; 1046 1047 while ( $find_main_page > 0 ) { 1048 $parent = get_post( $find_main_page ); 1049 1050 if ( is_null( $parent ) ) { 1051 break; 1052 } 1053 1054 $this->current_level++; 1055 $find_main_page = (int) $parent->post_parent; 1056 1057 if ( ! isset( $parent_name ) ) { 1058 /** This filter is documented in wp-includes/post-template.php */ 1059 $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID ); 1060 } 1061 } 1062 } 1063 } 1064 1065 $can_edit_post = current_user_can( 'edit_post', $post->ID ); 1066 1067 if ( $can_edit_post && 'trash' !== $post->post_status ) { 1068 $lock_holder = wp_check_post_lock( $post->ID ); 1069 1070 if ( $lock_holder ) { 1071 $lock_holder = get_userdata( $lock_holder ); 1072 $locked_avatar = get_avatar( $lock_holder->ID, 18 ); 1073 /* translators: %s: User's display name. */ 1074 $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) ); 1075 } else { 1076 $locked_avatar = ''; 1077 $locked_text = ''; 1078 } 1079 1080 echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n"; 1081 } 1082 1083 $pad = str_repeat( '— ', $this->current_level ); 1084 echo '<strong>'; 1085 1086 $title = _draft_or_post_title(); 1087 1088 if ( $can_edit_post && 'trash' !== $post->post_status ) { 1089 printf( 1090 '<a class="row-title" href="%s" aria-label="%s">%s%s</a>', 1091 get_edit_post_link( $post->ID ), 1092 /* translators: %s: Post title. */ 1093 esc_attr( sprintf( __( '“%s” (Edit)' ), $title ) ), 1094 $pad, 1095 $title 1096 ); 1097 } else { 1098 printf( 1099 '<span>%s%s</span>', 1100 $pad, 1101 $title 1102 ); 1103 } 1104 _post_states( $post ); 1105 1106 if ( isset( $parent_name ) ) { 1107 $post_type_object = get_post_type_object( $post->post_type ); 1108 echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name ); 1109 } 1110 1111 echo "</strong>\n"; 1112 1113 if ( 'excerpt' === $mode 1114 && ! is_post_type_hierarchical( $this->screen->post_type ) 1115 && current_user_can( 'read_post', $post->ID ) 1116 ) { 1117 if ( post_password_required( $post ) ) { 1118 echo '<span class="protected-post-excerpt">' . esc_html( get_the_excerpt() ) . '</span>'; 1119 } else { 1120 echo esc_html( get_the_excerpt() ); 1121 } 1122 } 1123 1124 get_inline_data( $post ); 1125 } 1126 1127 /** 1128 * Handles the post date column output. 1129 * 1130 * @since 4.3.0 1131 * 1132 * @global string $mode List table view mode. 1133 * 1134 * @param WP_Post $post The current WP_Post object. 1135 */ 1136 public function column_date( $post ) { 1137 global $mode; 1138 1139 if ( '0000-00-00 00:00:00' === $post->post_date ) { 1140 $t_time = __( 'Unpublished' ); 1141 $time_diff = 0; 1142 } else { 1143 $t_time = sprintf( 1144 /* translators: 1: Post date, 2: Post time. */ 1145 __( '%1$s at %2$s' ), 1146 /* translators: Post date format. See https://www.php.net/manual/datetime.format.php */ 1147 get_the_time( __( 'Y/m/d' ), $post ), 1148 /* translators: Post time format. See https://www.php.net/manual/datetime.format.php */ 1149 get_the_time( __( 'g:i a' ), $post ) 1150 ); 1151 1152 $time = get_post_timestamp( $post ); 1153 $time_diff = time() - $time; 1154 } 1155 1156 if ( 'publish' === $post->post_status ) { 1157 $status = __( 'Published' ); 1158 } elseif ( 'future' === $post->post_status ) { 1159 if ( $time_diff > 0 ) { 1160 $status = '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>'; 1161 } else { 1162 $status = __( 'Scheduled' ); 1163 } 1164 } else { 1165 $status = __( 'Last Modified' ); 1166 } 1167 1168 /** 1169 * Filters the status text of the post. 1170 * 1171 * @since 4.8.0 1172 * 1173 * @param string $status The status text. 1174 * @param WP_Post $post Post object. 1175 * @param string $column_name The column name. 1176 * @param string $mode The list display mode ('excerpt' or 'list'). 1177 */ 1178 $status = apply_filters( 'post_date_column_status', $status, $post, 'date', $mode ); 1179 1180 if ( $status ) { 1181 echo $status . '<br />'; 1182 } 1183 1184 /** 1185 * Filters the published time of the post. 1186 * 1187 * @since 2.5.1 1188 * @since 5.5.0 Removed the difference between 'excerpt' and 'list' modes. 1189 * The published time and date are both displayed now, 1190 * which is equivalent to the previous 'excerpt' mode. 1191 * 1192 * @param string $t_time The published time. 1193 * @param WP_Post $post Post object. 1194 * @param string $column_name The column name. 1195 * @param string $mode The list display mode ('excerpt' or 'list'). 1196 */ 1197 echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode ); 1198 } 1199 1200 /** 1201 * Handles the comments column output. 1202 * 1203 * @since 4.3.0 1204 * 1205 * @param WP_Post $post The current WP_Post object. 1206 */ 1207 public function column_comments( $post ) { 1208 ?> 1209 <div class="post-com-count-wrapper"> 1210 <?php 1211 $pending_comments = isset( $this->comment_pending_count[ $post->ID ] ) ? $this->comment_pending_count[ $post->ID ] : 0; 1212 1213 $this->comments_bubble( $post->ID, $pending_comments ); 1214 ?> 1215 </div> 1216 <?php 1217 } 1218 1219 /** 1220 * Handles the post author column output. 1221 * 1222 * @since 4.3.0 1223 * 1224 * @param WP_Post $post The current WP_Post object. 1225 */ 1226 public function column_author( $post ) { 1227 $args = array( 1228 'post_type' => $post->post_type, 1229 'author' => get_the_author_meta( 'ID' ), 1230 ); 1231 echo $this->get_edit_link( $args, get_the_author() ); 1232 } 1233 1234 /** 1235 * Handles the default column output. 1236 * 1237 * @since 4.3.0 1238 * 1239 * @param WP_Post $post The current WP_Post object. 1240 * @param string $column_name The current column name. 1241 */ 1242 public function column_default( $post, $column_name ) { 1243 if ( 'categories' === $column_name ) { 1244 $taxonomy = 'category'; 1245 } elseif ( 'tags' === $column_name ) { 1246 $taxonomy = 'post_tag'; 1247 } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) { 1248 $taxonomy = substr( $column_name, 9 ); 1249 } else { 1250 $taxonomy = false; 1251 } 1252 1253 if ( $taxonomy ) { 1254 $taxonomy_object = get_taxonomy( $taxonomy ); 1255 $terms = get_the_terms( $post->ID, $taxonomy ); 1256 1257 if ( is_array( $terms ) ) { 1258 $term_links = array(); 1259 1260 foreach ( $terms as $t ) { 1261 $posts_in_term_qv = array(); 1262 1263 if ( 'post' !== $post->post_type ) { 1264 $posts_in_term_qv['post_type'] = $post->post_type; 1265 } 1266 1267 if ( $taxonomy_object->query_var ) { 1268 $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug; 1269 } else { 1270 $posts_in_term_qv['taxonomy'] = $taxonomy; 1271 $posts_in_term_qv['term'] = $t->slug; 1272 } 1273 1274 $label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) ); 1275 1276 $term_links[] = $this->get_edit_link( $posts_in_term_qv, $label ); 1277 } 1278 1279 /** 1280 * Filters the links in `$taxonomy` column of edit.php. 1281 * 1282 * @since 5.2.0 1283 * 1284 * @param string[] $term_links Array of term editing links. 1285 * @param string $taxonomy Taxonomy name. 1286 * @param WP_Term[] $terms Array of term objects appearing in the post row. 1287 */ 1288 $term_links = apply_filters( 'post_column_taxonomy_links', $term_links, $taxonomy, $terms ); 1289 1290 /* translators: Used between list items, there is a space after the comma. */ 1291 echo implode( __( ', ' ), $term_links ); 1292 } else { 1293 echo '<span aria-hidden="true">—</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>'; 1294 } 1295 return; 1296 } 1297 1298 if ( is_post_type_hierarchical( $post->post_type ) ) { 1299 1300 /** 1301 * Fires in each custom column on the Posts list table. 1302 * 1303 * This hook only fires if the current post type is hierarchical, 1304 * such as pages. 1305 * 1306 * @since 2.5.0 1307 * 1308 * @param string $column_name The name of the column to display. 1309 * @param int $post_id The current post ID. 1310 */ 1311 do_action( 'manage_pages_custom_column', $column_name, $post->ID ); 1312 } else { 1313 1314 /** 1315 * Fires in each custom column in the Posts list table. 1316 * 1317 * This hook only fires if the current post type is non-hierarchical, 1318 * such as posts. 1319 * 1320 * @since 1.5.0 1321 * 1322 * @param string $column_name The name of the column to display. 1323 * @param int $post_id The current post ID. 1324 */ 1325 do_action( 'manage_posts_custom_column', $column_name, $post->ID ); 1326 } 1327 1328 /** 1329 * Fires for each custom column of a specific post type in the Posts list table. 1330 * 1331 * The dynamic portion of the hook name, `$post->post_type`, refers to the post type. 1332 * 1333 * Possible hook names include: 1334 * 1335 * - `manage_post_posts_custom_column` 1336 * - `manage_page_posts_custom_column` 1337 * 1338 * @since 3.1.0 1339 * 1340 * @param string $column_name The name of the column to display. 1341 * @param int $post_id The current post ID. 1342 */ 1343 do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID ); 1344 } 1345 1346 /** 1347 * @global WP_Post $post Global post object. 1348 * 1349 * @param int|WP_Post $post 1350 * @param int $level 1351 */ 1352 public function single_row( $post, $level = 0 ) { 1353 $global_post = get_post(); 1354 1355 $post = get_post( $post ); 1356 $this->current_level = $level; 1357 1358 $GLOBALS['post'] = $post; 1359 setup_postdata( $post ); 1360 1361 $classes = 'iedit author-' . ( get_current_user_id() === (int) $post->post_author ? 'self' : 'other' ); 1362 1363 $lock_holder = wp_check_post_lock( $post->ID ); 1364 1365 if ( $lock_holder ) { 1366 $classes .= ' wp-locked'; 1367 } 1368 1369 if ( $post->post_parent ) { 1370 $count = count( get_post_ancestors( $post->ID ) ); 1371 $classes .= ' level-' . $count; 1372 } else { 1373 $classes .= ' level-0'; 1374 } 1375 ?> 1376 <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>"> 1377 <?php $this->single_row_columns( $post ); ?> 1378 </tr> 1379 <?php 1380 $GLOBALS['post'] = $global_post; 1381 } 1382 1383 /** 1384 * Gets the name of the default primary column. 1385 * 1386 * @since 4.3.0 1387 * 1388 * @return string Name of the default primary column, in this case, 'title'. 1389 */ 1390 protected function get_default_primary_column_name() { 1391 return 'title'; 1392 } 1393 1394 /** 1395 * Generates and displays row action links. 1396 * 1397 * @since 4.3.0 1398 * 1399 * @param WP_Post $post Post being acted upon. 1400 * @param string $column_name Current column name. 1401 * @param string $primary Primary column name. 1402 * @return string Row actions output for posts, or an empty string 1403 * if the current column is not the primary column. 1404 */ 1405 protected function handle_row_actions( $post, $column_name, $primary ) { 1406 if ( $primary !== $column_name ) { 1407 return ''; 1408 } 1409 1410 $post_type_object = get_post_type_object( $post->post_type ); 1411 $can_edit_post = current_user_can( 'edit_post', $post->ID ); 1412 $actions = array(); 1413 $title = _draft_or_post_title(); 1414 1415 if ( $can_edit_post && 'trash' !== $post->post_status ) { 1416 $actions['edit'] = sprintf( 1417 '<a href="%s" aria-label="%s">%s</a>', 1418 get_edit_post_link( $post->ID ), 1419 /* translators: %s: Post title. */ 1420 esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ), 1421 __( 'Edit' ) 1422 ); 1423 1424 if ( 'wp_block' !== $post->post_type ) { 1425 $actions['inline hide-if-no-js'] = sprintf( 1426 '<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>', 1427 /* translators: %s: Post title. */ 1428 esc_attr( sprintf( __( 'Quick edit “%s” inline' ), $title ) ), 1429 __( 'Quick Edit' ) 1430 ); 1431 } 1432 } 1433 1434 if ( current_user_can( 'delete_post', $post->ID ) ) { 1435 if ( 'trash' === $post->post_status ) { 1436 $actions['untrash'] = sprintf( 1437 '<a href="%s" aria-label="%s">%s</a>', 1438 wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ), 1439 /* translators: %s: Post title. */ 1440 esc_attr( sprintf( __( 'Restore “%s” from the Trash' ), $title ) ), 1441 __( 'Restore' ) 1442 ); 1443 } elseif ( EMPTY_TRASH_DAYS ) { 1444 $actions['trash'] = sprintf( 1445 '<a href="%s" class="submitdelete" aria-label="%s">%s</a>', 1446 get_delete_post_link( $post->ID ), 1447 /* translators: %s: Post title. */ 1448 esc_attr( sprintf( __( 'Move “%s” to the Trash' ), $title ) ), 1449 _x( 'Trash', 'verb' ) 1450 ); 1451 } 1452 1453 if ( 'trash' === $post->post_status || ! EMPTY_TRASH_DAYS ) { 1454 $actions['delete'] = sprintf( 1455 '<a href="%s" class="submitdelete" aria-label="%s">%s</a>', 1456 get_delete_post_link( $post->ID, '', true ), 1457 /* translators: %s: Post title. */ 1458 esc_attr( sprintf( __( 'Delete “%s” permanently' ), $title ) ), 1459 __( 'Delete Permanently' ) 1460 ); 1461 } 1462 } 1463 1464 if ( is_post_type_viewable( $post_type_object ) ) { 1465 if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ), true ) ) { 1466 if ( $can_edit_post ) { 1467 $preview_link = get_preview_post_link( $post ); 1468 $actions['view'] = sprintf( 1469 '<a href="%s" rel="bookmark" aria-label="%s">%s</a>', 1470 esc_url( $preview_link ), 1471 /* translators: %s: Post title. */ 1472 esc_attr( sprintf( __( 'Preview “%s”' ), $title ) ), 1473 __( 'Preview' ) 1474 ); 1475 } 1476 } elseif ( 'trash' !== $post->post_status ) { 1477 $actions['view'] = sprintf( 1478 '<a href="%s" rel="bookmark" aria-label="%s">%s</a>', 1479 get_permalink( $post->ID ), 1480 /* translators: %s: Post title. */ 1481 esc_attr( sprintf( __( 'View “%s”' ), $title ) ), 1482 __( 'View' ) 1483 ); 1484 } 1485 } 1486 1487 if ( 'wp_block' === $post->post_type ) { 1488 $actions['export'] = sprintf( 1489 '<button type="button" class="wp-list-reusable-blocks__export button-link" data-id="%s" aria-label="%s">%s</button>', 1490 $post->ID, 1491 /* translators: %s: Post title. */ 1492 esc_attr( sprintf( __( 'Export “%s” as JSON' ), $title ) ), 1493 __( 'Export as JSON' ) 1494 ); 1495 } 1496 1497 if ( is_post_type_hierarchical( $post->post_type ) ) { 1498 1499 /** 1500 * Filters the array of row action links on the Pages list table. 1501 * 1502 * The filter is evaluated only for hierarchical post types. 1503 * 1504 * @since 2.8.0 1505 * 1506 * @param string[] $actions An array of row action links. Defaults are 1507 * 'Edit', 'Quick Edit', 'Restore', 'Trash', 1508 * 'Delete Permanently', 'Preview', and 'View'. 1509 * @param WP_Post $post The post object. 1510 */ 1511 $actions = apply_filters( 'page_row_actions', $actions, $post ); 1512 } else { 1513 1514 /** 1515 * Filters the array of row action links on the Posts list table. 1516 * 1517 * The filter is evaluated only for non-hierarchical post types. 1518 * 1519 * @since 2.8.0 1520 * 1521 * @param string[] $actions An array of row action links. Defaults are 1522 * 'Edit', 'Quick Edit', 'Restore', 'Trash', 1523 * 'Delete Permanently', 'Preview', and 'View'. 1524 * @param WP_Post $post The post object. 1525 */ 1526 $actions = apply_filters( 'post_row_actions', $actions, $post ); 1527 } 1528 1529 return $this->row_actions( $actions ); 1530 } 1531 1532 /** 1533 * Outputs the hidden row displayed when inline editing 1534 * 1535 * @since 3.1.0 1536 * 1537 * @global string $mode List table view mode. 1538 */ 1539 public function inline_edit() { 1540 global $mode; 1541 1542 $screen = $this->screen; 1543 1544 $post = get_default_post_to_edit( $screen->post_type ); 1545 $post_type_object = get_post_type_object( $screen->post_type ); 1546 1547 $taxonomy_names = get_object_taxonomies( $screen->post_type ); 1548 $hierarchical_taxonomies = array(); 1549 $flat_taxonomies = array(); 1550 1551 foreach ( $taxonomy_names as $taxonomy_name ) { 1552 $taxonomy = get_taxonomy( $taxonomy_name ); 1553 1554 $show_in_quick_edit = $taxonomy->show_in_quick_edit; 1555 1556 /** 1557 * Filters whether the current taxonomy should be shown in the Quick Edit panel. 1558 * 1559 * @since 4.2.0 1560 * 1561 * @param bool $show_in_quick_edit Whether to show the current taxonomy in Quick Edit. 1562 * @param string $taxonomy_name Taxonomy name. 1563 * @param string $post_type Post type of current Quick Edit post. 1564 */ 1565 if ( ! apply_filters( 'quick_edit_show_taxonomy', $show_in_quick_edit, $taxonomy_name, $screen->post_type ) ) { 1566 continue; 1567 } 1568 1569 if ( $taxonomy->hierarchical ) { 1570 $hierarchical_taxonomies[] = $taxonomy; 1571 } else { 1572 $flat_taxonomies[] = $taxonomy; 1573 } 1574 } 1575 1576 $m = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list'; 1577 $can_publish = current_user_can( $post_type_object->cap->publish_posts ); 1578 $core_columns = array( 1579 'cb' => true, 1580 'date' => true, 1581 'title' => true, 1582 'categories' => true, 1583 'tags' => true, 1584 'comments' => true, 1585 'author' => true, 1586 ); 1587 ?> 1588 1589 <form method="get"> 1590 <table style="display: none"><tbody id="inlineedit"> 1591 <?php 1592 $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page'; 1593 $inline_edit_classes = "inline-edit-row inline-edit-row-$hclass"; 1594 $bulk_edit_classes = "bulk-edit-row bulk-edit-row-$hclass bulk-edit-{$screen->post_type}"; 1595 $quick_edit_classes = "quick-edit-row quick-edit-row-$hclass inline-edit-{$screen->post_type}"; 1596 1597 $bulk = 0; 1598 1599 while ( $bulk < 2 ) : 1600 $classes = $inline_edit_classes . ' '; 1601 $classes .= $bulk ? $bulk_edit_classes : $quick_edit_classes; 1602 ?> 1603 <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="<?php echo $classes; ?>" style="display: none"> 1604 <td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange"> 1605 1606 <fieldset class="inline-edit-col-left"> 1607 <legend class="inline-edit-legend"><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></legend> 1608 <div class="inline-edit-col"> 1609 1610 <?php if ( post_type_supports( $screen->post_type, 'title' ) ) : ?> 1611 1612 <?php if ( $bulk ) : ?> 1613 1614 <div id="bulk-title-div"> 1615 <div id="bulk-titles"></div> 1616 </div> 1617 1618 <?php else : // $bulk ?> 1619 1620 <label> 1621 <span class="title"><?php _e( 'Title' ); ?></span> 1622 <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span> 1623 </label> 1624 1625 <?php if ( is_post_type_viewable( $screen->post_type ) ) : ?> 1626 1627 <label> 1628 <span class="title"><?php _e( 'Slug' ); ?></span> 1629 <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span> 1630 </label> 1631 1632 <?php endif; // is_post_type_viewable() ?> 1633 1634 <?php endif; // $bulk ?> 1635 1636 <?php endif; // post_type_supports( ... 'title' ) ?> 1637 1638 <?php if ( ! $bulk ) : ?> 1639 <fieldset class="inline-edit-date"> 1640 <legend><span class="title"><?php _e( 'Date' ); ?></span></legend> 1641 <?php touch_time( 1, 1, 0, 1 ); ?> 1642 </fieldset> 1643 <br class="clear" /> 1644 <?php endif; // $bulk ?> 1645 1646 <?php 1647 if ( post_type_supports( $screen->post_type, 'author' ) ) { 1648 $authors_dropdown = ''; 1649 1650 if ( current_user_can( $post_type_object->cap->edit_others_posts ) ) { 1651 $users_opt = array( 1652 'hide_if_only_one_author' => false, 1653 'who' => 'authors', 1654 'name' => 'post_author', 1655 'class' => 'authors', 1656 'multi' => 1, 1657 'echo' => 0, 1658 'show' => 'display_name_with_login', 1659 ); 1660 1661 if ( $bulk ) { 1662 $users_opt['show_option_none'] = __( '— No Change —' ); 1663 } 1664 1665 /** 1666 * Filters the arguments used to generate the Quick Edit authors drop-down. 1667 * 1668 * @since 5.6.0 1669 * 1670 * @see wp_dropdown_users() 1671 * 1672 * @param array $users_opt An array of arguments passed to wp_dropdown_users(). 1673 * @param bool $bulk A flag to denote if it's a bulk action. 1674 */ 1675 $users_opt = apply_filters( 'quick_edit_dropdown_authors_args', $users_opt, $bulk ); 1676 1677 $authors = wp_dropdown_users( $users_opt ); 1678 1679 if ( $authors ) { 1680 $authors_dropdown = '<label class="inline-edit-author">'; 1681 $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>'; 1682 $authors_dropdown .= $authors; 1683 $authors_dropdown .= '</label>'; 1684 } 1685 } // current_user_can( 'edit_others_posts' ) 1686 1687 if ( ! $bulk ) { 1688 echo $authors_dropdown; 1689 } 1690 } // post_type_supports( ... 'author' ) 1691 ?> 1692 1693 <?php if ( ! $bulk && $can_publish ) : ?> 1694 1695 <div class="inline-edit-group wp-clearfix"> 1696 <label class="alignleft"> 1697 <span class="title"><?php _e( 'Password' ); ?></span> 1698 <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span> 1699 </label> 1700 1701 <span class="alignleft inline-edit-or"> 1702 <?php 1703 /* translators: Between password field and private checkbox on post quick edit interface. */ 1704 _e( '–OR–' ); 1705 ?> 1706 </span> 1707 <label class="alignleft inline-edit-private"> 1708 <input type="checkbox" name="keep_private" value="private" /> 1709 <span class="checkbox-title"><?php _e( 'Private' ); ?></span> 1710 </label> 1711 </div> 1712 1713 <?php endif; ?> 1714 1715 </div> 1716 </fieldset> 1717 1718 <?php if ( count( $hierarchical_taxonomies ) && ! $bulk ) : ?> 1719 1720 <fieldset class="inline-edit-col-center inline-edit-categories"> 1721 <div class="inline-edit-col"> 1722 1723 <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?> 1724 1725 <span class="title inline-edit-categories-label"><?php echo esc_html( $taxonomy->labels->name ); ?></span> 1726 <input type="hidden" name="<?php echo ( 'category' === $taxonomy->name ) ? 'post_category[]' : 'tax_input[' . esc_attr( $taxonomy->name ) . '][]'; ?>" value="0" /> 1727 <ul class="cat-checklist <?php echo esc_attr( $taxonomy->name ); ?>-checklist"> 1728 <?php wp_terms_checklist( null, array( 'taxonomy' => $taxonomy->name ) ); ?> 1729 </ul> 1730 1731 <?php endforeach; // $hierarchical_taxonomies as $taxonomy ?> 1732 1733 </div> 1734 </fieldset> 1735 1736 <?php endif; // count( $hierarchical_taxonomies ) && ! $bulk ?> 1737 1738 <fieldset class="inline-edit-col-right"> 1739 <div class="inline-edit-col"> 1740 1741 <?php 1742 if ( post_type_supports( $screen->post_type, 'author' ) && $bulk ) { 1743 echo $authors_dropdown; 1744 } 1745 ?> 1746 1747 <?php if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) : ?> 1748 1749 <?php if ( $post_type_object->hierarchical ) : ?> 1750 1751 <label> 1752 <span class="title"><?php _e( 'Parent' ); ?></span> 1753 <?php 1754 $dropdown_args = array( 1755 'post_type' => $post_type_object->name, 1756 'selected' => $post->post_parent, 1757 'name' => 'post_parent', 1758 'show_option_none' => __( 'Main Page (no parent)' ), 1759 'option_none_value' => 0, 1760 'sort_column' => 'menu_order, post_title', 1761 ); 1762 1763 if ( $bulk ) { 1764 $dropdown_args['show_option_no_change'] = __( '— No Change —' ); 1765 } 1766 1767 /** 1768 * Filters the arguments used to generate the Quick Edit page-parent drop-down. 1769 * 1770 * @since 2.7.0 1771 * @since 5.6.0 The `$bulk` parameter was added. 1772 * 1773 * @see wp_dropdown_pages() 1774 * 1775 * @param array $dropdown_args An array of arguments passed to wp_dropdown_pages(). 1776 * @param bool $bulk A flag to denote if it's a bulk action. 1777 */ 1778 $dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args, $bulk ); 1779 1780 wp_dropdown_pages( $dropdown_args ); 1781 ?> 1782 </label> 1783 1784 <?php endif; // hierarchical ?> 1785 1786 <?php if ( ! $bulk ) : ?> 1787 1788 <label> 1789 <span class="title"><?php _e( 'Order' ); ?></span> 1790 <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order; ?>" /></span> 1791 </label> 1792 1793 <?php endif; // ! $bulk ?> 1794 1795 <?php endif; // post_type_supports( ... 'page-attributes' ) ?> 1796 1797 <?php if ( 0 < count( get_page_templates( null, $screen->post_type ) ) ) : ?> 1798 1799 <label> 1800 <span class="title"><?php _e( 'Template' ); ?></span> 1801 <select name="page_template"> 1802 <?php if ( $bulk ) : ?> 1803 <option value="-1"><?php _e( '— No Change —' ); ?></option> 1804 <?php endif; // $bulk ?> 1805 <?php 1806 /** This filter is documented in wp-admin/includes/meta-boxes.php */ 1807 $default_title = apply_filters( 'default_page_template_title', __( 'Default template' ), 'quick-edit' ); 1808 ?> 1809 <option value="default"><?php echo esc_html( $default_title ); ?></option> 1810 <?php page_template_dropdown( '', $screen->post_type ); ?> 1811 </select> 1812 </label> 1813 1814 <?php endif; ?> 1815 1816 <?php if ( count( $flat_taxonomies ) && ! $bulk ) : ?> 1817 1818 <?php foreach ( $flat_taxonomies as $taxonomy ) : ?> 1819 1820 <?php if ( current_user_can( $taxonomy->cap->assign_terms ) ) : ?> 1821 <?php $taxonomy_name = esc_attr( $taxonomy->name ); ?> 1822 1823 <label class="inline-edit-tags"> 1824 <span class="title"><?php echo esc_html( $taxonomy->labels->name ); ?></span> 1825 <textarea data-wp-taxonomy="<?php echo $taxonomy_name; ?>" cols="22" rows="1" name="tax_input[<?php echo $taxonomy_name; ?>]" class="tax_input_<?php echo $taxonomy_name; ?>"></textarea> 1826 </label> 1827 1828 <?php endif; // current_user_can( 'assign_terms' ) ?> 1829 1830 <?php endforeach; // $flat_taxonomies as $taxonomy ?> 1831 1832 <?php endif; // count( $flat_taxonomies ) && ! $bulk ?> 1833 1834 <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?> 1835 1836 <?php if ( $bulk ) : ?> 1837 1838 <div class="inline-edit-group wp-clearfix"> 1839 1840 <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?> 1841 1842 <label class="alignleft"> 1843 <span class="title"><?php _e( 'Comments' ); ?></span> 1844 <select name="comment_status"> 1845 <option value=""><?php _e( '— No Change —' ); ?></option> 1846 <option value="open"><?php _e( 'Allow' ); ?></option> 1847 <option value="closed"><?php _e( 'Do not allow' ); ?></option> 1848 </select> 1849 </label> 1850 1851 <?php endif; ?> 1852 1853 <?php if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?> 1854 1855 <label class="alignright"> 1856 <span class="title"><?php _e( 'Pings' ); ?></span> 1857 <select name="ping_status"> 1858 <option value=""><?php _e( '— No Change —' ); ?></option> 1859 <option value="open"><?php _e( 'Allow' ); ?></option> 1860 <option value="closed"><?php _e( 'Do not allow' ); ?></option> 1861 </select> 1862 </label> 1863 1864 <?php endif; ?> 1865 1866 </div> 1867 1868 <?php else : // $bulk ?> 1869 1870 <div class="inline-edit-group wp-clearfix"> 1871 1872 <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?> 1873 1874 <label class="alignleft"> 1875 <input type="checkbox" name="comment_status" value="open" /> 1876 <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span> 1877 </label> 1878 1879 <?php endif; ?> 1880 1881 <?php if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?> 1882 1883 <label class="alignleft"> 1884 <input type="checkbox" name="ping_status" value="open" /> 1885 <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span> 1886 </label> 1887 1888 <?php endif; ?> 1889 1890 </div> 1891 1892 <?php endif; // $bulk ?> 1893 1894 <?php endif; // post_type_supports( ... comments or pings ) ?> 1895 1896 <div class="inline-edit-group wp-clearfix"> 1897 1898 <label class="inline-edit-status alignleft"> 1899 <span class="title"><?php _e( 'Status' ); ?></span> 1900 <select name="_status"> 1901 <?php if ( $bulk ) : ?> 1902 <option value="-1"><?php _e( '— No Change —' ); ?></option> 1903 <?php endif; // $bulk ?> 1904 1905 <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review". ?> 1906 <option value="publish"><?php _e( 'Published' ); ?></option> 1907 <option value="future"><?php _e( 'Scheduled' ); ?></option> 1908 <?php if ( $bulk ) : ?> 1909 <option value="private"><?php _e( 'Private' ); ?></option> 1910 <?php endif; // $bulk ?> 1911 <?php endif; ?> 1912 1913 <option value="pending"><?php _e( 'Pending Review' ); ?></option> 1914 <option value="draft"><?php _e( 'Draft' ); ?></option> 1915 </select> 1916 </label> 1917 1918 <?php if ( 'post' === $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?> 1919 1920 <?php if ( $bulk ) : ?> 1921 1922 <label class="alignright"> 1923 <span class="title"><?php _e( 'Sticky' ); ?></span> 1924 <select name="sticky"> 1925 <option value="-1"><?php _e( '— No Change —' ); ?></option> 1926 <option value="sticky"><?php _e( 'Sticky' ); ?></option> 1927 <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option> 1928 </select> 1929 </label> 1930 1931 <?php else : // $bulk ?> 1932 1933 <label class="alignleft"> 1934 <input type="checkbox" name="sticky" value="sticky" /> 1935 <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span> 1936 </label> 1937 1938 <?php endif; // $bulk ?> 1939 1940 <?php endif; // 'post' && $can_publish && current_user_can( 'edit_others_posts' ) ?> 1941 1942 </div> 1943 1944 <?php if ( $bulk && current_theme_supports( 'post-formats' ) && post_type_supports( $screen->post_type, 'post-formats' ) ) : ?> 1945 <?php $post_formats = get_theme_support( 'post-formats' ); ?> 1946 1947 <label class="alignleft"> 1948 <span class="title"><?php _ex( 'Format', 'post format' ); ?></span> 1949 <select name="post_format"> 1950 <option value="-1"><?php _e( '— No Change —' ); ?></option> 1951 <option value="0"><?php echo get_post_format_string( 'standard' ); ?></option> 1952 <?php if ( is_array( $post_formats[0] ) ) : ?> 1953 <?php foreach ( $post_formats[0] as $format ) : ?> 1954 <option value="<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></option> 1955 <?php endforeach; ?> 1956 <?php endif; ?> 1957 </select> 1958 </label> 1959 1960 <?php endif; ?> 1961 1962 </div> 1963 </fieldset> 1964 1965 <?php 1966 list( $columns ) = $this->get_column_info(); 1967 1968 foreach ( $columns as $column_name => $column_display_name ) { 1969 if ( isset( $core_columns[ $column_name ] ) ) { 1970 continue; 1971 } 1972 1973 if ( $bulk ) { 1974 1975 /** 1976 * Fires once for each column in Bulk Edit mode. 1977 * 1978 * @since 2.7.0 1979 * 1980 * @param string $column_name Name of the column to edit. 1981 * @param string $post_type The post type slug. 1982 */ 1983 do_action( 'bulk_edit_custom_box', $column_name, $screen->post_type ); 1984 } else { 1985 1986 /** 1987 * Fires once for each column in Quick Edit mode. 1988 * 1989 * @since 2.7.0 1990 * 1991 * @param string $column_name Name of the column to edit. 1992 * @param string $post_type The post type slug, or current screen name if this is a taxonomy list table. 1993 * @param string $taxonomy The taxonomy name, if any. 1994 */ 1995 do_action( 'quick_edit_custom_box', $column_name, $screen->post_type, '' ); 1996 } 1997 } 1998 ?> 1999 2000 <div class="submit inline-edit-save"> 2001 <button type="button" class="button cancel alignleft"><?php _e( 'Cancel' ); ?></button> 2002 2003 <?php if ( ! $bulk ) : ?> 2004 <?php wp_nonce_field( 'inlineeditnonce', '_inline_edit', false ); ?> 2005 <button type="button" class="button button-primary save alignright"><?php _e( 'Update' ); ?></button> 2006 <span class="spinner"></span> 2007 <?php else : ?> 2008 <?php submit_button( __( 'Update' ), 'primary alignright', 'bulk_edit', false ); ?> 2009 <?php endif; ?> 2010 2011 <input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" /> 2012 <input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" /> 2013 <?php if ( ! $bulk && ! post_type_supports( $screen->post_type, 'author' ) ) : ?> 2014 <input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" /> 2015 <?php endif; ?> 2016 <br class="clear" /> 2017 2018 <div class="notice notice-error notice-alt inline hidden"> 2019 <p class="error"></p> 2020 </div> 2021 </div> 2022 2023 </td></tr> 2024 2025 <?php 2026 $bulk++; 2027 endwhile; 2028 ?> 2029 </tbody></table> 2030 </form> 2031 <?php 2032 } 2033 }