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;
51 * Current level for output.
57 protected $current_level = 0;
65 * @see WP_List_Table::__construct() for more information on default arguments.
67 * @global object $post_type_object
70 * @param array $args An associative array of arguments.
72 public function __construct( $args = array() ) {
73 global $post_type_object, $wpdb;
75 parent::__construct( array(
77 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
80 $post_type = $this->screen->post_type;
81 $post_type_object = get_post_type_object( $post_type );
83 if ( !current_user_can( $post_type_object->cap->edit_others_posts ) ) {
84 $exclude_states = get_post_stati( array( 'show_in_admin_all_list' => false ) );
85 $this->user_posts_count = $wpdb->get_var( $wpdb->prepare( "
86 SELECT COUNT( 1 ) FROM $wpdb->posts
87 WHERE post_type = %s AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
89 ", $post_type, get_current_user_id() ) );
91 if ( $this->user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) )
92 $_GET['author'] = get_current_user_id();
95 if ( 'post' == $post_type && $sticky_posts = get_option( 'sticky_posts' ) ) {
96 $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
97 $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 ) );
102 * Sets whether the table layout should be hierarchical or not.
106 * @param bool $display Whether the table layout should be hierarchical.
108 public function set_hierarchical_display( $display ) {
109 $this->hierarchical_display = $display;
116 public function ajax_user_can() {
117 return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts );
122 * @global array $avail_post_stati
123 * @global WP_Query $wp_query
124 * @global int $per_page
125 * @global string $mode
127 public function prepare_items() {
128 global $avail_post_stati, $wp_query, $per_page, $mode;
130 $avail_post_stati = wp_edit_posts_query();
132 $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' == $wp_query->query['orderby'] );
134 $total_items = $this->hierarchical_display ? $wp_query->post_count : $wp_query->found_posts;
136 $post_type = $this->screen->post_type;
137 $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
139 /** This filter is documented in wp-admin/includes/post.php */
140 $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
142 if ( $this->hierarchical_display )
143 $total_pages = ceil( $total_items / $per_page );
145 $total_pages = $wp_query->max_num_pages;
147 if ( ! empty( $_REQUEST['mode'] ) ) {
148 $mode = $_REQUEST['mode'] == 'excerpt' ? 'excerpt' : 'list';
149 set_user_setting ( 'posts_list_mode', $mode );
151 $mode = get_user_setting ( 'posts_list_mode', 'list' );
154 $this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] == 'trash';
156 $this->set_pagination_args( array(
157 'total_items' => $total_items,
158 'total_pages' => $total_pages,
159 'per_page' => $per_page
167 public function has_items() {
174 public function no_items() {
175 if ( isset( $_REQUEST['post_status'] ) && 'trash' == $_REQUEST['post_status'] )
176 echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash;
178 echo get_post_type_object( $this->screen->post_type )->labels->not_found;
182 * Determine if the current view is the "All" view.
186 * @return bool Whether the current view is the "All" view.
188 protected function is_base_request() {
189 if ( empty( $_GET ) ) {
191 } elseif ( 1 === count( $_GET ) && ! empty( $_GET['post_type'] ) ) {
192 return $this->screen->post_type === $_GET['post_type'];
198 * @global array $locked_post_status This seems to be deprecated.
199 * @global array $avail_post_stati
202 protected function get_views() {
203 global $locked_post_status, $avail_post_stati;
205 $post_type = $this->screen->post_type;
207 if ( !empty($locked_post_status) )
210 $status_links = array();
211 $num_posts = wp_count_posts( $post_type, 'readable' );
215 $current_user_id = get_current_user_id();
217 if ( $this->user_posts_count ) {
218 if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) )
219 $class = ' class="current"';
220 $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>';
221 $allposts = '&all_posts=1';
225 $total_posts = array_sum( (array) $num_posts );
227 // Subtract post types that are not included in the admin all list.
228 foreach ( get_post_stati( array('show_in_admin_all_list' => false) ) as $state )
229 $total_posts -= $num_posts->$state;
231 if ( empty( $class ) && ( ( $this->is_base_request() && ! $this->user_posts_count ) || isset( $_REQUEST['all_posts'] ) ) ) {
232 $class = ' class="current"';
235 $all_inner_html = sprintf(
237 'All <span class="count">(%s)</span>',
238 'All <span class="count">(%s)</span>',
242 number_format_i18n( $total_posts )
245 $status_links['all'] = "<a href='edit.php?post_type=$post_type{$allposts}'$class>" . $all_inner_html . '</a>';
247 foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
250 $status_name = $status->name;
252 if ( !in_array( $status_name, $avail_post_stati ) )
255 if ( empty( $num_posts->$status_name ) )
258 if ( isset($_REQUEST['post_status']) && $status_name == $_REQUEST['post_status'] )
259 $class = ' class="current"';
261 $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>';
264 if ( ! empty( $this->sticky_posts_count ) ) {
265 $class = ! empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : '';
267 $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>' );
269 // Sticky comes after Publish, or if not listed, after All.
270 $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) );
271 $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
274 return $status_links;
281 protected function get_bulk_actions() {
283 $post_type_obj = get_post_type_object( $this->screen->post_type );
285 if ( $this->is_trash ) {
286 $actions['untrash'] = __( 'Restore' );
288 $actions['edit'] = __( 'Edit' );
291 if ( current_user_can( $post_type_obj->cap->delete_posts ) ) {
292 if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) {
293 $actions['delete'] = __( 'Delete Permanently' );
295 $actions['trash'] = __( 'Move to Trash' );
304 * @param string $which
306 protected function extra_tablenav( $which ) {
309 <div class="alignleft actions">
311 if ( 'top' == $which && !is_singular() ) {
313 $this->months_dropdown( $this->screen->post_type );
315 if ( is_object_in_taxonomy( $this->screen->post_type, 'category' ) ) {
316 $dropdown_options = array(
317 'show_option_all' => __( 'All categories' ),
325 echo '<label class="screen-reader-text" for="cat">' . __( 'Filter by category' ) . '</label>';
326 wp_dropdown_categories( $dropdown_options );
330 * Fires before the Filter button on the Posts and Pages list tables.
332 * The Filter button allows sorting by date and/or category on the
333 * Posts list table, and sorting by date on the Pages list table.
337 do_action( 'restrict_manage_posts' );
339 submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
342 if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) ) {
343 submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
354 public function current_action() {
355 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
358 return parent::current_action();
362 * @global string $mode
363 * @param string $which
365 protected function pagination( $which ) {
368 parent::pagination( $which );
370 if ( 'top' == $which && ! is_post_type_hierarchical( $this->screen->post_type ) )
371 $this->view_switcher( $mode );
378 protected function get_table_classes() {
379 return array( 'widefat', 'fixed', 'striped', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
386 public function get_columns() {
387 $post_type = $this->screen->post_type;
389 $posts_columns = array();
391 $posts_columns['cb'] = '<input type="checkbox" />';
393 /* translators: manage posts column name */
394 $posts_columns['title'] = _x( 'Title', 'column name' );
396 if ( post_type_supports( $post_type, 'author' ) ) {
397 $posts_columns['author'] = __( 'Author' );
400 $taxonomies = get_object_taxonomies( $post_type, 'objects' );
401 $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
404 * Filter the taxonomy columns in the Posts list table.
406 * The dynamic portion of the hook name, `$post_type`, refers to the post
411 * @param array $taxonomies Array of taxonomies to show columns for.
412 * @param string $post_type The post type.
414 $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
415 $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
417 foreach ( $taxonomies as $taxonomy ) {
418 if ( 'category' == $taxonomy )
419 $column_key = 'categories';
420 elseif ( 'post_tag' == $taxonomy )
421 $column_key = 'tags';
423 $column_key = 'taxonomy-' . $taxonomy;
425 $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
428 $post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
429 if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) )
430 $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>';
432 $posts_columns['date'] = __( 'Date' );
434 if ( 'page' == $post_type ) {
437 * Filter the columns displayed in the Pages list table.
441 * @param array $post_columns An array of column names.
443 $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
447 * Filter the columns displayed in the Posts list table.
451 * @param array $posts_columns An array of column names.
452 * @param string $post_type The post type slug.
454 $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
458 * Filter the columns displayed in the Posts list table for a specific post type.
460 * The dynamic portion of the hook name, `$post_type`, refers to the post type slug.
464 * @param array $post_columns An array of column names.
466 return apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
473 protected function get_sortable_columns() {
476 'parent' => 'parent',
477 'comments' => 'comment_count',
478 'date' => array( 'date', true )
483 * @global WP_Query $wp_query
484 * @global int $per_page
485 * @param array $posts
488 public function display_rows( $posts = array(), $level = 0 ) {
489 global $wp_query, $per_page;
491 if ( empty( $posts ) )
492 $posts = $wp_query->posts;
494 add_filter( 'the_title', 'esc_html' );
496 if ( $this->hierarchical_display ) {
497 $this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page );
499 $this->_display_rows( $posts, $level );
504 * @global string $mode
505 * @param array $posts
508 private function _display_rows( $posts, $level = 0 ) {
511 // Create array of post IDs.
514 foreach ( $posts as $a_post )
515 $post_ids[] = $a_post->ID;
517 $this->comment_pending_count = get_pending_comments_num( $post_ids );
519 foreach ( $posts as $post )
520 $this->single_row( $post, $level );
525 * @global WP_Post $post
526 * @param array $pages
527 * @param int $pagenum
528 * @param int $per_page
530 private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
536 $pages = get_pages( array( 'sort_column' => 'menu_order' ) );
543 * Arrange pages into two parts: top level pages and children_pages
544 * children_pages is two dimensional array, eg.
545 * children_pages[10][] contains all sub-pages whose parent is 10.
546 * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations
547 * If searching, ignore hierarchy and treat everything as top level
549 if ( empty( $_REQUEST['s'] ) ) {
551 $top_level_pages = array();
552 $children_pages = array();
554 foreach ( $pages as $page ) {
556 // Catch and repair bad pages.
557 if ( $page->post_parent == $page->ID ) {
558 $page->post_parent = 0;
559 $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
560 clean_post_cache( $page );
563 if ( 0 == $page->post_parent )
564 $top_level_pages[] = $page;
566 $children_pages[ $page->post_parent ][] = $page;
569 $pages = &$top_level_pages;
573 $start = ( $pagenum - 1 ) * $per_page;
574 $end = $start + $per_page;
575 $to_display = array();
577 foreach ( $pages as $page ) {
578 if ( $count >= $end )
581 if ( $count >= $start ) {
582 $to_display[$page->ID] = $level;
587 if ( isset( $children_pages ) )
588 $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
591 // If it is the last pagenum and there are orphaned pages, display them with paging as well.
592 if ( isset( $children_pages ) && $count < $end ){
593 foreach ( $children_pages as $orphans ){
594 foreach ( $orphans as $op ) {
595 if ( $count >= $end )
598 if ( $count >= $start ) {
599 $to_display[$op->ID] = 0;
607 $ids = array_keys( $to_display );
608 _prime_post_caches( $ids );
610 if ( ! isset( $GLOBALS['post'] ) ) {
611 $GLOBALS['post'] = reset( $ids );
614 foreach ( $to_display as $page_id => $level ) {
616 $this->single_row( $page_id, $level );
621 * Given a top level page ID, display the nested hierarchy of sub-pages
622 * together with paging support
624 * @since 3.1.0 (Standalone function exists since 2.6.0)
625 * @since 4.2.0 Added the `$to_display` parameter.
627 * @param array $children_pages
631 * @param int $pagenum
632 * @param int $per_page
633 * @param array $to_display List of pages to be displayed. Passed by reference.
635 private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) {
636 if ( ! isset( $children_pages[$parent] ) )
639 $start = ( $pagenum - 1 ) * $per_page;
640 $end = $start + $per_page;
642 foreach ( $children_pages[$parent] as $page ) {
643 if ( $count >= $end )
646 // If the page starts in a subtree, print the parents.
647 if ( $count == $start && $page->post_parent > 0 ) {
648 $my_parents = array();
649 $my_parent = $page->post_parent;
650 while ( $my_parent ) {
651 // Get the ID from the list or the attribute if my_parent is an object
652 $parent_id = $my_parent;
653 if ( is_object( $my_parent ) ) {
654 $parent_id = $my_parent->ID;
657 $my_parent = get_post( $parent_id );
658 $my_parents[] = $my_parent;
659 if ( !$my_parent->post_parent )
661 $my_parent = $my_parent->post_parent;
663 $num_parents = count( $my_parents );
664 while ( $my_parent = array_pop( $my_parents ) ) {
665 $to_display[$my_parent->ID] = $level - $num_parents;
670 if ( $count >= $start ) {
671 $to_display[$page->ID] = $level;
676 $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
679 unset( $children_pages[$parent] ); //required in order to keep track of orphans
683 * Handles the checkbox column output.
688 * @param WP_Post $post The current WP_Post object.
690 public function column_cb( $post ) {
691 if ( current_user_can( 'edit_post', $post->ID ) ): ?>
692 <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php
693 printf( __( 'Select %s' ), _draft_or_post_title() );
695 <input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" />
696 <div class="locked-indicator"></div>
704 * @param WP_Post $post
705 * @param string $classes
706 * @param string $data
707 * @param string $primary
709 protected function _column_title( $post, $classes, $data, $primary ) {
710 echo '<td class="' . $classes . ' page-title" ', $data, '>';
711 echo $this->column_title( $post );
712 echo $this->handle_row_actions( $post, 'title', $primary );
717 * Handles the title column output.
722 * @global string $mode
724 * @param WP_Post $post The current WP_Post object.
726 public function column_title( $post ) {
729 if ( $this->hierarchical_display ) {
730 if ( 0 === $this->current_level && (int) $post->post_parent > 0 ) {
731 // Sent level 0 by accident, by default, or because we don't know the actual level.
732 $find_main_page = (int) $post->post_parent;
733 while ( $find_main_page > 0 ) {
734 $parent = get_post( $find_main_page );
736 if ( is_null( $parent ) ) {
740 $this->current_level++;
741 $find_main_page = (int) $parent->post_parent;
743 if ( ! isset( $parent_name ) ) {
744 /** This filter is documented in wp-includes/post-template.php */
745 $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
751 $pad = str_repeat( '— ', $this->current_level );
754 $format = get_post_format( $post->ID );
756 $label = get_post_format_string( $format );
758 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> ";
761 $can_edit_post = current_user_can( 'edit_post', $post->ID );
762 $title = _draft_or_post_title();
764 if ( $can_edit_post && $post->post_status != 'trash' ) {
765 $edit_link = get_edit_post_link( $post->ID );
766 echo '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . $pad . $title . '</a>';
770 _post_states( $post );
772 if ( isset( $parent_name ) ) {
773 $post_type_object = get_post_type_object( $post->post_type );
774 echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
778 if ( $can_edit_post && $post->post_status != 'trash' ) {
779 $lock_holder = wp_check_post_lock( $post->ID );
781 if ( $lock_holder ) {
782 $lock_holder = get_userdata( $lock_holder );
783 $locked_avatar = get_avatar( $lock_holder->ID, 18 );
784 $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
786 $locked_avatar = $locked_text = '';
789 echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
792 if ( ! is_post_type_hierarchical( $this->screen->post_type ) && 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) ) {
796 get_inline_data( $post );
800 * Handles the post date column output.
805 * @global string $mode
807 * @param WP_Post $post The current WP_Post object.
809 public function column_date( $post ) {
812 if ( '0000-00-00 00:00:00' == $post->post_date ) {
813 $t_time = $h_time = __( 'Unpublished' );
816 $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
817 $m_time = $post->post_date;
818 $time = get_post_time( 'G', true, $post );
820 $time_diff = time() - $time;
822 if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
823 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
825 $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
829 if ( 'excerpt' == $mode ) {
831 * Filter the published time of the post.
833 * If $mode equals 'excerpt', the published time and date are both displayed.
834 * If $mode equals 'list' (default), the publish date is displayed, with the
835 * time and date together available as an abbreviation definition.
839 * @param array $t_time The published time.
840 * @param WP_Post $post Post object.
841 * @param string $column_name The column name.
842 * @param string $mode The list display mode ('excerpt' or 'list').
844 echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
847 /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
848 echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . '</abbr>';
851 if ( 'publish' == $post->post_status ) {
853 } elseif ( 'future' == $post->post_status ) {
854 if ( $time_diff > 0 ) {
855 echo '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>';
860 _e( 'Last Modified' );
865 * Handles the comments column output.
870 * @param WP_Post $post The current WP_Post object.
872 public function column_comments( $post ) {
874 <div class="post-com-count-wrapper">
876 $pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0;
878 $this->comments_bubble( $post->ID, $pending_comments );
885 * Handles the post author column output.
890 * @param WP_Post $post The current WP_Post object.
892 public function column_author( $post ) {
893 printf( '<a href="%s">%s</a>',
894 esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'author' => get_the_author_meta( 'ID' ) ), 'edit.php' )),
900 * Handles the default column output.
905 * @param WP_Post $post The current WP_Post object.
906 * @param string $column_name The current column name.
908 public function column_default( $post, $column_name ) {
909 if ( 'categories' == $column_name ) {
910 $taxonomy = 'category';
911 } elseif ( 'tags' == $column_name ) {
912 $taxonomy = 'post_tag';
913 } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) {
914 $taxonomy = substr( $column_name, 9 );
919 $taxonomy_object = get_taxonomy( $taxonomy );
920 $terms = get_the_terms( $post->ID, $taxonomy );
921 if ( is_array( $terms ) ) {
923 foreach ( $terms as $t ) {
924 $posts_in_term_qv = array();
925 if ( 'post' != $post->post_type ) {
926 $posts_in_term_qv['post_type'] = $post->post_type;
928 if ( $taxonomy_object->query_var ) {
929 $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
931 $posts_in_term_qv['taxonomy'] = $taxonomy;
932 $posts_in_term_qv['term'] = $t->slug;
935 $out[] = sprintf( '<a href="%s">%s</a>',
936 esc_url( add_query_arg( $posts_in_term_qv, 'edit.php' ) ),
937 esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
940 /* translators: used between list items, there is a space after the comma */
941 echo join( __( ', ' ), $out );
943 echo '<span aria-hidden="true">—</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
948 if ( is_post_type_hierarchical( $post->post_type ) ) {
951 * Fires in each custom column on the Posts list table.
953 * This hook only fires if the current post type is hierarchical,
958 * @param string $column_name The name of the column to display.
959 * @param int $post_id The current post ID.
961 do_action( 'manage_pages_custom_column', $column_name, $post->ID );
965 * Fires in each custom column in the Posts list table.
967 * This hook only fires if the current post type is non-hierarchical,
972 * @param string $column_name The name of the column to display.
973 * @param int $post_id The current post ID.
975 do_action( 'manage_posts_custom_column', $column_name, $post->ID );
979 * Fires for each custom column of a specific post type in the Posts list table.
981 * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
985 * @param string $column_name The name of the column to display.
986 * @param int $post_id The current post ID.
988 do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
992 * @global WP_Post $post
994 * @param int|WP_Post $post
997 public function single_row( $post, $level = 0 ) {
998 $global_post = get_post();
1000 $post = get_post( $post );
1001 $this->current_level = $level;
1003 $GLOBALS['post'] = $post;
1004 setup_postdata( $post );
1006 $classes = 'iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
1008 $lock_holder = wp_check_post_lock( $post->ID );
1009 if ( $lock_holder ) {
1010 $classes .= ' wp-locked';
1013 if ( $post->post_parent ) {
1014 $count = count( get_post_ancestors( $post->ID ) );
1015 $classes .= ' level-'. $count;
1017 $classes .= ' level-0';
1020 <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>">
1021 <?php $this->single_row_columns( $post ); ?>
1024 $GLOBALS['post'] = $global_post;
1028 * Gets the name of the default primary column.
1033 * @return string Name of the default primary column, in this case, 'title'.
1035 protected function get_default_primary_column_name() {
1040 * Generates and displays row action links.
1045 * @param object $post Post being acted upon.
1046 * @param string $column_name Current column name.
1047 * @param string $primary Primary column name.
1048 * @return string Row actions output for posts.
1050 protected function handle_row_actions( $post, $column_name, $primary ) {
1051 if ( $primary !== $column_name ) {
1055 $post_type_object = get_post_type_object( $post->post_type );
1056 $can_edit_post = current_user_can( 'edit_post', $post->ID );
1059 if ( $can_edit_post && 'trash' != $post->post_status ) {
1060 $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . esc_attr__( 'Edit this item' ) . '">' . __( 'Edit' ) . '</a>';
1061 $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr__( 'Edit this item inline' ) . '">' . __( 'Quick Edit' ) . '</a>';
1064 if ( current_user_can( 'delete_post', $post->ID ) ) {
1065 if ( 'trash' == $post->post_status )
1066 $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>";
1067 elseif ( EMPTY_TRASH_DAYS )
1068 $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash' ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
1069 if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
1070 $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently' ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
1073 if ( $post_type_object->public ) {
1074 $title = _draft_or_post_title();
1075 if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
1076 if ( $can_edit_post ) {
1077 $preview_link = set_url_scheme( get_permalink( $post->ID ) );
1078 /** This filter is documented in wp-admin/includes/meta-boxes.php */
1079 $preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post );
1080 $actions['view'] = '<a href="' . esc_url( $preview_link ) . '" title="' . esc_attr( sprintf( __( 'Preview “%s”' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';
1082 } elseif ( 'trash' != $post->post_status ) {
1083 $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
1087 if ( is_post_type_hierarchical( $post->post_type ) ) {
1090 * Filter the array of row action links on the Pages list table.
1092 * The filter is evaluated only for hierarchical post types.
1096 * @param array $actions An array of row action links. Defaults are
1097 * 'Edit', 'Quick Edit', 'Restore, 'Trash',
1098 * 'Delete Permanently', 'Preview', and 'View'.
1099 * @param WP_Post $post The post object.
1101 $actions = apply_filters( 'page_row_actions', $actions, $post );
1105 * Filter the array of row action links on the Posts list table.
1107 * The filter is evaluated only for non-hierarchical post types.
1111 * @param array $actions An array of row action links. Defaults are
1112 * 'Edit', 'Quick Edit', 'Restore, 'Trash',
1113 * 'Delete Permanently', 'Preview', and 'View'.
1114 * @param WP_Post $post The post object.
1116 $actions = apply_filters( 'post_row_actions', $actions, $post );
1119 return $this->row_actions( $actions );
1123 * Outputs the hidden row displayed when inline editing
1127 * @global string $mode
1129 public function inline_edit() {
1132 $screen = $this->screen;
1134 $post = get_default_post_to_edit( $screen->post_type );
1135 $post_type_object = get_post_type_object( $screen->post_type );
1137 $taxonomy_names = get_object_taxonomies( $screen->post_type );
1138 $hierarchical_taxonomies = array();
1139 $flat_taxonomies = array();
1140 foreach ( $taxonomy_names as $taxonomy_name ) {
1142 $taxonomy = get_taxonomy( $taxonomy_name );
1144 $show_in_quick_edit = $taxonomy->show_in_quick_edit;
1147 * Filter whether the current taxonomy should be shown in the Quick Edit panel.
1151 * @param bool $show_in_quick_edit Whether to show the current taxonomy in Quick Edit.
1152 * @param string $taxonomy_name Taxonomy name.
1153 * @param string $post_type Post type of current Quick Edit post.
1155 if ( ! apply_filters( 'quick_edit_show_taxonomy', $show_in_quick_edit, $taxonomy_name, $screen->post_type ) ) {
1159 if ( $taxonomy->hierarchical )
1160 $hierarchical_taxonomies[] = $taxonomy;
1162 $flat_taxonomies[] = $taxonomy;
1165 $m = ( isset( $mode ) && 'excerpt' == $mode ) ? 'excerpt' : 'list';
1166 $can_publish = current_user_can( $post_type_object->cap->publish_posts );
1167 $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
1171 <form method="get"><table style="display: none"><tbody id="inlineedit">
1173 $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page';
1175 while ( $bulk < 2 ) { ?>
1177 <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-" . $screen->post_type;
1178 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}";
1179 ?>" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
1181 <fieldset class="inline-edit-col-left"><div class="inline-edit-col">
1182 <h4><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></h4>
1185 if ( post_type_supports( $screen->post_type, 'title' ) ) :
1187 <div id="bulk-title-div">
1188 <div id="bulk-titles"></div>
1191 <?php else : // $bulk ?>
1194 <span class="title"><?php _e( 'Title' ); ?></span>
1195 <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span>
1199 <span class="title"><?php _e( 'Slug' ); ?></span>
1200 <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span>
1203 <?php endif; // $bulk
1204 endif; // post_type_supports title ?>
1206 <?php if ( !$bulk ) : ?>
1207 <fieldset class="inline-edit-date">
1208 <legend><span class="title"><?php _e( 'Date' ); ?></span></legend>
1209 <?php touch_time( 1, 1, 0, 1 ); ?>
1211 <br class="clear" />
1212 <?php endif; // $bulk
1214 if ( post_type_supports( $screen->post_type, 'author' ) ) :
1215 $authors_dropdown = '';
1217 if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) :
1219 'hide_if_only_one_author' => false,
1221 'name' => 'post_author',
1222 'class'=> 'authors',
1227 $users_opt['show_option_none'] = __( '— No Change —' );
1229 if ( $authors = wp_dropdown_users( $users_opt ) ) :
1230 $authors_dropdown = '<label class="inline-edit-author">';
1231 $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
1232 $authors_dropdown .= $authors;
1233 $authors_dropdown .= '</label>';
1238 <?php if ( !$bulk ) echo $authors_dropdown;
1239 endif; // post_type_supports author
1241 if ( !$bulk && $can_publish ) :
1244 <div class="inline-edit-group">
1245 <label class="alignleft">
1246 <span class="title"><?php _e( 'Password' ); ?></span>
1247 <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
1250 <em class="alignleft inline-edit-or">
1252 /* translators: Between password field and private checkbox on post quick edit interface */
1253 _e( '–OR–' );
1256 <label class="alignleft inline-edit-private">
1257 <input type="checkbox" name="keep_private" value="private" />
1258 <span class="checkbox-title"><?php _e( 'Private' ); ?></span>
1266 <?php if ( count( $hierarchical_taxonomies ) && !$bulk ) : ?>
1268 <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col">
1270 <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?>
1272 <span class="title inline-edit-categories-label"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
1273 <input type="hidden" name="<?php echo ( $taxonomy->name == 'category' ) ? 'post_category[]' : 'tax_input[' . esc_attr( $taxonomy->name ) . '][]'; ?>" value="0" />
1274 <ul class="cat-checklist <?php echo esc_attr( $taxonomy->name )?>-checklist">
1275 <?php wp_terms_checklist( null, array( 'taxonomy' => $taxonomy->name ) ) ?>
1278 <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?>
1282 <?php endif; // count( $hierarchical_taxonomies ) && !$bulk ?>
1284 <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
1287 if ( post_type_supports( $screen->post_type, 'author' ) && $bulk )
1288 echo $authors_dropdown;
1290 if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) :
1292 if ( $post_type_object->hierarchical ) :
1295 <span class="title"><?php _e( 'Parent' ); ?></span>
1297 $dropdown_args = array(
1298 'post_type' => $post_type_object->name,
1299 'selected' => $post->post_parent,
1300 'name' => 'post_parent',
1301 'show_option_none' => __( 'Main Page (no parent)' ),
1302 'option_none_value' => 0,
1303 'sort_column' => 'menu_order, post_title',
1307 $dropdown_args['show_option_no_change'] = __( '— No Change —' );
1310 * Filter the arguments used to generate the Quick Edit page-parent drop-down.
1314 * @see wp_dropdown_pages()
1316 * @param array $dropdown_args An array of arguments.
1318 $dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args );
1320 wp_dropdown_pages( $dropdown_args );
1325 endif; // hierarchical
1330 <span class="title"><?php _e( 'Order' ); ?></span>
1331 <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order ?>" /></span>
1334 <?php endif; // !$bulk
1336 if ( 'page' == $screen->post_type ) :
1340 <span class="title"><?php _e( 'Template' ); ?></span>
1341 <select name="page_template">
1342 <?php if ( $bulk ) : ?>
1343 <option value="-1"><?php _e( '— No Change —' ); ?></option>
1344 <?php endif; // $bulk ?>
1346 /** This filter is documented in wp-admin/includes/meta-boxes.php */
1347 $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'quick-edit' );
1349 <option value="default"><?php echo esc_html( $default_title ); ?></option>
1350 <?php page_template_dropdown() ?>
1355 endif; // page post_type
1356 endif; // page-attributes
1359 <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?>
1361 <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
1362 <?php if ( current_user_can( $taxonomy->cap->assign_terms ) ) : ?>
1363 <label class="inline-edit-tags">
1364 <span class="title"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
1365 <textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr( $taxonomy->name )?>]" class="tax_input_<?php echo esc_attr( $taxonomy->name )?>"></textarea>
1369 <?php endforeach; //$flat_taxonomies as $taxonomy ?>
1371 <?php endif; // count( $flat_taxonomies ) && !$bulk ?>
1373 <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) :
1376 <div class="inline-edit-group">
1377 <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
1378 <label class="alignleft">
1379 <span class="title"><?php _e( 'Comments' ); ?></span>
1380 <select name="comment_status">
1381 <option value=""><?php _e( '— No Change —' ); ?></option>
1382 <option value="open"><?php _e( 'Allow' ); ?></option>
1383 <option value="closed"><?php _e( 'Do not allow' ); ?></option>
1386 <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
1387 <label class="alignright">
1388 <span class="title"><?php _e( 'Pings' ); ?></span>
1389 <select name="ping_status">
1390 <option value=""><?php _e( '— No Change —' ); ?></option>
1391 <option value="open"><?php _e( 'Allow' ); ?></option>
1392 <option value="closed"><?php _e( 'Do not allow' ); ?></option>
1398 <?php else : // $bulk ?>
1400 <div class="inline-edit-group">
1401 <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
1402 <label class="alignleft">
1403 <input type="checkbox" name="comment_status" value="open" />
1404 <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span>
1406 <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
1407 <label class="alignleft">
1408 <input type="checkbox" name="ping_status" value="open" />
1409 <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span>
1414 <?php endif; // $bulk
1415 endif; // post_type_supports comments or pings ?>
1417 <div class="inline-edit-group">
1418 <label class="inline-edit-status alignleft">
1419 <span class="title"><?php _e( 'Status' ); ?></span>
1420 <select name="_status">
1421 <?php if ( $bulk ) : ?>
1422 <option value="-1"><?php _e( '— No Change —' ); ?></option>
1423 <?php endif; // $bulk ?>
1424 <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?>
1425 <option value="publish"><?php _e( 'Published' ); ?></option>
1426 <option value="future"><?php _e( 'Scheduled' ); ?></option>
1427 <?php if ( $bulk ) : ?>
1428 <option value="private"><?php _e( 'Private' ) ?></option>
1429 <?php endif; // $bulk ?>
1431 <option value="pending"><?php _e( 'Pending Review' ); ?></option>
1432 <option value="draft"><?php _e( 'Draft' ); ?></option>
1436 <?php if ( 'post' == $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?>
1438 <?php if ( $bulk ) : ?>
1440 <label class="alignright">
1441 <span class="title"><?php _e( 'Sticky' ); ?></span>
1442 <select name="sticky">
1443 <option value="-1"><?php _e( '— No Change —' ); ?></option>
1444 <option value="sticky"><?php _e( 'Sticky' ); ?></option>
1445 <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option>
1449 <?php else : // $bulk ?>
1451 <label class="alignleft">
1452 <input type="checkbox" name="sticky" value="sticky" />
1453 <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span>
1456 <?php endif; // $bulk ?>
1458 <?php endif; // 'post' && $can_publish && current_user_can( 'edit_others_cap' ) ?>
1464 if ( $bulk && current_theme_supports( 'post-formats' ) && post_type_supports( $screen->post_type, 'post-formats' ) ) {
1465 $post_formats = get_theme_support( 'post-formats' );
1468 <label class="alignleft">
1469 <span class="title"><?php _ex( 'Format', 'post format' ); ?></span>
1470 <select name="post_format">
1471 <option value="-1"><?php _e( '— No Change —' ); ?></option>
1472 <option value="0"><?php echo get_post_format_string( 'standard' ); ?></option>
1475 foreach ( $post_formats[0] as $format ) {
1477 <option value="<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></option>
1492 list( $columns ) = $this->get_column_info();
1494 foreach ( $columns as $column_name => $column_display_name ) {
1495 if ( isset( $core_columns[$column_name] ) )
1501 * Fires once for each column in Bulk Edit mode.
1505 * @param string $column_name Name of the column to edit.
1506 * @param WP_Post $post_type The post type slug.
1508 do_action( 'bulk_edit_custom_box', $column_name, $screen->post_type );
1512 * Fires once for each column in Quick Edit mode.
1516 * @param string $column_name Name of the column to edit.
1517 * @param WP_Post $post_type The post type slug.
1519 do_action( 'quick_edit_custom_box', $column_name, $screen->post_type );
1524 <p class="submit inline-edit-save">
1525 <button type="button" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></button>
1526 <?php if ( ! $bulk ) {
1527 wp_nonce_field( 'inlineeditnonce', '_inline_edit', false );
1529 <button type="button" class="button-primary save alignright"><?php _e( 'Update' ); ?></button>
1530 <span class="spinner"></span>
1532 submit_button( __( 'Update' ), 'button-primary alignright', 'bulk_edit', false );
1534 <input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" />
1535 <input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" />
1536 <?php if ( ! $bulk && ! post_type_supports( $screen->post_type, 'author' ) ) { ?>
1537 <input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
1539 <span class="error" style="display:none"></span>
1540 <br class="clear" />
1547 </tbody></table></form>