3 * Posts List Table class.
6 * @subpackage List_Table
10 class WP_Posts_List_Table extends WP_List_Table {
13 * Whether the items should be displayed hierarchically or linearly
19 protected $hierarchical_display;
22 * Holds the number of pending comments for each post
28 protected $comment_pending_count;
31 * Holds the number of posts for this user
37 private $user_posts_count;
40 * Holds the number of posts which are sticky.
46 private $sticky_posts_count = 0;
56 * @see WP_List_Table::__construct() for more information on default arguments.
58 * @param array $args An associative array of arguments.
60 public function __construct( $args = array() ) {
61 global $post_type_object, $wpdb;
63 parent::__construct( array(
65 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
68 $post_type = $this->screen->post_type;
69 $post_type_object = get_post_type_object( $post_type );
71 if ( !current_user_can( $post_type_object->cap->edit_others_posts ) ) {
72 $exclude_states = get_post_stati( array( 'show_in_admin_all_list' => false ) );
73 $this->user_posts_count = $wpdb->get_var( $wpdb->prepare( "
74 SELECT COUNT( 1 ) FROM $wpdb->posts
75 WHERE post_type = %s AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
77 ", $post_type, get_current_user_id() ) );
79 if ( $this->user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) )
80 $_GET['author'] = get_current_user_id();
83 if ( 'post' == $post_type && $sticky_posts = get_option( 'sticky_posts' ) ) {
84 $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
85 $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 ) );
90 * Sets whether the table layout should be hierarchical or not.
94 * @param bool $display Whether the table layout should be hierarchical.
96 public function set_hierarchical_display( $display ) {
97 $this->hierarchical_display = $display;
100 public function ajax_user_can() {
101 return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts );
104 public function prepare_items() {
105 global $avail_post_stati, $wp_query, $per_page, $mode;
107 $avail_post_stati = wp_edit_posts_query();
109 $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' == $wp_query->query['orderby'] );
111 $total_items = $this->hierarchical_display ? $wp_query->post_count : $wp_query->found_posts;
113 $post_type = $this->screen->post_type;
114 $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
116 /** This filter is documented in wp-admin/includes/post.php */
117 $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
119 if ( $this->hierarchical_display )
120 $total_pages = ceil( $total_items / $per_page );
122 $total_pages = $wp_query->max_num_pages;
124 if ( ! empty( $_REQUEST['mode'] ) ) {
125 $mode = $_REQUEST['mode'] == 'excerpt' ? 'excerpt' : 'list';
126 set_user_setting ( 'posts_list_mode', $mode );
128 $mode = get_user_setting ( 'posts_list_mode', 'list' );
131 $this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] == 'trash';
133 $this->set_pagination_args( array(
134 'total_items' => $total_items,
135 'total_pages' => $total_pages,
136 'per_page' => $per_page
140 public function has_items() {
144 public function no_items() {
145 if ( isset( $_REQUEST['post_status'] ) && 'trash' == $_REQUEST['post_status'] )
146 echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash;
148 echo get_post_type_object( $this->screen->post_type )->labels->not_found;
152 * Determine if the current view is the "All" view.
156 * @return bool Whether the current ivew is the "All" view.
158 protected function is_base_request() {
159 if ( empty( $_GET ) ) {
161 } elseif ( 1 === count( $_GET ) && ! empty( $_GET['post_type'] ) ) {
162 return $this->screen->post_type === $_GET['post_type'];
166 protected function get_views() {
167 global $locked_post_status, $avail_post_stati;
169 $post_type = $this->screen->post_type;
171 if ( !empty($locked_post_status) )
174 $status_links = array();
175 $num_posts = wp_count_posts( $post_type, 'readable' );
179 $current_user_id = get_current_user_id();
181 if ( $this->user_posts_count ) {
182 if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) )
183 $class = ' class="current"';
184 $status_links['mine'] = "<a href='edit.php?post_type=$post_type&author=$current_user_id'$class>" . sprintf( _nx( 'Mine <span class="count">(%s)</span>', 'Mine <span class="count">(%s)</span>', $this->user_posts_count, 'posts' ), number_format_i18n( $this->user_posts_count ) ) . '</a>';
185 $allposts = '&all_posts=1';
189 $total_posts = array_sum( (array) $num_posts );
191 // Subtract post types that are not included in the admin all list.
192 foreach ( get_post_stati( array('show_in_admin_all_list' => false) ) as $state )
193 $total_posts -= $num_posts->$state;
195 if ( empty( $class ) && $this->is_base_request() && ! $this->user_posts_count ) {
196 $class = ' class="current"';
199 $all_inner_html = sprintf(
201 'All <span class="count">(%s)</span>',
202 'All <span class="count">(%s)</span>',
206 number_format_i18n( $total_posts )
209 $status_links['all'] = "<a href='edit.php?post_type=$post_type{$allposts}'$class>" . $all_inner_html . '</a>';
211 foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
214 $status_name = $status->name;
216 if ( !in_array( $status_name, $avail_post_stati ) )
219 if ( empty( $num_posts->$status_name ) )
222 if ( isset($_REQUEST['post_status']) && $status_name == $_REQUEST['post_status'] )
223 $class = ' class="current"';
225 $status_links[$status_name] = "<a href='edit.php?post_status=$status_name&post_type=$post_type'$class>" . sprintf( translate_nooped_plural( $status->label_count, $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '</a>';
228 if ( ! empty( $this->sticky_posts_count ) ) {
229 $class = ! empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : '';
231 $sticky_link = array( 'sticky' => "<a href='edit.php?post_type=$post_type&show_sticky=1'$class>" . sprintf( _nx( 'Sticky <span class="count">(%s)</span>', 'Sticky <span class="count">(%s)</span>', $this->sticky_posts_count, 'posts' ), number_format_i18n( $this->sticky_posts_count ) ) . '</a>' );
233 // Sticky comes after Publish, or if not listed, after All.
234 $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) );
235 $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
238 return $status_links;
241 protected function get_bulk_actions() {
243 $post_type_obj = get_post_type_object( $this->screen->post_type );
245 if ( $this->is_trash ) {
246 $actions['untrash'] = __( 'Restore' );
248 $actions['edit'] = __( 'Edit' );
251 if ( current_user_can( $post_type_obj->cap->delete_posts ) ) {
252 if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) {
253 $actions['delete'] = __( 'Delete Permanently' );
255 $actions['trash'] = __( 'Move to Trash' );
264 * @param string $which
266 protected function extra_tablenav( $which ) {
269 <div class="alignleft actions">
271 if ( 'top' == $which && !is_singular() ) {
273 $this->months_dropdown( $this->screen->post_type );
275 if ( is_object_in_taxonomy( $this->screen->post_type, 'category' ) ) {
276 $dropdown_options = array(
277 'show_option_all' => __( 'All categories' ),
285 echo '<label class="screen-reader-text" for="cat">' . __( 'Filter by category' ) . '</label>';
286 wp_dropdown_categories( $dropdown_options );
290 * Fires before the Filter button on the Posts and Pages list tables.
292 * The Filter button allows sorting by date and/or category on the
293 * Posts list table, and sorting by date on the Pages list table.
297 do_action( 'restrict_manage_posts' );
299 submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
302 if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) ) {
303 submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
310 public function current_action() {
311 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
314 return parent::current_action();
318 * @global string $mode
319 * @param string $which
321 protected function pagination( $which ) {
324 parent::pagination( $which );
326 if ( 'top' == $which && ! is_post_type_hierarchical( $this->screen->post_type ) )
327 $this->view_switcher( $mode );
330 protected function get_table_classes() {
331 return array( 'widefat', 'fixed', 'striped', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
334 public function get_columns() {
335 $post_type = $this->screen->post_type;
337 $posts_columns = array();
339 $posts_columns['cb'] = '<input type="checkbox" />';
341 /* translators: manage posts column name */
342 $posts_columns['title'] = _x( 'Title', 'column name' );
344 if ( post_type_supports( $post_type, 'author' ) ) {
345 $posts_columns['author'] = __( 'Author' );
348 $taxonomies = get_object_taxonomies( $post_type, 'objects' );
349 $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
352 * Filter the taxonomy columns in the Posts list table.
354 * The dynamic portion of the hook name, `$post_type`, refers to the post
359 * @param array $taxonomies Array of taxonomies to show columns for.
360 * @param string $post_type The post type.
362 $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
363 $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
365 foreach ( $taxonomies as $taxonomy ) {
366 if ( 'category' == $taxonomy )
367 $column_key = 'categories';
368 elseif ( 'post_tag' == $taxonomy )
369 $column_key = 'tags';
371 $column_key = 'taxonomy-' . $taxonomy;
373 $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
376 $post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
377 if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) )
378 $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>';
380 $posts_columns['date'] = __( 'Date' );
382 if ( 'page' == $post_type ) {
385 * Filter the columns displayed in the Pages list table.
389 * @param array $post_columns An array of column names.
391 $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
395 * Filter the columns displayed in the Posts list table.
399 * @param array $posts_columns An array of column names.
400 * @param string $post_type The post type slug.
402 $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
406 * Filter the columns displayed in the Posts list table for a specific post type.
408 * The dynamic portion of the hook name, `$post_type`, refers to the post type slug.
412 * @param array $post_columns An array of column names.
414 $posts_columns = apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
416 return $posts_columns;
419 protected function get_sortable_columns() {
422 'parent' => 'parent',
423 'comments' => 'comment_count',
424 'date' => array( 'date', true )
429 * @global WP_Query $wp_query
430 * @global int $per_page
431 * @param array $posts
434 public function display_rows( $posts = array(), $level = 0 ) {
435 global $wp_query, $per_page;
437 if ( empty( $posts ) )
438 $posts = $wp_query->posts;
440 add_filter( 'the_title', 'esc_html' );
442 if ( $this->hierarchical_display ) {
443 $this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page );
445 $this->_display_rows( $posts, $level );
450 * @global string $mode
451 * @param array $posts
454 private function _display_rows( $posts, $level = 0 ) {
457 // Create array of post IDs.
460 foreach ( $posts as $a_post )
461 $post_ids[] = $a_post->ID;
463 $this->comment_pending_count = get_pending_comments_num( $post_ids );
465 foreach ( $posts as $post )
466 $this->single_row( $post, $level );
471 * @param array $pages
472 * @param int $pagenum
473 * @param int $per_page
476 private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
482 $pages = get_pages( array( 'sort_column' => 'menu_order' ) );
489 * Arrange pages into two parts: top level pages and children_pages
490 * children_pages is two dimensional array, eg.
491 * children_pages[10][] contains all sub-pages whose parent is 10.
492 * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations
493 * If searching, ignore hierarchy and treat everything as top level
495 if ( empty( $_REQUEST['s'] ) ) {
497 $top_level_pages = array();
498 $children_pages = array();
500 foreach ( $pages as $page ) {
502 // Catch and repair bad pages.
503 if ( $page->post_parent == $page->ID ) {
504 $page->post_parent = 0;
505 $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
506 clean_post_cache( $page );
509 if ( 0 == $page->post_parent )
510 $top_level_pages[] = $page;
512 $children_pages[ $page->post_parent ][] = $page;
515 $pages = &$top_level_pages;
519 $start = ( $pagenum - 1 ) * $per_page;
520 $end = $start + $per_page;
521 $to_display = array();
523 foreach ( $pages as $page ) {
524 if ( $count >= $end )
527 if ( $count >= $start ) {
528 $to_display[$page->ID] = $level;
533 if ( isset( $children_pages ) )
534 $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
537 // If it is the last pagenum and there are orphaned pages, display them with paging as well.
538 if ( isset( $children_pages ) && $count < $end ){
539 foreach ( $children_pages as $orphans ){
540 foreach ( $orphans as $op ) {
541 if ( $count >= $end )
544 if ( $count >= $start ) {
545 $to_display[$op->ID] = 0;
553 $ids = array_keys( $to_display );
554 _prime_post_caches( $ids );
556 if ( ! isset( $GLOBALS['post'] ) ) {
557 $GLOBALS['post'] = reset( $ids );
560 foreach ( $to_display as $page_id => $level ) {
562 $this->single_row( $page_id, $level );
567 * Given a top level page ID, display the nested hierarchy of sub-pages
568 * together with paging support
570 * @since 3.1.0 (Standalone function exists since 2.6.0)
571 * @since 4.2.0 Added the `$to_display` parameter.
573 * @param array $children_pages
577 * @param int $pagenum
578 * @param int $per_page
579 * @param array $to_display List of pages to be displayed. Passed by reference.
581 private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) {
583 if ( ! isset( $children_pages[$parent] ) )
586 $start = ( $pagenum - 1 ) * $per_page;
587 $end = $start + $per_page;
589 foreach ( $children_pages[$parent] as $page ) {
591 if ( $count >= $end )
594 // If the page starts in a subtree, print the parents.
595 if ( $count == $start && $page->post_parent > 0 ) {
596 $my_parents = array();
597 $my_parent = $page->post_parent;
598 while ( $my_parent ) {
599 // Get the ID from the list or the attribute if my_parent is an object
600 $parent_id = $my_parent;
601 if ( is_object( $my_parent ) ) {
602 $parent_id = $my_parent->ID;
605 $my_parent = get_post( $parent_id );
606 $my_parents[] = $my_parent;
607 if ( !$my_parent->post_parent )
609 $my_parent = $my_parent->post_parent;
611 $num_parents = count( $my_parents );
612 while ( $my_parent = array_pop( $my_parents ) ) {
613 $to_display[$my_parent->ID] = $level - $num_parents;
618 if ( $count >= $start ) {
619 $to_display[$page->ID] = $level;
624 $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
627 unset( $children_pages[$parent] ); //required in order to keep track of orphans
631 * @global string $mode
632 * @param WP_Post $post
635 public function single_row( $post, $level = 0 ) {
638 $global_post = get_post();
640 $post = get_post( $post );
642 $GLOBALS['post'] = $post;
643 setup_postdata( $post );
645 $edit_link = get_edit_post_link( $post->ID );
646 $title = _draft_or_post_title();
647 $post_type_object = get_post_type_object( $post->post_type );
648 $can_edit_post = current_user_can( 'edit_post', $post->ID );
650 $classes = 'iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
652 $lock_holder = wp_check_post_lock( $post->ID );
653 if ( $lock_holder ) {
654 $classes .= ' wp-locked';
655 $lock_holder = get_userdata( $lock_holder );
658 if ( $post->post_parent ) {
659 $count = count( get_post_ancestors( $post->ID ) );
660 $classes .= ' level-'. $count;
662 $classes .= ' level-0';
665 <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>">
668 list( $columns, $hidden ) = $this->get_column_info();
670 foreach ( $columns as $column_name => $column_display_name ) {
671 $class = "class=\"$column_name column-$column_name\"";
674 if ( in_array( $column_name, $hidden ) )
675 $style = ' style="display:none;"';
677 $attributes = "$class$style";
679 switch ( $column_name ) {
683 <th scope="row" class="check-column">
685 if ( $can_edit_post ) {
688 <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php printf( __( 'Select %s' ), $title ); ?></label>
689 <input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" />
690 <div class="locked-indicator"></div>
699 $attributes = 'class="post-title page-title column-title"' . $style;
700 if ( $this->hierarchical_display ) {
701 if ( 0 == $level && (int) $post->post_parent > 0 ) {
702 // Sent level 0 by accident, by default, or because we don't know the actual level.
703 $find_main_page = (int) $post->post_parent;
704 while ( $find_main_page > 0 ) {
705 $parent = get_post( $find_main_page );
707 if ( is_null( $parent ) )
711 $find_main_page = (int) $parent->post_parent;
713 if ( !isset( $parent_name ) ) {
714 /** This filter is documented in wp-includes/post-template.php */
715 $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
721 $pad = str_repeat( '— ', $level );
722 echo "<td $attributes><strong>";
724 if ( $format = get_post_format( $post->ID ) ) {
725 $label = get_post_format_string( $format );
727 echo '<a href="' . esc_url( add_query_arg( array( 'post_format' => $format, 'post_type' => $post->post_type ), 'edit.php' ) ) . '" class="post-state-format post-format-icon post-format-' . $format . '" title="' . $label . '">' . $label . ":</a> ";
730 if ( $can_edit_post && $post->post_status != 'trash' ) {
731 echo '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . $pad . $title . '</a>';
735 _post_states( $post );
737 if ( isset( $parent_name ) )
738 echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
742 if ( $can_edit_post && $post->post_status != 'trash' ) {
743 if ( $lock_holder ) {
744 $locked_avatar = get_avatar( $lock_holder->ID, 18 );
745 $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
747 $locked_avatar = $locked_text = '';
750 echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
753 if ( ! $this->hierarchical_display && 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) )
757 if ( $can_edit_post && 'trash' != $post->post_status ) {
758 $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . esc_attr__( 'Edit this item' ) . '">' . __( 'Edit' ) . '</a>';
759 $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr__( 'Edit this item inline' ) . '">' . __( 'Quick Edit' ) . '</a>';
761 if ( current_user_can( 'delete_post', $post->ID ) ) {
762 if ( 'trash' == $post->post_status )
763 $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>";
764 elseif ( EMPTY_TRASH_DAYS )
765 $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash' ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
766 if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
767 $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently' ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
769 if ( $post_type_object->public ) {
770 if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
771 if ( $can_edit_post ) {
772 $preview_link = set_url_scheme( get_permalink( $post->ID ) );
773 /** This filter is documented in wp-admin/includes/meta-boxes.php */
774 $preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post );
775 $actions['view'] = '<a href="' . esc_url( $preview_link ) . '" title="' . esc_attr( sprintf( __( 'Preview “%s”' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';
777 } elseif ( 'trash' != $post->post_status ) {
778 $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
782 if ( is_post_type_hierarchical( $post->post_type ) ) {
785 * Filter the array of row action links on the Pages list table.
787 * The filter is evaluated only for hierarchical post types.
791 * @param array $actions An array of row action links. Defaults are
792 * 'Edit', 'Quick Edit', 'Restore, 'Trash',
793 * 'Delete Permanently', 'Preview', and 'View'.
794 * @param WP_Post $post The post object.
796 $actions = apply_filters( 'page_row_actions', $actions, $post );
800 * Filter the array of row action links on the Posts list table.
802 * The filter is evaluated only for non-hierarchical post types.
806 * @param array $actions An array of row action links. Defaults are
807 * 'Edit', 'Quick Edit', 'Restore, 'Trash',
808 * 'Delete Permanently', 'Preview', and 'View'.
809 * @param WP_Post $post The post object.
811 $actions = apply_filters( 'post_row_actions', $actions, $post );
814 echo $this->row_actions( $actions );
816 get_inline_data( $post );
821 if ( '0000-00-00 00:00:00' == $post->post_date ) {
822 $t_time = $h_time = __( 'Unpublished' );
825 $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
826 $m_time = $post->post_date;
827 $time = get_post_time( 'G', true, $post );
829 $time_diff = time() - $time;
831 if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS )
832 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
834 $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
837 echo '<td ' . $attributes . '>';
838 if ( 'excerpt' == $mode ) {
841 * Filter the published time of the post.
843 * If $mode equals 'excerpt', the published time and date are both displayed.
844 * If $mode equals 'list' (default), the publish date is displayed, with the
845 * time and date together available as an abbreviation definition.
849 * @param array $t_time The published time.
850 * @param WP_Post $post Post object.
851 * @param string $column_name The column name.
852 * @param string $mode The list display mode ('excerpt' or 'list').
854 echo apply_filters( 'post_date_column_time', $t_time, $post, $column_name, $mode );
857 /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
858 echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, $column_name, $mode ) . '</abbr>';
861 if ( 'publish' == $post->post_status ) {
863 } elseif ( 'future' == $post->post_status ) {
864 if ( $time_diff > 0 )
865 echo '<strong class="attention">' . __( 'Missed schedule' ) . '</strong>';
869 _e( 'Last Modified' );
876 <td <?php echo $attributes ?>><div class="post-com-count-wrapper">
878 $pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0;
880 $this->comments_bubble( $post->ID, $pending_comments );
888 <td <?php echo $attributes ?>><?php
889 printf( '<a href="%s">%s</a>',
890 esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'author' => get_the_author_meta( 'ID' ) ), 'edit.php' )),
898 if ( 'categories' == $column_name )
899 $taxonomy = 'category';
900 elseif ( 'tags' == $column_name )
901 $taxonomy = 'post_tag';
902 elseif ( 0 === strpos( $column_name, 'taxonomy-' ) )
903 $taxonomy = substr( $column_name, 9 );
908 $taxonomy_object = get_taxonomy( $taxonomy );
909 echo '<td ' . $attributes . '>';
910 if ( $terms = get_the_terms( $post->ID, $taxonomy ) ) {
912 foreach ( $terms as $t ) {
913 $posts_in_term_qv = array();
914 if ( 'post' != $post->post_type )
915 $posts_in_term_qv['post_type'] = $post->post_type;
916 if ( $taxonomy_object->query_var ) {
917 $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
919 $posts_in_term_qv['taxonomy'] = $taxonomy;
920 $posts_in_term_qv['term'] = $t->slug;
923 $out[] = sprintf( '<a href="%s">%s</a>',
924 esc_url( add_query_arg( $posts_in_term_qv, 'edit.php' ) ),
925 esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
928 /* translators: used between list items, there is a space after the comma */
929 echo join( __( ', ' ), $out );
937 <td <?php echo $attributes ?>><?php
938 if ( is_post_type_hierarchical( $post->post_type ) ) {
941 * Fires in each custom column on the Posts list table.
943 * This hook only fires if the current post type is hierarchical,
948 * @param string $column_name The name of the column to display.
949 * @param int $post_id The current post ID.
951 do_action( 'manage_pages_custom_column', $column_name, $post->ID );
955 * Fires in each custom column in the Posts list table.
957 * This hook only fires if the current post type is non-hierarchical,
962 * @param string $column_name The name of the column to display.
963 * @param int $post_id The current post ID.
965 do_action( 'manage_posts_custom_column', $column_name, $post->ID );
969 * Fires for each custom column of a specific post type in the Posts list table.
971 * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
975 * @param string $column_name The name of the column to display.
976 * @param int $post_id The current post ID.
978 do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
987 $GLOBALS['post'] = $global_post;
991 * Outputs the hidden row displayed when inline editing
995 public function inline_edit() {
998 $screen = $this->screen;
1000 $post = get_default_post_to_edit( $screen->post_type );
1001 $post_type_object = get_post_type_object( $screen->post_type );
1003 $taxonomy_names = get_object_taxonomies( $screen->post_type );
1004 $hierarchical_taxonomies = array();
1005 $flat_taxonomies = array();
1006 foreach ( $taxonomy_names as $taxonomy_name ) {
1008 $taxonomy = get_taxonomy( $taxonomy_name );
1010 $show_in_quick_edit = $taxonomy->show_in_quick_edit;
1013 * Filter whether the current taxonomy should be shown in the Quick Edit panel.
1017 * @param bool $show_in_quick_edit Whether to show the current taxonomy in Quick Edit.
1018 * @param string $taxonomy_name Taxonomy name.
1019 * @param string $post_type Post type of current Quick Edit post.
1021 if ( ! apply_filters( 'quick_edit_show_taxonomy', $show_in_quick_edit, $taxonomy_name, $screen->post_type ) ) {
1025 if ( $taxonomy->hierarchical )
1026 $hierarchical_taxonomies[] = $taxonomy;
1028 $flat_taxonomies[] = $taxonomy;
1031 $m = ( isset( $mode ) && 'excerpt' == $mode ) ? 'excerpt' : 'list';
1032 $can_publish = current_user_can( $post_type_object->cap->publish_posts );
1033 $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
1037 <form method="get"><table style="display: none"><tbody id="inlineedit">
1039 $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page';
1041 while ( $bulk < 2 ) { ?>
1043 <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-" . $screen->post_type;
1044 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}";
1045 ?>" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
1047 <fieldset class="inline-edit-col-left"><div class="inline-edit-col">
1048 <h4><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></h4>
1051 if ( post_type_supports( $screen->post_type, 'title' ) ) :
1053 <div id="bulk-title-div">
1054 <div id="bulk-titles"></div>
1057 <?php else : // $bulk ?>
1060 <span class="title"><?php _e( 'Title' ); ?></span>
1061 <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span>
1065 <span class="title"><?php _e( 'Slug' ); ?></span>
1066 <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span>
1069 <?php endif; // $bulk
1070 endif; // post_type_supports title ?>
1072 <?php if ( !$bulk ) : ?>
1073 <label><span class="title"><?php _e( 'Date' ); ?></span></label>
1074 <div class="inline-edit-date">
1075 <?php touch_time( 1, 1, 0, 1 ); ?>
1077 <br class="clear" />
1078 <?php endif; // $bulk
1080 if ( post_type_supports( $screen->post_type, 'author' ) ) :
1081 $authors_dropdown = '';
1083 if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) :
1085 'hide_if_only_one_author' => false,
1087 'name' => 'post_author',
1088 'class'=> 'authors',
1093 $users_opt['show_option_none'] = __( '— No Change —' );
1095 if ( $authors = wp_dropdown_users( $users_opt ) ) :
1096 $authors_dropdown = '<label class="inline-edit-author">';
1097 $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
1098 $authors_dropdown .= $authors;
1099 $authors_dropdown .= '</label>';
1104 <?php if ( !$bulk ) echo $authors_dropdown;
1105 endif; // post_type_supports author
1107 if ( !$bulk && $can_publish ) :
1110 <div class="inline-edit-group">
1111 <label class="alignleft">
1112 <span class="title"><?php _e( 'Password' ); ?></span>
1113 <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
1116 <em class="alignleft inline-edit-or">
1118 /* translators: Between password field and private checkbox on post quick edit interface */
1119 echo __( '–OR–' );
1122 <label class="alignleft inline-edit-private">
1123 <input type="checkbox" name="keep_private" value="private" />
1124 <span class="checkbox-title"><?php echo __( 'Private' ); ?></span>
1132 <?php if ( count( $hierarchical_taxonomies ) && !$bulk ) : ?>
1134 <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col">
1136 <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?>
1138 <span class="title inline-edit-categories-label"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
1139 <input type="hidden" name="<?php echo ( $taxonomy->name == 'category' ) ? 'post_category[]' : 'tax_input[' . esc_attr( $taxonomy->name ) . '][]'; ?>" value="0" />
1140 <ul class="cat-checklist <?php echo esc_attr( $taxonomy->name )?>-checklist">
1141 <?php wp_terms_checklist( null, array( 'taxonomy' => $taxonomy->name ) ) ?>
1144 <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?>
1148 <?php endif; // count( $hierarchical_taxonomies ) && !$bulk ?>
1150 <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
1153 if ( post_type_supports( $screen->post_type, 'author' ) && $bulk )
1154 echo $authors_dropdown;
1156 if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) :
1158 if ( $post_type_object->hierarchical ) :
1161 <span class="title"><?php _e( 'Parent' ); ?></span>
1163 $dropdown_args = array(
1164 'post_type' => $post_type_object->name,
1165 'selected' => $post->post_parent,
1166 'name' => 'post_parent',
1167 'show_option_none' => __( 'Main Page (no parent)' ),
1168 'option_none_value' => 0,
1169 'sort_column' => 'menu_order, post_title',
1173 $dropdown_args['show_option_no_change'] = __( '— No Change —' );
1176 * Filter the arguments used to generate the Quick Edit page-parent drop-down.
1180 * @see wp_dropdown_pages()
1182 * @param array $dropdown_args An array of arguments.
1184 $dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args );
1186 wp_dropdown_pages( $dropdown_args );
1191 endif; // hierarchical
1196 <span class="title"><?php _e( 'Order' ); ?></span>
1197 <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order ?>" /></span>
1200 <?php endif; // !$bulk
1202 if ( 'page' == $screen->post_type ) :
1206 <span class="title"><?php _e( 'Template' ); ?></span>
1207 <select name="page_template">
1208 <?php if ( $bulk ) : ?>
1209 <option value="-1"><?php _e( '— No Change —' ); ?></option>
1210 <?php endif; // $bulk ?>
1212 /** This filter is documented in wp-admin/includes/meta-boxes.php */
1213 $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'quick-edit' );
1215 <option value="default"><?php echo esc_html( $default_title ); ?></option>
1216 <?php page_template_dropdown() ?>
1221 endif; // page post_type
1222 endif; // page-attributes
1225 <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?>
1227 <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
1228 <?php if ( current_user_can( $taxonomy->cap->assign_terms ) ) : ?>
1229 <label class="inline-edit-tags">
1230 <span class="title"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
1231 <textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr( $taxonomy->name )?>]" class="tax_input_<?php echo esc_attr( $taxonomy->name )?>"></textarea>
1235 <?php endforeach; //$flat_taxonomies as $taxonomy ?>
1237 <?php endif; // count( $flat_taxonomies ) && !$bulk ?>
1239 <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) :
1242 <div class="inline-edit-group">
1243 <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
1244 <label class="alignleft">
1245 <span class="title"><?php _e( 'Comments' ); ?></span>
1246 <select name="comment_status">
1247 <option value=""><?php _e( '— No Change —' ); ?></option>
1248 <option value="open"><?php _e( 'Allow' ); ?></option>
1249 <option value="closed"><?php _e( 'Do not allow' ); ?></option>
1252 <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
1253 <label class="alignright">
1254 <span class="title"><?php _e( 'Pings' ); ?></span>
1255 <select name="ping_status">
1256 <option value=""><?php _e( '— No Change —' ); ?></option>
1257 <option value="open"><?php _e( 'Allow' ); ?></option>
1258 <option value="closed"><?php _e( 'Do not allow' ); ?></option>
1264 <?php else : // $bulk ?>
1266 <div class="inline-edit-group">
1267 <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
1268 <label class="alignleft">
1269 <input type="checkbox" name="comment_status" value="open" />
1270 <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span>
1272 <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
1273 <label class="alignleft">
1274 <input type="checkbox" name="ping_status" value="open" />
1275 <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span>
1280 <?php endif; // $bulk
1281 endif; // post_type_supports comments or pings ?>
1283 <div class="inline-edit-group">
1284 <label class="inline-edit-status alignleft">
1285 <span class="title"><?php _e( 'Status' ); ?></span>
1286 <select name="_status">
1287 <?php if ( $bulk ) : ?>
1288 <option value="-1"><?php _e( '— No Change —' ); ?></option>
1289 <?php endif; // $bulk ?>
1290 <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?>
1291 <option value="publish"><?php _e( 'Published' ); ?></option>
1292 <option value="future"><?php _e( 'Scheduled' ); ?></option>
1293 <?php if ( $bulk ) : ?>
1294 <option value="private"><?php _e( 'Private' ) ?></option>
1295 <?php endif; // $bulk ?>
1297 <option value="pending"><?php _e( 'Pending Review' ); ?></option>
1298 <option value="draft"><?php _e( 'Draft' ); ?></option>
1302 <?php if ( 'post' == $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?>
1304 <?php if ( $bulk ) : ?>
1306 <label class="alignright">
1307 <span class="title"><?php _e( 'Sticky' ); ?></span>
1308 <select name="sticky">
1309 <option value="-1"><?php _e( '— No Change —' ); ?></option>
1310 <option value="sticky"><?php _e( 'Sticky' ); ?></option>
1311 <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option>
1315 <?php else : // $bulk ?>
1317 <label class="alignleft">
1318 <input type="checkbox" name="sticky" value="sticky" />
1319 <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span>
1322 <?php endif; // $bulk ?>
1324 <?php endif; // 'post' && $can_publish && current_user_can( 'edit_others_cap' ) ?>
1330 if ( $bulk && current_theme_supports( 'post-formats' ) && post_type_supports( $screen->post_type, 'post-formats' ) ) {
1331 $post_formats = get_theme_support( 'post-formats' );
1334 <label class="alignleft" for="post_format">
1335 <span class="title"><?php _ex( 'Format', 'post format' ); ?></span>
1336 <select name="post_format">
1337 <option value="-1"><?php _e( '— No Change —' ); ?></option>
1338 <option value="0"><?php echo get_post_format_string( 'standard' ); ?></option>
1341 foreach ( $post_formats[0] as $format ) {
1343 <option value="<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></option>
1358 list( $columns ) = $this->get_column_info();
1360 foreach ( $columns as $column_name => $column_display_name ) {
1361 if ( isset( $core_columns[$column_name] ) )
1367 * Fires once for each column in Bulk Edit mode.
1371 * @param string $column_name Name of the column to edit.
1372 * @param WP_Post $post_type The post type slug.
1374 do_action( 'bulk_edit_custom_box', $column_name, $screen->post_type );
1378 * Fires once for each column in Quick Edit mode.
1382 * @param string $column_name Name of the column to edit.
1383 * @param WP_Post $post_type The post type slug.
1385 do_action( 'quick_edit_custom_box', $column_name, $screen->post_type );
1390 <p class="submit inline-edit-save">
1391 <a href="#inline-edit" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></a>
1392 <?php if ( ! $bulk ) {
1393 wp_nonce_field( 'inlineeditnonce', '_inline_edit', false );
1395 <a href="#inline-edit" class="button-primary save alignright"><?php _e( 'Update' ); ?></a>
1396 <span class="spinner"></span>
1398 submit_button( __( 'Update' ), 'button-primary alignright', 'bulk_edit', false );
1400 <input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" />
1401 <input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" />
1402 <?php if ( ! $bulk && ! post_type_supports( $screen->post_type, 'author' ) ) { ?>
1403 <input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
1405 <span class="error" style="display:none"></span>
1406 <br class="clear" />
1413 </tbody></table></form>