3 * List Table API: WP_Posts_List_Table class
6 * @subpackage Administration
11 * Core class used to implement displaying posts in a list table.
18 class WP_Posts_List_Table extends WP_List_Table {
21 * Whether the items should be displayed hierarchically or linearly.
27 protected $hierarchical_display;
30 * Holds the number of pending comments for each post.
36 protected $comment_pending_count;
39 * Holds the number of posts for this user.
45 private $user_posts_count;
48 * Holds the number of posts which are sticky.
54 private $sticky_posts_count = 0;
59 * Current level for output.
65 protected $current_level = 0;
73 * @see WP_List_Table::__construct() for more information on default arguments.
75 * @global object $post_type_object
78 * @param array $args An associative array of arguments.
80 public function __construct( $args = array() ) {
81 global $post_type_object, $wpdb;
83 parent::__construct( array(
85 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
88 $post_type = $this->screen->post_type;
89 $post_type_object = get_post_type_object( $post_type );
91 $exclude_states = get_post_stati( array(
92 'show_in_admin_all_list' => false,
94 $this->user_posts_count = intval( $wpdb->get_var( $wpdb->prepare( "
98 AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
100 ", $post_type, get_current_user_id() ) ) );
102 if ( $this->user_posts_count && ! current_user_can( $post_type_object->cap->edit_others_posts ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) ) {
103 $_GET['author'] = get_current_user_id();
106 if ( 'post' === $post_type && $sticky_posts = get_option( 'sticky_posts' ) ) {
107 $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
108 $this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ('trash', 'auto-draft') AND ID IN ($sticky_posts)", $post_type ) );
113 * Sets whether the table layout should be hierarchical or not.
117 * @param bool $display Whether the table layout should be hierarchical.
119 public function set_hierarchical_display( $display ) {
120 $this->hierarchical_display = $display;
127 public function ajax_user_can() {
128 return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts );
133 * @global array $avail_post_stati
134 * @global WP_Query $wp_query
135 * @global int $per_page
136 * @global string $mode
138 public function prepare_items() {
139 global $avail_post_stati, $wp_query, $per_page, $mode;
141 // is going to call wp()
142 $avail_post_stati = wp_edit_posts_query();
144 $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' === $wp_query->query['orderby'] );
146 $post_type = $this->screen->post_type;
147 $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
149 /** This filter is documented in wp-admin/includes/post.php */
150 $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
152 if ( $this->hierarchical_display ) {
153 $total_items = $wp_query->post_count;
154 } elseif ( $wp_query->found_posts || $this->get_pagenum() === 1 ) {
155 $total_items = $wp_query->found_posts;
157 $post_counts = (array) wp_count_posts( $post_type, 'readable' );
159 if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'] , $avail_post_stati ) ) {
160 $total_items = $post_counts[ $_REQUEST['post_status'] ];
161 } elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) {
162 $total_items = $this->sticky_posts_count;
163 } elseif ( isset( $_GET['author'] ) && $_GET['author'] == get_current_user_id() ) {
164 $total_items = $this->user_posts_count;
166 $total_items = array_sum( $post_counts );
168 // Subtract post types that are not included in the admin all list.
169 foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
170 $total_items -= $post_counts[ $state ];
175 if ( ! empty( $_REQUEST['mode'] ) ) {
176 $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
177 set_user_setting ( 'posts_list_mode', $mode );
179 $mode = get_user_setting ( 'posts_list_mode', 'list' );
182 $this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] === 'trash';
184 $this->set_pagination_args( array(
185 'total_items' => $total_items,
186 'per_page' => $per_page
194 public function has_items() {
201 public function no_items() {
202 if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] )
203 echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash;
205 echo get_post_type_object( $this->screen->post_type )->labels->not_found;
209 * Determine if the current view is the "All" view.
213 * @return bool Whether the current view is the "All" view.
215 protected function is_base_request() {
217 unset( $vars['paged'] );
219 if ( empty( $vars ) ) {
221 } elseif ( 1 === count( $vars ) && ! empty( $vars['post_type'] ) ) {
222 return $this->screen->post_type === $vars['post_type'];
225 return 1 === count( $vars ) && ! empty( $vars['mode'] );
229 * Helper to create links to edit.php with params.
234 * @param array $args URL parameters for the link.
235 * @param string $label Link text.
236 * @param string $class Optional. Class attribute. Default empty string.
237 * @return string The formatted link string.
239 protected function get_edit_link( $args, $label, $class = '' ) {
240 $url = add_query_arg( $args, 'edit.php' );
243 if ( ! empty( $class ) ) {
244 $class_html = sprintf(
251 '<a href="%s"%s>%s</a>',
260 * @global array $locked_post_status This seems to be deprecated.
261 * @global array $avail_post_stati
264 protected function get_views() {
265 global $locked_post_status, $avail_post_stati;
267 $post_type = $this->screen->post_type;
269 if ( !empty($locked_post_status) )
272 $status_links = array();
273 $num_posts = wp_count_posts( $post_type, 'readable' );
274 $total_posts = array_sum( (array) $num_posts );
277 $current_user_id = get_current_user_id();
278 $all_args = array( 'post_type' => $post_type );
281 // Subtract post types that are not included in the admin all list.
282 foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
283 $total_posts -= $num_posts->$state;
286 if ( $this->user_posts_count && $this->user_posts_count !== $total_posts ) {
287 if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) ) {
292 'post_type' => $post_type,
293 'author' => $current_user_id
296 $mine_inner_html = sprintf(
298 'Mine <span class="count">(%s)</span>',
299 'Mine <span class="count">(%s)</span>',
300 $this->user_posts_count,
303 number_format_i18n( $this->user_posts_count )
306 $mine = $this->get_edit_link( $mine_args, $mine_inner_html, $class );
308 $all_args['all_posts'] = 1;
312 if ( empty( $class ) && ( $this->is_base_request() || isset( $_REQUEST['all_posts'] ) ) ) {
316 $all_inner_html = sprintf(
318 'All <span class="count">(%s)</span>',
319 'All <span class="count">(%s)</span>',
323 number_format_i18n( $total_posts )
326 $status_links['all'] = $this->get_edit_link( $all_args, $all_inner_html, $class );
328 $status_links['mine'] = $mine;
331 foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
334 $status_name = $status->name;
336 if ( ! in_array( $status_name, $avail_post_stati ) || empty( $num_posts->$status_name ) ) {
340 if ( isset($_REQUEST['post_status']) && $status_name === $_REQUEST['post_status'] ) {
344 $status_args = array(
345 'post_status' => $status_name,
346 'post_type' => $post_type,
349 $status_label = sprintf(
350 translate_nooped_plural( $status->label_count, $num_posts->$status_name ),
351 number_format_i18n( $num_posts->$status_name )
354 $status_links[ $status_name ] = $this->get_edit_link( $status_args, $status_label, $class );
357 if ( ! empty( $this->sticky_posts_count ) ) {
358 $class = ! empty( $_REQUEST['show_sticky'] ) ? 'current' : '';
360 $sticky_args = array(
361 'post_type' => $post_type,
365 $sticky_inner_html = sprintf(
367 'Sticky <span class="count">(%s)</span>',
368 'Sticky <span class="count">(%s)</span>',
369 $this->sticky_posts_count,
372 number_format_i18n( $this->sticky_posts_count )
375 $sticky_link = array(
376 'sticky' => $this->get_edit_link( $sticky_args, $sticky_inner_html, $class )
379 // Sticky comes after Publish, or if not listed, after All.
380 $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) );
381 $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
384 return $status_links;
391 protected function get_bulk_actions() {
393 $post_type_obj = get_post_type_object( $this->screen->post_type );
395 if ( current_user_can( $post_type_obj->cap->edit_posts ) ) {
396 if ( $this->is_trash ) {
397 $actions['untrash'] = __( 'Restore' );
399 $actions['edit'] = __( 'Edit' );
403 if ( current_user_can( $post_type_obj->cap->delete_posts ) ) {
404 if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) {
405 $actions['delete'] = __( 'Delete Permanently' );
407 $actions['trash'] = __( 'Move to Trash' );
416 * @param string $which
418 protected function extra_tablenav( $which ) {
421 <div class="alignleft actions">
423 if ( 'top' === $which && !is_singular() ) {
425 $this->months_dropdown( $this->screen->post_type );
427 if ( is_object_in_taxonomy( $this->screen->post_type, 'category' ) ) {
428 $dropdown_options = array(
429 'show_option_all' => __( 'All categories' ),
437 echo '<label class="screen-reader-text" for="cat">' . __( 'Filter by category' ) . '</label>';
438 wp_dropdown_categories( $dropdown_options );
442 * Fires before the Filter button on the Posts and Pages list tables.
444 * The Filter button allows sorting by date and/or category on the
445 * Posts list table, and sorting by date on the Pages list table.
448 * @since 4.4.0 The `$post_type` parameter was added.
450 * @param string $post_type The post type slug.
452 do_action( 'restrict_manage_posts', $this->screen->post_type );
454 submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
457 if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) ) {
458 submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
464 * Fires immediately following the closing "actions" div in the tablenav for the posts
469 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
471 do_action( 'manage_posts_extra_tablenav', $which );
478 public function current_action() {
479 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
482 return parent::current_action();
489 protected function get_table_classes() {
490 return array( 'widefat', 'fixed', 'striped', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
497 public function get_columns() {
498 $post_type = $this->screen->post_type;
500 $posts_columns = array();
502 $posts_columns['cb'] = '<input type="checkbox" />';
504 /* translators: manage posts column name */
505 $posts_columns['title'] = _x( 'Title', 'column name' );
507 if ( post_type_supports( $post_type, 'author' ) ) {
508 $posts_columns['author'] = __( 'Author' );
511 $taxonomies = get_object_taxonomies( $post_type, 'objects' );
512 $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
515 * Filter the taxonomy columns in the Posts list table.
517 * The dynamic portion of the hook name, `$post_type`, refers to the post
522 * @param array $taxonomies Array of taxonomies to show columns for.
523 * @param string $post_type The post type.
525 $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
526 $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
528 foreach ( $taxonomies as $taxonomy ) {
529 if ( 'category' === $taxonomy )
530 $column_key = 'categories';
531 elseif ( 'post_tag' === $taxonomy )
532 $column_key = 'tags';
534 $column_key = 'taxonomy-' . $taxonomy;
536 $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
539 $post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
540 if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) )
541 $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>';
543 $posts_columns['date'] = __( 'Date' );
545 if ( 'page' === $post_type ) {
548 * Filter the columns displayed in the Pages list table.
552 * @param array $post_columns An array of column names.
554 $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
558 * Filter the columns displayed in the Posts list table.
562 * @param array $posts_columns An array of column names.
563 * @param string $post_type The post type slug.
565 $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
569 * Filter the columns displayed in the Posts list table for a specific post type.
571 * The dynamic portion of the hook name, `$post_type`, refers to the post type slug.
575 * @param array $post_columns An array of column names.
577 return apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
584 protected function get_sortable_columns() {
587 'parent' => 'parent',
588 'comments' => 'comment_count',
589 'date' => array( 'date', true )
594 * @global WP_Query $wp_query
595 * @global int $per_page
596 * @param array $posts
599 public function display_rows( $posts = array(), $level = 0 ) {
600 global $wp_query, $per_page;
602 if ( empty( $posts ) )
603 $posts = $wp_query->posts;
605 add_filter( 'the_title', 'esc_html' );
607 if ( $this->hierarchical_display ) {
608 $this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page );
610 $this->_display_rows( $posts, $level );
615 * @param array $posts
618 private function _display_rows( $posts, $level = 0 ) {
619 // Create array of post IDs.
622 foreach ( $posts as $a_post )
623 $post_ids[] = $a_post->ID;
625 $this->comment_pending_count = get_pending_comments_num( $post_ids );
627 foreach ( $posts as $post )
628 $this->single_row( $post, $level );
633 * @global WP_Post $post
634 * @param array $pages
635 * @param int $pagenum
636 * @param int $per_page
638 private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
644 $pages = get_pages( array( 'sort_column' => 'menu_order' ) );
651 * Arrange pages into two parts: top level pages and children_pages
652 * children_pages is two dimensional array, eg.
653 * children_pages[10][] contains all sub-pages whose parent is 10.
654 * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations
655 * If searching, ignore hierarchy and treat everything as top level
657 if ( empty( $_REQUEST['s'] ) ) {
659 $top_level_pages = array();
660 $children_pages = array();
662 foreach ( $pages as $page ) {
664 // Catch and repair bad pages.
665 if ( $page->post_parent == $page->ID ) {
666 $page->post_parent = 0;
667 $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
668 clean_post_cache( $page );
671 if ( 0 == $page->post_parent )
672 $top_level_pages[] = $page;
674 $children_pages[ $page->post_parent ][] = $page;
677 $pages = &$top_level_pages;
681 $start = ( $pagenum - 1 ) * $per_page;
682 $end = $start + $per_page;
683 $to_display = array();
685 foreach ( $pages as $page ) {
686 if ( $count >= $end )
689 if ( $count >= $start ) {
690 $to_display[$page->ID] = $level;
695 if ( isset( $children_pages ) )
696 $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
699 // If it is the last pagenum and there are orphaned pages, display them with paging as well.
700 if ( isset( $children_pages ) && $count < $end ){
701 foreach ( $children_pages as $orphans ){
702 foreach ( $orphans as $op ) {
703 if ( $count >= $end )
706 if ( $count >= $start ) {
707 $to_display[$op->ID] = 0;
715 $ids = array_keys( $to_display );
716 _prime_post_caches( $ids );
718 if ( ! isset( $GLOBALS['post'] ) ) {
719 $GLOBALS['post'] = reset( $ids );
722 foreach ( $to_display as $page_id => $level ) {
724 $this->single_row( $page_id, $level );
729 * Given a top level page ID, display the nested hierarchy of sub-pages
730 * together with paging support
732 * @since 3.1.0 (Standalone function exists since 2.6.0)
733 * @since 4.2.0 Added the `$to_display` parameter.
735 * @param array $children_pages
739 * @param int $pagenum
740 * @param int $per_page
741 * @param array $to_display List of pages to be displayed. Passed by reference.
743 private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) {
744 if ( ! isset( $children_pages[$parent] ) )
747 $start = ( $pagenum - 1 ) * $per_page;
748 $end = $start + $per_page;
750 foreach ( $children_pages[$parent] as $page ) {
751 if ( $count >= $end )
754 // If the page starts in a subtree, print the parents.
755 if ( $count == $start && $page->post_parent > 0 ) {
756 $my_parents = array();
757 $my_parent = $page->post_parent;
758 while ( $my_parent ) {
759 // Get the ID from the list or the attribute if my_parent is an object
760 $parent_id = $my_parent;
761 if ( is_object( $my_parent ) ) {
762 $parent_id = $my_parent->ID;
765 $my_parent = get_post( $parent_id );
766 $my_parents[] = $my_parent;
767 if ( !$my_parent->post_parent )
769 $my_parent = $my_parent->post_parent;
771 $num_parents = count( $my_parents );
772 while ( $my_parent = array_pop( $my_parents ) ) {
773 $to_display[$my_parent->ID] = $level - $num_parents;
778 if ( $count >= $start ) {
779 $to_display[$page->ID] = $level;
784 $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
787 unset( $children_pages[$parent] ); //required in order to keep track of orphans
791 * Handles the checkbox column output.
796 * @param WP_Post $post The current WP_Post object.
798 public function column_cb( $post ) {
799 if ( current_user_can( 'edit_post', $post->ID ) ): ?>
800 <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php
801 printf( __( 'Select %s' ), _draft_or_post_title() );
803 <input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" />
804 <div class="locked-indicator"></div>
812 * @param WP_Post $post
813 * @param string $classes
814 * @param string $data
815 * @param string $primary
817 protected function _column_title( $post, $classes, $data, $primary ) {
818 echo '<td class="' . $classes . ' page-title" ', $data, '>';
819 echo $this->column_title( $post );
820 echo $this->handle_row_actions( $post, 'title', $primary );
825 * Handles the title column output.
830 * @global string $mode
832 * @param WP_Post $post The current WP_Post object.
834 public function column_title( $post ) {
837 if ( $this->hierarchical_display ) {
838 if ( 0 === $this->current_level && (int) $post->post_parent > 0 ) {
839 // Sent level 0 by accident, by default, or because we don't know the actual level.
840 $find_main_page = (int) $post->post_parent;
841 while ( $find_main_page > 0 ) {
842 $parent = get_post( $find_main_page );
844 if ( is_null( $parent ) ) {
848 $this->current_level++;
849 $find_main_page = (int) $parent->post_parent;
851 if ( ! isset( $parent_name ) ) {
852 /** This filter is documented in wp-includes/post-template.php */
853 $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
859 $pad = str_repeat( '— ', $this->current_level );
862 $format = get_post_format( $post->ID );
864 $label = get_post_format_string( $format );
866 $format_class = 'post-state-format post-format-icon post-format-' . $format;
868 $format_args = array(
869 'post_format' => $format,
870 'post_type' => $post->post_type
873 echo $this->get_edit_link( $format_args, $label . ':', $format_class );
876 $can_edit_post = current_user_can( 'edit_post', $post->ID );
877 $title = _draft_or_post_title();
879 if ( $can_edit_post && $post->post_status != 'trash' ) {
880 $edit_link = get_edit_post_link( $post->ID );
881 echo '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . $pad . $title . '</a>';
885 _post_states( $post );
887 if ( isset( $parent_name ) ) {
888 $post_type_object = get_post_type_object( $post->post_type );
889 echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
893 if ( $can_edit_post && $post->post_status != 'trash' ) {
894 $lock_holder = wp_check_post_lock( $post->ID );
896 if ( $lock_holder ) {
897 $lock_holder = get_userdata( $lock_holder );
898 $locked_avatar = get_avatar( $lock_holder->ID, 18 );
899 $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
901 $locked_avatar = $locked_text = '';
904 echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
907 if ( ! is_post_type_hierarchical( $this->screen->post_type ) && 'excerpt' === $mode && current_user_can( 'read_post', $post->ID ) ) {
911 get_inline_data( $post );
915 * Handles the post date column output.
920 * @global string $mode
922 * @param WP_Post $post The current WP_Post object.
924 public function column_date( $post ) {
927 if ( '0000-00-00 00:00:00' === $post->post_date ) {
928 $t_time = $h_time = __( 'Unpublished' );
931 $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
932 $m_time = $post->post_date;
933 $time = get_post_time( 'G', true, $post );
935 $time_diff = time() - $time;
937 if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
938 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
940 $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
944 if ( 'publish' === $post->post_status ) {
946 } elseif ( 'future' === $post->post_status ) {
947 if ( $time_diff > 0 ) {
948 echo '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>';
953 _e( 'Last Modified' );
956 if ( 'excerpt' === $mode ) {
958 * Filter the published time of the post.
960 * If `$mode` equals 'excerpt', the published time and date are both displayed.
961 * If `$mode` equals 'list' (default), the publish date is displayed, with the
962 * time and date together available as an abbreviation definition.
966 * @param string $t_time The published time.
967 * @param WP_Post $post Post object.
968 * @param string $column_name The column name.
969 * @param string $mode The list display mode ('excerpt' or 'list').
971 echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
974 /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
975 echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . '</abbr>';
980 * Handles the comments column output.
985 * @param WP_Post $post The current WP_Post object.
987 public function column_comments( $post ) {
989 <div class="post-com-count-wrapper">
991 $pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0;
993 $this->comments_bubble( $post->ID, $pending_comments );
1000 * Handles the post author column output.
1005 * @param WP_Post $post The current WP_Post object.
1007 public function column_author( $post ) {
1009 'post_type' => $post->post_type,
1010 'author' => get_the_author_meta( 'ID' )
1012 echo $this->get_edit_link( $args, get_the_author() );
1016 * Handles the default column output.
1021 * @param WP_Post $post The current WP_Post object.
1022 * @param string $column_name The current column name.
1024 public function column_default( $post, $column_name ) {
1025 if ( 'categories' === $column_name ) {
1026 $taxonomy = 'category';
1027 } elseif ( 'tags' === $column_name ) {
1028 $taxonomy = 'post_tag';
1029 } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) {
1030 $taxonomy = substr( $column_name, 9 );
1035 $taxonomy_object = get_taxonomy( $taxonomy );
1036 $terms = get_the_terms( $post->ID, $taxonomy );
1037 if ( is_array( $terms ) ) {
1039 foreach ( $terms as $t ) {
1040 $posts_in_term_qv = array();
1041 if ( 'post' != $post->post_type ) {
1042 $posts_in_term_qv['post_type'] = $post->post_type;
1044 if ( $taxonomy_object->query_var ) {
1045 $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
1047 $posts_in_term_qv['taxonomy'] = $taxonomy;
1048 $posts_in_term_qv['term'] = $t->slug;
1051 $label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) );
1052 $out[] = $this->get_edit_link( $posts_in_term_qv, $label );
1054 /* translators: used between list items, there is a space after the comma */
1055 echo join( __( ', ' ), $out );
1057 echo '<span aria-hidden="true">—</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
1062 if ( is_post_type_hierarchical( $post->post_type ) ) {
1065 * Fires in each custom column on the Posts list table.
1067 * This hook only fires if the current post type is hierarchical,
1072 * @param string $column_name The name of the column to display.
1073 * @param int $post_id The current post ID.
1075 do_action( 'manage_pages_custom_column', $column_name, $post->ID );
1079 * Fires in each custom column in the Posts list table.
1081 * This hook only fires if the current post type is non-hierarchical,
1086 * @param string $column_name The name of the column to display.
1087 * @param int $post_id The current post ID.
1089 do_action( 'manage_posts_custom_column', $column_name, $post->ID );
1093 * Fires for each custom column of a specific post type in the Posts list table.
1095 * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
1099 * @param string $column_name The name of the column to display.
1100 * @param int $post_id The current post ID.
1102 do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
1106 * @global WP_Post $post
1108 * @param int|WP_Post $post
1111 public function single_row( $post, $level = 0 ) {
1112 $global_post = get_post();
1114 $post = get_post( $post );
1115 $this->current_level = $level;
1117 $GLOBALS['post'] = $post;
1118 setup_postdata( $post );
1120 $classes = 'iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
1122 $lock_holder = wp_check_post_lock( $post->ID );
1123 if ( $lock_holder ) {
1124 $classes .= ' wp-locked';
1127 if ( $post->post_parent ) {
1128 $count = count( get_post_ancestors( $post->ID ) );
1129 $classes .= ' level-'. $count;
1131 $classes .= ' level-0';
1134 <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>">
1135 <?php $this->single_row_columns( $post ); ?>
1138 $GLOBALS['post'] = $global_post;
1142 * Gets the name of the default primary column.
1147 * @return string Name of the default primary column, in this case, 'title'.
1149 protected function get_default_primary_column_name() {
1154 * Generates and displays row action links.
1159 * @param object $post Post being acted upon.
1160 * @param string $column_name Current column name.
1161 * @param string $primary Primary column name.
1162 * @return string Row actions output for posts.
1164 protected function handle_row_actions( $post, $column_name, $primary ) {
1165 if ( $primary !== $column_name ) {
1169 $post_type_object = get_post_type_object( $post->post_type );
1170 $can_edit_post = current_user_can( 'edit_post', $post->ID );
1173 if ( $can_edit_post && 'trash' != $post->post_status ) {
1174 $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . esc_attr__( 'Edit this item' ) . '">' . __( 'Edit' ) . '</a>';
1175 $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr__( 'Edit this item inline' ) . '">' . __( 'Quick Edit' ) . '</a>';
1178 if ( current_user_can( 'delete_post', $post->ID ) ) {
1179 if ( 'trash' === $post->post_status )
1180 $actions['untrash'] = "<a title='" . esc_attr__( 'Restore this item from the Trash' ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";
1181 elseif ( EMPTY_TRASH_DAYS )
1182 $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash' ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
1183 if ( 'trash' === $post->post_status || !EMPTY_TRASH_DAYS )
1184 $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently' ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
1187 if ( is_post_type_viewable( $post_type_object ) ) {
1188 $title = _draft_or_post_title();
1189 if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
1190 if ( $can_edit_post ) {
1191 $unpublished_link = set_url_scheme( get_permalink( $post ) );
1192 $preview_link = get_preview_post_link( $post, array(), $unpublished_link );
1193 $actions['view'] = '<a href="' . esc_url( $preview_link ) . '" title="' . esc_attr( sprintf( __( 'Preview “%s”' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';
1195 } elseif ( 'trash' != $post->post_status ) {
1196 $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
1200 if ( is_post_type_hierarchical( $post->post_type ) ) {
1203 * Filter the array of row action links on the Pages list table.
1205 * The filter is evaluated only for hierarchical post types.
1209 * @param array $actions An array of row action links. Defaults are
1210 * 'Edit', 'Quick Edit', 'Restore, 'Trash',
1211 * 'Delete Permanently', 'Preview', and 'View'.
1212 * @param WP_Post $post The post object.
1214 $actions = apply_filters( 'page_row_actions', $actions, $post );
1218 * Filter the array of row action links on the Posts list table.
1220 * The filter is evaluated only for non-hierarchical post types.
1224 * @param array $actions An array of row action links. Defaults are
1225 * 'Edit', 'Quick Edit', 'Restore, 'Trash',
1226 * 'Delete Permanently', 'Preview', and 'View'.
1227 * @param WP_Post $post The post object.
1229 $actions = apply_filters( 'post_row_actions', $actions, $post );
1232 return $this->row_actions( $actions );
1236 * Outputs the hidden row displayed when inline editing
1240 * @global string $mode
1242 public function inline_edit() {
1245 $screen = $this->screen;
1247 $post = get_default_post_to_edit( $screen->post_type );
1248 $post_type_object = get_post_type_object( $screen->post_type );
1250 $taxonomy_names = get_object_taxonomies( $screen->post_type );
1251 $hierarchical_taxonomies = array();
1252 $flat_taxonomies = array();
1253 foreach ( $taxonomy_names as $taxonomy_name ) {
1255 $taxonomy = get_taxonomy( $taxonomy_name );
1257 $show_in_quick_edit = $taxonomy->show_in_quick_edit;
1260 * Filter whether the current taxonomy should be shown in the Quick Edit panel.
1264 * @param bool $show_in_quick_edit Whether to show the current taxonomy in Quick Edit.
1265 * @param string $taxonomy_name Taxonomy name.
1266 * @param string $post_type Post type of current Quick Edit post.
1268 if ( ! apply_filters( 'quick_edit_show_taxonomy', $show_in_quick_edit, $taxonomy_name, $screen->post_type ) ) {
1272 if ( $taxonomy->hierarchical )
1273 $hierarchical_taxonomies[] = $taxonomy;
1275 $flat_taxonomies[] = $taxonomy;
1278 $m = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list';
1279 $can_publish = current_user_can( $post_type_object->cap->publish_posts );
1280 $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
1284 <form method="get"><table style="display: none"><tbody id="inlineedit">
1286 $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page';
1288 while ( $bulk < 2 ) { ?>
1290 <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-" . $screen->post_type;
1291 echo $bulk ? " bulk-edit-row bulk-edit-row-$hclass bulk-edit-{$screen->post_type}" : " quick-edit-row quick-edit-row-$hclass inline-edit-{$screen->post_type}";
1292 ?>" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
1294 <fieldset class="inline-edit-col-left">
1295 <legend class="inline-edit-legend"><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></legend>
1296 <div class="inline-edit-col">
1299 if ( post_type_supports( $screen->post_type, 'title' ) ) :
1301 <div id="bulk-title-div">
1302 <div id="bulk-titles"></div>
1305 <?php else : // $bulk ?>
1308 <span class="title"><?php _e( 'Title' ); ?></span>
1309 <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span>
1313 <span class="title"><?php _e( 'Slug' ); ?></span>
1314 <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span>
1317 <?php endif; // $bulk
1318 endif; // post_type_supports title ?>
1320 <?php if ( !$bulk ) : ?>
1321 <fieldset class="inline-edit-date">
1322 <legend><span class="title"><?php _e( 'Date' ); ?></span></legend>
1323 <?php touch_time( 1, 1, 0, 1 ); ?>
1325 <br class="clear" />
1326 <?php endif; // $bulk
1328 if ( post_type_supports( $screen->post_type, 'author' ) ) :
1329 $authors_dropdown = '';
1331 if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) :
1333 'hide_if_only_one_author' => false,
1335 'name' => 'post_author',
1336 'class'=> 'authors',
1341 $users_opt['show_option_none'] = __( '— No Change —' );
1343 if ( $authors = wp_dropdown_users( $users_opt ) ) :
1344 $authors_dropdown = '<label class="inline-edit-author">';
1345 $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
1346 $authors_dropdown .= $authors;
1347 $authors_dropdown .= '</label>';
1352 <?php if ( !$bulk ) echo $authors_dropdown;
1353 endif; // post_type_supports author
1355 if ( !$bulk && $can_publish ) :
1358 <div class="inline-edit-group">
1359 <label class="alignleft">
1360 <span class="title"><?php _e( 'Password' ); ?></span>
1361 <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
1364 <em class="alignleft inline-edit-or">
1366 /* translators: Between password field and private checkbox on post quick edit interface */
1367 _e( '–OR–' );
1370 <label class="alignleft inline-edit-private">
1371 <input type="checkbox" name="keep_private" value="private" />
1372 <span class="checkbox-title"><?php _e( 'Private' ); ?></span>
1380 <?php if ( count( $hierarchical_taxonomies ) && !$bulk ) : ?>
1382 <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col">
1384 <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?>
1386 <span class="title inline-edit-categories-label"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
1387 <input type="hidden" name="<?php echo ( $taxonomy->name === 'category' ) ? 'post_category[]' : 'tax_input[' . esc_attr( $taxonomy->name ) . '][]'; ?>" value="0" />
1388 <ul class="cat-checklist <?php echo esc_attr( $taxonomy->name )?>-checklist">
1389 <?php wp_terms_checklist( null, array( 'taxonomy' => $taxonomy->name ) ) ?>
1392 <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?>
1396 <?php endif; // count( $hierarchical_taxonomies ) && !$bulk ?>
1398 <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
1401 if ( post_type_supports( $screen->post_type, 'author' ) && $bulk )
1402 echo $authors_dropdown;
1404 if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) :
1406 if ( $post_type_object->hierarchical ) :
1409 <span class="title"><?php _e( 'Parent' ); ?></span>
1411 $dropdown_args = array(
1412 'post_type' => $post_type_object->name,
1413 'selected' => $post->post_parent,
1414 'name' => 'post_parent',
1415 'show_option_none' => __( 'Main Page (no parent)' ),
1416 'option_none_value' => 0,
1417 'sort_column' => 'menu_order, post_title',
1421 $dropdown_args['show_option_no_change'] = __( '— No Change —' );
1424 * Filter the arguments used to generate the Quick Edit page-parent drop-down.
1428 * @see wp_dropdown_pages()
1430 * @param array $dropdown_args An array of arguments.
1432 $dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args );
1434 wp_dropdown_pages( $dropdown_args );
1439 endif; // hierarchical
1444 <span class="title"><?php _e( 'Order' ); ?></span>
1445 <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order ?>" /></span>
1448 <?php endif; // !$bulk
1450 if ( 'page' === $screen->post_type ) :
1454 <span class="title"><?php _e( 'Template' ); ?></span>
1455 <select name="page_template">
1456 <?php if ( $bulk ) : ?>
1457 <option value="-1"><?php _e( '— No Change —' ); ?></option>
1458 <?php endif; // $bulk ?>
1460 /** This filter is documented in wp-admin/includes/meta-boxes.php */
1461 $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'quick-edit' );
1463 <option value="default"><?php echo esc_html( $default_title ); ?></option>
1464 <?php page_template_dropdown() ?>
1469 endif; // page post_type
1470 endif; // page-attributes
1473 <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?>
1475 <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
1476 <?php if ( current_user_can( $taxonomy->cap->assign_terms ) ) : ?>
1477 <label class="inline-edit-tags">
1478 <span class="title"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
1479 <textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr( $taxonomy->name )?>]" class="tax_input_<?php echo esc_attr( $taxonomy->name )?>"></textarea>
1483 <?php endforeach; //$flat_taxonomies as $taxonomy ?>
1485 <?php endif; // count( $flat_taxonomies ) && !$bulk ?>
1487 <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) :
1490 <div class="inline-edit-group">
1491 <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
1492 <label class="alignleft">
1493 <span class="title"><?php _e( 'Comments' ); ?></span>
1494 <select name="comment_status">
1495 <option value=""><?php _e( '— No Change —' ); ?></option>
1496 <option value="open"><?php _e( 'Allow' ); ?></option>
1497 <option value="closed"><?php _e( 'Do not allow' ); ?></option>
1500 <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
1501 <label class="alignright">
1502 <span class="title"><?php _e( 'Pings' ); ?></span>
1503 <select name="ping_status">
1504 <option value=""><?php _e( '— No Change —' ); ?></option>
1505 <option value="open"><?php _e( 'Allow' ); ?></option>
1506 <option value="closed"><?php _e( 'Do not allow' ); ?></option>
1512 <?php else : // $bulk ?>
1514 <div class="inline-edit-group">
1515 <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
1516 <label class="alignleft">
1517 <input type="checkbox" name="comment_status" value="open" />
1518 <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span>
1520 <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
1521 <label class="alignleft">
1522 <input type="checkbox" name="ping_status" value="open" />
1523 <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span>
1528 <?php endif; // $bulk
1529 endif; // post_type_supports comments or pings ?>
1531 <div class="inline-edit-group">
1532 <label class="inline-edit-status alignleft">
1533 <span class="title"><?php _e( 'Status' ); ?></span>
1534 <select name="_status">
1535 <?php if ( $bulk ) : ?>
1536 <option value="-1"><?php _e( '— No Change —' ); ?></option>
1537 <?php endif; // $bulk ?>
1538 <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?>
1539 <option value="publish"><?php _e( 'Published' ); ?></option>
1540 <option value="future"><?php _e( 'Scheduled' ); ?></option>
1541 <?php if ( $bulk ) : ?>
1542 <option value="private"><?php _e( 'Private' ) ?></option>
1543 <?php endif; // $bulk ?>
1545 <option value="pending"><?php _e( 'Pending Review' ); ?></option>
1546 <option value="draft"><?php _e( 'Draft' ); ?></option>
1550 <?php if ( 'post' === $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?>
1552 <?php if ( $bulk ) : ?>
1554 <label class="alignright">
1555 <span class="title"><?php _e( 'Sticky' ); ?></span>
1556 <select name="sticky">
1557 <option value="-1"><?php _e( '— No Change —' ); ?></option>
1558 <option value="sticky"><?php _e( 'Sticky' ); ?></option>
1559 <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option>
1563 <?php else : // $bulk ?>
1565 <label class="alignleft">
1566 <input type="checkbox" name="sticky" value="sticky" />
1567 <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span>
1570 <?php endif; // $bulk ?>
1572 <?php endif; // 'post' && $can_publish && current_user_can( 'edit_others_cap' ) ?>
1578 if ( $bulk && current_theme_supports( 'post-formats' ) && post_type_supports( $screen->post_type, 'post-formats' ) ) {
1579 $post_formats = get_theme_support( 'post-formats' );
1582 <label class="alignleft">
1583 <span class="title"><?php _ex( 'Format', 'post format' ); ?></span>
1584 <select name="post_format">
1585 <option value="-1"><?php _e( '— No Change —' ); ?></option>
1586 <option value="0"><?php echo get_post_format_string( 'standard' ); ?></option>
1588 if ( is_array( $post_formats[0] ) ) {
1589 foreach ( $post_formats[0] as $format ) {
1591 <option value="<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></option>
1606 list( $columns ) = $this->get_column_info();
1608 foreach ( $columns as $column_name => $column_display_name ) {
1609 if ( isset( $core_columns[$column_name] ) )
1615 * Fires once for each column in Bulk Edit mode.
1619 * @param string $column_name Name of the column to edit.
1620 * @param WP_Post $post_type The post type slug.
1622 do_action( 'bulk_edit_custom_box', $column_name, $screen->post_type );
1626 * Fires once for each column in Quick Edit mode.
1630 * @param string $column_name Name of the column to edit.
1631 * @param string $post_type The post type slug.
1633 do_action( 'quick_edit_custom_box', $column_name, $screen->post_type );
1638 <p class="submit inline-edit-save">
1639 <button type="button" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></button>
1640 <?php if ( ! $bulk ) {
1641 wp_nonce_field( 'inlineeditnonce', '_inline_edit', false );
1643 <button type="button" class="button-primary save alignright"><?php _e( 'Update' ); ?></button>
1644 <span class="spinner"></span>
1646 submit_button( __( 'Update' ), 'button-primary alignright', 'bulk_edit', false );
1648 <input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" />
1649 <input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" />
1650 <?php if ( ! $bulk && ! post_type_supports( $screen->post_type, 'author' ) ) { ?>
1651 <input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
1653 <span class="error" style="display:none"></span>
1654 <br class="clear" />
1661 </tbody></table></form>