]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/class-wp-posts-list-table.php
Wordpress 4.5.3-scripts
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-posts-list-table.php
1 <?php
2 /**
3  * List Table API: WP_Posts_List_Table class
4  *
5  * @package WordPress
6  * @subpackage Administration
7  * @since 3.1.0
8  */
9
10 /**
11  * Core class used to implement displaying posts in a list table.
12  *
13  * @since 3.1.0
14  * @access private
15  *
16  * @see WP_List_Table
17  */
18 class WP_Posts_List_Table extends WP_List_Table {
19
20         /**
21          * Whether the items should be displayed hierarchically or linearly.
22          *
23          * @since 3.1.0
24          * @var bool
25          * @access protected
26          */
27         protected $hierarchical_display;
28
29         /**
30          * Holds the number of pending comments for each post.
31          *
32          * @since 3.1.0
33          * @var array
34          * @access protected
35          */
36         protected $comment_pending_count;
37
38         /**
39          * Holds the number of posts for this user.
40          *
41          * @since 3.1.0
42          * @var int
43          * @access private
44          */
45         private $user_posts_count;
46
47         /**
48          * Holds the number of posts which are sticky.
49          *
50          * @since 3.1.0
51          * @var int
52          * @access private
53          */
54         private $sticky_posts_count = 0;
55
56         private $is_trash;
57
58         /**
59          * Current level for output.
60          *
61          * @since 4.3.0
62          * @access protected
63          * @var int
64          */
65         protected $current_level = 0;
66
67         /**
68          * Constructor.
69          *
70          * @since 3.1.0
71          * @access public
72          *
73          * @see WP_List_Table::__construct() for more information on default arguments.
74          *
75          * @global object $post_type_object
76          * @global wpdb   $wpdb
77          *
78          * @param array $args An associative array of arguments.
79          */
80         public function __construct( $args = array() ) {
81                 global $post_type_object, $wpdb;
82
83                 parent::__construct( array(
84                         'plural' => 'posts',
85                         'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
86                 ) );
87
88                 $post_type        = $this->screen->post_type;
89                 $post_type_object = get_post_type_object( $post_type );
90
91                 $exclude_states   = get_post_stati( array(
92                         'show_in_admin_all_list' => false,
93                 ) );
94                 $this->user_posts_count = intval( $wpdb->get_var( $wpdb->prepare( "
95                         SELECT COUNT( 1 )
96                         FROM $wpdb->posts
97                         WHERE post_type = %s
98                         AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
99                         AND post_author = %d
100                 ", $post_type, get_current_user_id() ) ) );
101
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();
104                 }
105
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 ) );
109                 }
110         }
111
112         /**
113          * Sets whether the table layout should be hierarchical or not.
114          *
115          * @since 4.2.0
116          *
117          * @param bool $display Whether the table layout should be hierarchical.
118          */
119         public function set_hierarchical_display( $display ) {
120                 $this->hierarchical_display = $display;
121         }
122
123         /**
124          *
125          * @return bool
126          */
127         public function ajax_user_can() {
128                 return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts );
129         }
130
131         /**
132          *
133          * @global array    $avail_post_stati
134          * @global WP_Query $wp_query
135          * @global int      $per_page
136          * @global string   $mode
137          */
138         public function prepare_items() {
139                 global $avail_post_stati, $wp_query, $per_page, $mode;
140
141                 // is going to call wp()
142                 $avail_post_stati = wp_edit_posts_query();
143
144                 $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' === $wp_query->query['orderby'] );
145
146                 $post_type = $this->screen->post_type;
147                 $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
148
149                 /** This filter is documented in wp-admin/includes/post.php */
150                 $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
151
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;
156                 } else {
157                         $post_counts = (array) wp_count_posts( $post_type, 'readable' );
158
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;
165                         } else {
166                                 $total_items = array_sum( $post_counts );
167
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 ];
171                                 }
172                         }
173                 }
174
175                 if ( ! empty( $_REQUEST['mode'] ) ) {
176                         $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
177                         set_user_setting( 'posts_list_mode', $mode );
178                 } else {
179                         $mode = get_user_setting( 'posts_list_mode', 'list' );
180                 }
181
182                 $this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] === 'trash';
183
184                 $this->set_pagination_args( array(
185                         'total_items' => $total_items,
186                         'per_page' => $per_page
187                 ) );
188         }
189
190         /**
191          *
192          * @return bool
193          */
194         public function has_items() {
195                 return have_posts();
196         }
197
198         /**
199          * @access public
200          */
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;
204                 else
205                         echo get_post_type_object( $this->screen->post_type )->labels->not_found;
206         }
207
208         /**
209          * Determine if the current view is the "All" view.
210          *
211          * @since 4.2.0
212          *
213          * @return bool Whether the current view is the "All" view.
214          */
215         protected function is_base_request() {
216                 $vars = $_GET;
217                 unset( $vars['paged'] );
218
219                 if ( empty( $vars ) ) {
220                         return true;
221                 } elseif ( 1 === count( $vars ) && ! empty( $vars['post_type'] ) ) {
222                         return $this->screen->post_type === $vars['post_type'];
223                 }
224
225                 return 1 === count( $vars ) && ! empty( $vars['mode'] );
226         }
227
228         /**
229          * Helper to create links to edit.php with params.
230          *
231          * @since 4.4.0
232          * @access protected
233          *
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.
238          */
239         protected function get_edit_link( $args, $label, $class = '' ) {
240                 $url = add_query_arg( $args, 'edit.php' );
241
242                 $class_html = '';
243                 if ( ! empty( $class ) ) {
244                          $class_html = sprintf(
245                                 ' class="%s"',
246                                 esc_attr( $class )
247                         );
248                 }
249
250                 return sprintf(
251                         '<a href="%s"%s>%s</a>',
252                         esc_url( $url ),
253                         $class_html,
254                         $label
255                 );
256         }
257
258         /**
259          *
260          * @global array $locked_post_status This seems to be deprecated.
261          * @global array $avail_post_stati
262          * @return array
263          */
264         protected function get_views() {
265                 global $locked_post_status, $avail_post_stati;
266
267                 $post_type = $this->screen->post_type;
268
269                 if ( !empty($locked_post_status) )
270                         return array();
271
272                 $status_links = array();
273                 $num_posts = wp_count_posts( $post_type, 'readable' );
274                 $total_posts = array_sum( (array) $num_posts );
275                 $class = '';
276
277                 $current_user_id = get_current_user_id();
278                 $all_args = array( 'post_type' => $post_type );
279                 $mine = '';
280
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;
284                 }
285
286                 if ( $this->user_posts_count && $this->user_posts_count !== $total_posts ) {
287                         if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) ) {
288                                 $class = 'current';
289                         }
290
291                         $mine_args = array(
292                                 'post_type' => $post_type,
293                                 'author' => $current_user_id
294                         );
295
296                         $mine_inner_html = sprintf(
297                                 _nx(
298                                         'Mine <span class="count">(%s)</span>',
299                                         'Mine <span class="count">(%s)</span>',
300                                         $this->user_posts_count,
301                                         'posts'
302                                 ),
303                                 number_format_i18n( $this->user_posts_count )
304                         );
305
306                         $mine = $this->get_edit_link( $mine_args, $mine_inner_html, $class );
307
308                         $all_args['all_posts'] = 1;
309                         $class = '';
310                 }
311
312                 if ( empty( $class ) && ( $this->is_base_request() || isset( $_REQUEST['all_posts'] ) ) ) {
313                         $class = 'current';
314                 }
315
316                 $all_inner_html = sprintf(
317                         _nx(
318                                 'All <span class="count">(%s)</span>',
319                                 'All <span class="count">(%s)</span>',
320                                 $total_posts,
321                                 'posts'
322                         ),
323                         number_format_i18n( $total_posts )
324                 );
325
326                 $status_links['all'] = $this->get_edit_link( $all_args, $all_inner_html, $class );
327                 if ( $mine ) {
328                         $status_links['mine'] = $mine;
329                 }
330
331                 foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
332                         $class = '';
333
334                         $status_name = $status->name;
335
336                         if ( ! in_array( $status_name, $avail_post_stati ) || empty( $num_posts->$status_name ) ) {
337                                 continue;
338                         }
339
340                         if ( isset($_REQUEST['post_status']) && $status_name === $_REQUEST['post_status'] ) {
341                                 $class = 'current';
342                         }
343
344                         $status_args = array(
345                                 'post_status' => $status_name,
346                                 'post_type' => $post_type,
347                         );
348
349                         $status_label = sprintf(
350                                 translate_nooped_plural( $status->label_count, $num_posts->$status_name ),
351                                 number_format_i18n( $num_posts->$status_name )
352                         );
353
354                         $status_links[ $status_name ] = $this->get_edit_link( $status_args, $status_label, $class );
355                 }
356
357                 if ( ! empty( $this->sticky_posts_count ) ) {
358                         $class = ! empty( $_REQUEST['show_sticky'] ) ? 'current' : '';
359
360                         $sticky_args = array(
361                                 'post_type'     => $post_type,
362                                 'show_sticky' => 1
363                         );
364
365                         $sticky_inner_html = sprintf(
366                                 _nx(
367                                         'Sticky <span class="count">(%s)</span>',
368                                         'Sticky <span class="count">(%s)</span>',
369                                         $this->sticky_posts_count,
370                                         'posts'
371                                 ),
372                                 number_format_i18n( $this->sticky_posts_count )
373                         );
374
375                         $sticky_link = array(
376                                 'sticky' => $this->get_edit_link( $sticky_args, $sticky_inner_html, $class )
377                         );
378
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 ) );
382                 }
383
384                 return $status_links;
385         }
386
387         /**
388          *
389          * @return array
390          */
391         protected function get_bulk_actions() {
392                 $actions = array();
393                 $post_type_obj = get_post_type_object( $this->screen->post_type );
394
395                 if ( current_user_can( $post_type_obj->cap->edit_posts ) ) {
396                         if ( $this->is_trash ) {
397                                 $actions['untrash'] = __( 'Restore' );
398                         } else {
399                                 $actions['edit'] = __( 'Edit' );
400                         }
401                 }
402
403                 if ( current_user_can( $post_type_obj->cap->delete_posts ) ) {
404                         if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) {
405                                 $actions['delete'] = __( 'Delete Permanently' );
406                         } else {
407                                 $actions['trash'] = __( 'Move to Trash' );
408                         }
409                 }
410
411                 return $actions;
412         }
413
414         /**
415          * @global int $cat
416          * @param string $which
417          */
418         protected function extra_tablenav( $which ) {
419                 global $cat;
420 ?>
421                 <div class="alignleft actions">
422 <?php
423                 if ( 'top' === $which && !is_singular() ) {
424
425                         $this->months_dropdown( $this->screen->post_type );
426
427                         if ( is_object_in_taxonomy( $this->screen->post_type, 'category' ) ) {
428                                 $dropdown_options = array(
429                                         'show_option_all' => get_taxonomy( 'category' )->labels->all_items,
430                                         'hide_empty' => 0,
431                                         'hierarchical' => 1,
432                                         'show_count' => 0,
433                                         'orderby' => 'name',
434                                         'selected' => $cat
435                                 );
436
437                                 echo '<label class="screen-reader-text" for="cat">' . __( 'Filter by category' ) . '</label>';
438                                 wp_dropdown_categories( $dropdown_options );
439                         }
440
441                         /**
442                          * Fires before the Filter button on the Posts and Pages list tables.
443                          *
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.
446                          *
447                          * @since 2.1.0
448                          * @since 4.4.0 The `$post_type` parameter was added.
449                          *
450                          * @param string $post_type The post type slug.
451                          */
452                         do_action( 'restrict_manage_posts', $this->screen->post_type );
453
454                         submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
455                 }
456
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 );
459                 }
460 ?>
461                 </div>
462 <?php
463                 /**
464                  * Fires immediately following the closing "actions" div in the tablenav for the posts
465                  * list table.
466                  *
467                  * @since 4.4.0
468                  *
469                  * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
470                  */
471                 do_action( 'manage_posts_extra_tablenav', $which );
472         }
473
474         /**
475          *
476          * @return string
477          */
478         public function current_action() {
479                 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
480                         return 'delete_all';
481
482                 return parent::current_action();
483         }
484
485         /**
486          *
487          * @return array
488          */
489         protected function get_table_classes() {
490                 return array( 'widefat', 'fixed', 'striped', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
491         }
492
493         /**
494          *
495          * @return array
496          */
497         public function get_columns() {
498                 $post_type = $this->screen->post_type;
499
500                 $posts_columns = array();
501
502                 $posts_columns['cb'] = '<input type="checkbox" />';
503
504                 /* translators: manage posts column name */
505                 $posts_columns['title'] = _x( 'Title', 'column name' );
506
507                 if ( post_type_supports( $post_type, 'author' ) ) {
508                         $posts_columns['author'] = __( 'Author' );
509                 }
510
511                 $taxonomies = get_object_taxonomies( $post_type, 'objects' );
512                 $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
513
514                 /**
515                  * Filter the taxonomy columns in the Posts list table.
516                  *
517                  * The dynamic portion of the hook name, `$post_type`, refers to the post
518                  * type slug.
519                  *
520                  * @since 3.5.0
521                  *
522                  * @param array  $taxonomies Array of taxonomies to show columns for.
523                  * @param string $post_type  The post type.
524                  */
525                 $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
526                 $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
527
528                 foreach ( $taxonomies as $taxonomy ) {
529                         if ( 'category' === $taxonomy )
530                                 $column_key = 'categories';
531                         elseif ( 'post_tag' === $taxonomy )
532                                 $column_key = 'tags';
533                         else
534                                 $column_key = 'taxonomy-' . $taxonomy;
535
536                         $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
537                 }
538
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>';
542
543                 $posts_columns['date'] = __( 'Date' );
544
545                 if ( 'page' === $post_type ) {
546
547                         /**
548                          * Filter the columns displayed in the Pages list table.
549                          *
550                          * @since 2.5.0
551                          *
552                          * @param array $post_columns An array of column names.
553                          */
554                         $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
555                 } else {
556
557                         /**
558                          * Filter the columns displayed in the Posts list table.
559                          *
560                          * @since 1.5.0
561                          *
562                          * @param array  $posts_columns An array of column names.
563                          * @param string $post_type     The post type slug.
564                          */
565                         $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
566                 }
567
568                 /**
569                  * Filter the columns displayed in the Posts list table for a specific post type.
570                  *
571                  * The dynamic portion of the hook name, `$post_type`, refers to the post type slug.
572                  *
573                  * @since 3.0.0
574                  *
575                  * @param array $post_columns An array of column names.
576                  */
577                 return apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
578         }
579
580         /**
581          *
582          * @return array
583          */
584         protected function get_sortable_columns() {
585                 return array(
586                         'title'    => 'title',
587                         'parent'   => 'parent',
588                         'comments' => 'comment_count',
589                         'date'     => array( 'date', true )
590                 );
591         }
592
593         /**
594          * @global WP_Query $wp_query
595          * @global int $per_page
596          * @param array $posts
597          * @param int $level
598          */
599         public function display_rows( $posts = array(), $level = 0 ) {
600                 global $wp_query, $per_page;
601
602                 if ( empty( $posts ) )
603                         $posts = $wp_query->posts;
604
605                 add_filter( 'the_title', 'esc_html' );
606
607                 if ( $this->hierarchical_display ) {
608                         $this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page );
609                 } else {
610                         $this->_display_rows( $posts, $level );
611                 }
612         }
613
614         /**
615          * @param array $posts
616          * @param int $level
617          */
618         private function _display_rows( $posts, $level = 0 ) {
619                 // Create array of post IDs.
620                 $post_ids = array();
621
622                 foreach ( $posts as $a_post )
623                         $post_ids[] = $a_post->ID;
624
625                 $this->comment_pending_count = get_pending_comments_num( $post_ids );
626
627                 foreach ( $posts as $post )
628                         $this->single_row( $post, $level );
629         }
630
631         /**
632          * @global wpdb    $wpdb
633          * @global WP_Post $post
634          * @param array $pages
635          * @param int $pagenum
636          * @param int $per_page
637          */
638         private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
639                 global $wpdb;
640
641                 $level = 0;
642
643                 if ( ! $pages ) {
644                         $pages = get_pages( array( 'sort_column' => 'menu_order' ) );
645
646                         if ( ! $pages )
647                                 return;
648                 }
649
650                 /*
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
656                  */
657                 if ( empty( $_REQUEST['s'] ) ) {
658
659                         $top_level_pages = array();
660                         $children_pages = array();
661
662                         foreach ( $pages as $page ) {
663
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 );
669                                 }
670
671                                 if ( 0 == $page->post_parent )
672                                         $top_level_pages[] = $page;
673                                 else
674                                         $children_pages[ $page->post_parent ][] = $page;
675                         }
676
677                         $pages = &$top_level_pages;
678                 }
679
680                 $count = 0;
681                 $start = ( $pagenum - 1 ) * $per_page;
682                 $end = $start + $per_page;
683                 $to_display = array();
684
685                 foreach ( $pages as $page ) {
686                         if ( $count >= $end )
687                                 break;
688
689                         if ( $count >= $start ) {
690                                 $to_display[$page->ID] = $level;
691                         }
692
693                         $count++;
694
695                         if ( isset( $children_pages ) )
696                                 $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
697                 }
698
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 )
704                                                 break;
705
706                                         if ( $count >= $start ) {
707                                                 $to_display[$op->ID] = 0;
708                                         }
709
710                                         $count++;
711                                 }
712                         }
713                 }
714
715                 $ids = array_keys( $to_display );
716                 _prime_post_caches( $ids );
717
718                 if ( ! isset( $GLOBALS['post'] ) ) {
719                         $GLOBALS['post'] = reset( $ids );
720                 }
721
722                 foreach ( $to_display as $page_id => $level ) {
723                         echo "\t";
724                         $this->single_row( $page_id, $level );
725                 }
726         }
727
728         /**
729          * Given a top level page ID, display the nested hierarchy of sub-pages
730          * together with paging support
731          *
732          * @since 3.1.0 (Standalone function exists since 2.6.0)
733          * @since 4.2.0 Added the `$to_display` parameter.
734          *
735          * @param array $children_pages
736          * @param int $count
737          * @param int $parent
738          * @param int $level
739          * @param int $pagenum
740          * @param int $per_page
741          * @param array $to_display List of pages to be displayed. Passed by reference.
742          */
743         private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) {
744                 if ( ! isset( $children_pages[$parent] ) )
745                         return;
746
747                 $start = ( $pagenum - 1 ) * $per_page;
748                 $end = $start + $per_page;
749
750                 foreach ( $children_pages[$parent] as $page ) {
751                         if ( $count >= $end )
752                                 break;
753
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;
763                                         }
764
765                                         $my_parent = get_post( $parent_id );
766                                         $my_parents[] = $my_parent;
767                                         if ( !$my_parent->post_parent )
768                                                 break;
769                                         $my_parent = $my_parent->post_parent;
770                                 }
771                                 $num_parents = count( $my_parents );
772                                 while ( $my_parent = array_pop( $my_parents ) ) {
773                                         $to_display[$my_parent->ID] = $level - $num_parents;
774                                         $num_parents--;
775                                 }
776                         }
777
778                         if ( $count >= $start ) {
779                                 $to_display[$page->ID] = $level;
780                         }
781
782                         $count++;
783
784                         $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
785                 }
786
787                 unset( $children_pages[$parent] ); //required in order to keep track of orphans
788         }
789
790         /**
791          * Handles the checkbox column output.
792          *
793          * @since 4.3.0
794          * @access public
795          *
796          * @param WP_Post $post The current WP_Post object.
797          */
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() );
802                         ?></label>
803                         <input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" />
804                         <div class="locked-indicator"></div>
805                 <?php endif;
806         }
807
808         /**
809          * @since 4.3.0
810          * @access protected
811          *
812          * @param WP_Post $post
813          * @param string  $classes
814          * @param string  $data
815          * @param string  $primary
816          */
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 );
821                 echo '</td>';
822         }
823
824         /**
825          * Handles the title column output.
826          *
827          * @since 4.3.0
828          * @access public
829          *
830          * @global string $mode
831          *
832          * @param WP_Post $post The current WP_Post object.
833          */
834         public function column_title( $post ) {
835                 global $mode;
836
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 );
843
844                                         if ( is_null( $parent ) ) {
845                                                 break;
846                                         }
847
848                                         $this->current_level++;
849                                         $find_main_page = (int) $parent->post_parent;
850
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 );
854                                         }
855                                 }
856                         }
857                 }
858
859                 $pad = str_repeat( '&#8212; ', $this->current_level );
860                 echo "<strong>";
861
862                 $format = get_post_format( $post->ID );
863                 if ( $format ) {
864                         $label = get_post_format_string( $format );
865
866                         $format_class = 'post-state-format post-format-icon post-format-' . $format;
867
868                         $format_args = array(
869                                 'post_format' => $format,
870                                 'post_type' => $post->post_type
871                         );
872
873                         echo $this->get_edit_link( $format_args, $label . ':', $format_class );
874                 }
875
876                 $can_edit_post = current_user_can( 'edit_post', $post->ID );
877                 $title = _draft_or_post_title();
878
879                 if ( $can_edit_post && $post->post_status != 'trash' ) {
880                         printf(
881                                 '<a class="row-title" href="%s" aria-label="%s">%s%s</a>',
882                                 get_edit_post_link( $post->ID ),
883                                 /* translators: %s: post title */
884                                 esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $title ) ),
885                                 $pad,
886                                 $title
887                         );
888                 } else {
889                         echo $pad . $title;
890                 }
891                 _post_states( $post );
892
893                 if ( isset( $parent_name ) ) {
894                         $post_type_object = get_post_type_object( $post->post_type );
895                         echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
896                 }
897                 echo "</strong>\n";
898
899                 if ( $can_edit_post && $post->post_status != 'trash' ) {
900                         $lock_holder = wp_check_post_lock( $post->ID );
901
902                         if ( $lock_holder ) {
903                                 $lock_holder = get_userdata( $lock_holder );
904                                 $locked_avatar = get_avatar( $lock_holder->ID, 18 );
905                                 $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
906                         } else {
907                                 $locked_avatar = $locked_text = '';
908                         }
909
910                         echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
911                 }
912
913                 if ( ! is_post_type_hierarchical( $this->screen->post_type ) && 'excerpt' === $mode && current_user_can( 'read_post', $post->ID ) ) {
914                         the_excerpt();
915                 }
916
917                 get_inline_data( $post );
918         }
919
920         /**
921          * Handles the post date column output.
922          *
923          * @since 4.3.0
924          * @access public
925          *
926          * @global string $mode
927          *
928          * @param WP_Post $post The current WP_Post object.
929          */
930         public function column_date( $post ) {
931                 global $mode;
932
933                 if ( '0000-00-00 00:00:00' === $post->post_date ) {
934                         $t_time = $h_time = __( 'Unpublished' );
935                         $time_diff = 0;
936                 } else {
937                         $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
938                         $m_time = $post->post_date;
939                         $time = get_post_time( 'G', true, $post );
940
941                         $time_diff = time() - $time;
942
943                         if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
944                                 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
945                         } else {
946                                 $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
947                         }
948                 }
949
950                 if ( 'publish' === $post->post_status ) {
951                         _e( 'Published' );
952                 } elseif ( 'future' === $post->post_status ) {
953                         if ( $time_diff > 0 ) {
954                                 echo '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>';
955                         } else {
956                                 _e( 'Scheduled' );
957                         }
958                 } else {
959                         _e( 'Last Modified' );
960                 }
961                 echo '<br />';
962                 if ( 'excerpt' === $mode ) {
963                         /**
964                          * Filter the published time of the post.
965                          *
966                          * If `$mode` equals 'excerpt', the published time and date are both displayed.
967                          * If `$mode` equals 'list' (default), the publish date is displayed, with the
968                          * time and date together available as an abbreviation definition.
969                          *
970                          * @since 2.5.1
971                          *
972                          * @param string  $t_time      The published time.
973                          * @param WP_Post $post        Post object.
974                          * @param string  $column_name The column name.
975                          * @param string  $mode        The list display mode ('excerpt' or 'list').
976                          */
977                         echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
978                 } else {
979
980                         /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
981                         echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . '</abbr>';
982                 }
983         }
984
985         /**
986          * Handles the comments column output.
987          *
988          * @since 4.3.0
989          * @access public
990          *
991          * @param WP_Post $post The current WP_Post object.
992          */
993         public function column_comments( $post ) {
994                 ?>
995                 <div class="post-com-count-wrapper">
996                 <?php
997                         $pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0;
998
999                         $this->comments_bubble( $post->ID, $pending_comments );
1000                 ?>
1001                 </div>
1002                 <?php
1003         }
1004
1005         /**
1006          * Handles the post author column output.
1007          *
1008          * @since 4.3.0
1009          * @access public
1010          *
1011          * @param WP_Post $post The current WP_Post object.
1012          */
1013         public function column_author( $post ) {
1014                 $args = array(
1015                         'post_type' => $post->post_type,
1016                         'author' => get_the_author_meta( 'ID' )
1017                 );
1018                 echo $this->get_edit_link( $args, get_the_author() );
1019         }
1020
1021         /**
1022          * Handles the default column output.
1023          *
1024          * @since 4.3.0
1025          * @access public
1026          *
1027          * @param WP_Post $post        The current WP_Post object.
1028          * @param string  $column_name The current column name.
1029          */
1030         public function column_default( $post, $column_name ) {
1031                 if ( 'categories' === $column_name ) {
1032                         $taxonomy = 'category';
1033                 } elseif ( 'tags' === $column_name ) {
1034                         $taxonomy = 'post_tag';
1035                 } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) {
1036                         $taxonomy = substr( $column_name, 9 );
1037                 } else {
1038                         $taxonomy = false;
1039                 }
1040                 if ( $taxonomy ) {
1041                         $taxonomy_object = get_taxonomy( $taxonomy );
1042                         $terms = get_the_terms( $post->ID, $taxonomy );
1043                         if ( is_array( $terms ) ) {
1044                                 $out = array();
1045                                 foreach ( $terms as $t ) {
1046                                         $posts_in_term_qv = array();
1047                                         if ( 'post' != $post->post_type ) {
1048                                                 $posts_in_term_qv['post_type'] = $post->post_type;
1049                                         }
1050                                         if ( $taxonomy_object->query_var ) {
1051                                                 $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
1052                                         } else {
1053                                                 $posts_in_term_qv['taxonomy'] = $taxonomy;
1054                                                 $posts_in_term_qv['term'] = $t->slug;
1055                                         }
1056
1057                                         $label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) );
1058                                         $out[] = $this->get_edit_link( $posts_in_term_qv, $label );
1059                                 }
1060                                 /* translators: used between list items, there is a space after the comma */
1061                                 echo join( __( ', ' ), $out );
1062                         } else {
1063                                 echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
1064                         }
1065                         return;
1066                 }
1067
1068                 if ( is_post_type_hierarchical( $post->post_type ) ) {
1069
1070                         /**
1071                          * Fires in each custom column on the Posts list table.
1072                          *
1073                          * This hook only fires if the current post type is hierarchical,
1074                          * such as pages.
1075                          *
1076                          * @since 2.5.0
1077                          *
1078                          * @param string $column_name The name of the column to display.
1079                          * @param int    $post_id     The current post ID.
1080                          */
1081                         do_action( 'manage_pages_custom_column', $column_name, $post->ID );
1082                 } else {
1083
1084                         /**
1085                          * Fires in each custom column in the Posts list table.
1086                          *
1087                          * This hook only fires if the current post type is non-hierarchical,
1088                          * such as posts.
1089                          *
1090                          * @since 1.5.0
1091                          *
1092                          * @param string $column_name The name of the column to display.
1093                          * @param int    $post_id     The current post ID.
1094                          */
1095                         do_action( 'manage_posts_custom_column', $column_name, $post->ID );
1096                 }
1097
1098                 /**
1099                  * Fires for each custom column of a specific post type in the Posts list table.
1100                  *
1101                  * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
1102                  *
1103                  * @since 3.1.0
1104                  *
1105                  * @param string $column_name The name of the column to display.
1106                  * @param int    $post_id     The current post ID.
1107                  */
1108                 do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
1109         }
1110
1111         /**
1112          * @global WP_Post $post
1113          *
1114          * @param int|WP_Post $post
1115          * @param int         $level
1116          */
1117         public function single_row( $post, $level = 0 ) {
1118                 $global_post = get_post();
1119
1120                 $post = get_post( $post );
1121                 $this->current_level = $level;
1122
1123                 $GLOBALS['post'] = $post;
1124                 setup_postdata( $post );
1125
1126                 $classes = 'iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
1127
1128                 $lock_holder = wp_check_post_lock( $post->ID );
1129                 if ( $lock_holder ) {
1130                         $classes .= ' wp-locked';
1131                 }
1132
1133                 if ( $post->post_parent ) {
1134                     $count = count( get_post_ancestors( $post->ID ) );
1135                     $classes .= ' level-'. $count;
1136                 } else {
1137                     $classes .= ' level-0';
1138                 }
1139         ?>
1140                 <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>">
1141                         <?php $this->single_row_columns( $post ); ?>
1142                 </tr>
1143         <?php
1144                 $GLOBALS['post'] = $global_post;
1145         }
1146
1147         /**
1148          * Gets the name of the default primary column.
1149          *
1150          * @since 4.3.0
1151          * @access protected
1152          *
1153          * @return string Name of the default primary column, in this case, 'title'.
1154          */
1155         protected function get_default_primary_column_name() {
1156                 return 'title';
1157         }
1158
1159         /**
1160          * Generates and displays row action links.
1161          *
1162          * @since 4.3.0
1163          * @access protected
1164          *
1165          * @param object $post        Post being acted upon.
1166          * @param string $column_name Current column name.
1167          * @param string $primary     Primary column name.
1168          * @return string Row actions output for posts.
1169          */
1170         protected function handle_row_actions( $post, $column_name, $primary ) {
1171                 if ( $primary !== $column_name ) {
1172                         return '';
1173                 }
1174
1175                 $post_type_object = get_post_type_object( $post->post_type );
1176                 $can_edit_post = current_user_can( 'edit_post', $post->ID );
1177                 $actions = array();
1178                 $title = _draft_or_post_title();
1179
1180                 if ( $can_edit_post && 'trash' != $post->post_status ) {
1181                         $actions['edit'] = sprintf(
1182                                 '<a href="%s" aria-label="%s">%s</a>',
1183                                 get_edit_post_link( $post->ID ),
1184                                 /* translators: %s: post title */
1185                                 esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ),
1186                                 __( 'Edit' )
1187                         );
1188                         $actions['inline hide-if-no-js'] = sprintf(
1189                                 '<a href="#" class="editinline" aria-label="%s">%s</a>',
1190                                 /* translators: %s: post title */
1191                                 esc_attr( sprintf( __( 'Quick edit &#8220;%s&#8221; inline' ), $title ) ),
1192                                 __( 'Quick&nbsp;Edit' )
1193                         );
1194                 }
1195
1196                 if ( current_user_can( 'delete_post', $post->ID ) ) {
1197                         if ( 'trash' === $post->post_status ) {
1198                                 $actions['untrash'] = sprintf(
1199                                         '<a href="%s" aria-label="%s">%s</a>',
1200                                         wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ),
1201                                         /* translators: %s: post title */
1202                                         esc_attr( sprintf( __( 'Restore &#8220;%s&#8221; from the Trash' ), $title ) ),
1203                                         __( 'Restore' )
1204                                 );
1205                         } elseif ( EMPTY_TRASH_DAYS ) {
1206                                 $actions['trash'] = sprintf(
1207                                         '<a href="%s" class="submitdelete" aria-label="%s">%s</a>',
1208                                         get_delete_post_link( $post->ID ),
1209                                         /* translators: %s: post title */
1210                                         esc_attr( sprintf( __( 'Move &#8220;%s&#8221; to the Trash' ), $title ) ),
1211                                         _x( 'Trash', 'verb' )
1212                                 );
1213                         }
1214                         if ( 'trash' === $post->post_status || ! EMPTY_TRASH_DAYS ) {
1215                                 $actions['delete'] = sprintf(
1216                                         '<a href="%s" class="submitdelete" aria-label="%s">%s</a>',
1217                                         get_delete_post_link( $post->ID, '', true ),
1218                                         /* translators: %s: post title */
1219                                         esc_attr( sprintf( __( 'Delete &#8220;%s&#8221; permanently' ), $title ) ),
1220                                         __( 'Delete Permanently' )
1221                                 );
1222                         }
1223                 }
1224
1225                 if ( is_post_type_viewable( $post_type_object ) ) {
1226                         if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
1227                                 if ( $can_edit_post ) {
1228                                         $preview_link = get_preview_post_link( $post );
1229                                         $actions['view'] = sprintf(
1230                                                 '<a href="%s" rel="permalink" aria-label="%s">%s</a>',
1231                                                 esc_url( $preview_link ),
1232                                                 /* translators: %s: post title */
1233                                                 esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ),
1234                                                 __( 'Preview' )
1235                                         );
1236                                 }
1237                         } elseif ( 'trash' != $post->post_status ) {
1238                                 $actions['view'] = sprintf(
1239                                         '<a href="%s" rel="permalink" aria-label="%s">%s</a>',
1240                                         get_permalink( $post->ID ),
1241                                         /* translators: %s: post title */
1242                                         esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ),
1243                                         __( 'View' )
1244                                 );
1245                         }
1246                 }
1247
1248                 if ( is_post_type_hierarchical( $post->post_type ) ) {
1249
1250                         /**
1251                          * Filter the array of row action links on the Pages list table.
1252                          *
1253                          * The filter is evaluated only for hierarchical post types.
1254                          *
1255                          * @since 2.8.0
1256                          *
1257                          * @param array $actions An array of row action links. Defaults are
1258                          *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
1259                          *                         'Delete Permanently', 'Preview', and 'View'.
1260                          * @param WP_Post $post The post object.
1261                          */
1262                         $actions = apply_filters( 'page_row_actions', $actions, $post );
1263                 } else {
1264
1265                         /**
1266                          * Filter the array of row action links on the Posts list table.
1267                          *
1268                          * The filter is evaluated only for non-hierarchical post types.
1269                          *
1270                          * @since 2.8.0
1271                          *
1272                          * @param array $actions An array of row action links. Defaults are
1273                          *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
1274                          *                         'Delete Permanently', 'Preview', and 'View'.
1275                          * @param WP_Post $post The post object.
1276                          */
1277                         $actions = apply_filters( 'post_row_actions', $actions, $post );
1278                 }
1279
1280                 return $this->row_actions( $actions );
1281         }
1282
1283         /**
1284          * Outputs the hidden row displayed when inline editing
1285          *
1286          * @since 3.1.0
1287          *
1288          * @global string $mode
1289          */
1290         public function inline_edit() {
1291                 global $mode;
1292
1293                 $screen = $this->screen;
1294
1295                 $post = get_default_post_to_edit( $screen->post_type );
1296                 $post_type_object = get_post_type_object( $screen->post_type );
1297
1298                 $taxonomy_names = get_object_taxonomies( $screen->post_type );
1299                 $hierarchical_taxonomies = array();
1300                 $flat_taxonomies = array();
1301                 foreach ( $taxonomy_names as $taxonomy_name ) {
1302
1303                         $taxonomy = get_taxonomy( $taxonomy_name );
1304
1305                         $show_in_quick_edit = $taxonomy->show_in_quick_edit;
1306
1307                         /**
1308                          * Filter whether the current taxonomy should be shown in the Quick Edit panel.
1309                          *
1310                          * @since 4.2.0
1311                          *
1312                          * @param bool   $show_in_quick_edit Whether to show the current taxonomy in Quick Edit.
1313                          * @param string $taxonomy_name      Taxonomy name.
1314                          * @param string $post_type          Post type of current Quick Edit post.
1315                          */
1316                         if ( ! apply_filters( 'quick_edit_show_taxonomy', $show_in_quick_edit, $taxonomy_name, $screen->post_type ) ) {
1317                                 continue;
1318                         }
1319
1320                         if ( $taxonomy->hierarchical )
1321                                 $hierarchical_taxonomies[] = $taxonomy;
1322                         else
1323                                 $flat_taxonomies[] = $taxonomy;
1324                 }
1325
1326                 $m = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list';
1327                 $can_publish = current_user_can( $post_type_object->cap->publish_posts );
1328                 $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
1329
1330         ?>
1331
1332         <form method="get"><table style="display: none"><tbody id="inlineedit">
1333                 <?php
1334                 $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page';
1335                 $bulk = 0;
1336                 while ( $bulk < 2 ) { ?>
1337
1338                 <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-" . $screen->post_type;
1339                         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}";
1340                 ?>" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
1341
1342                 <fieldset class="inline-edit-col-left">
1343                         <legend class="inline-edit-legend"><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></legend>
1344                         <div class="inline-edit-col">
1345         <?php
1346
1347         if ( post_type_supports( $screen->post_type, 'title' ) ) :
1348                 if ( $bulk ) : ?>
1349                         <div id="bulk-title-div">
1350                                 <div id="bulk-titles"></div>
1351                         </div>
1352
1353         <?php else : // $bulk ?>
1354
1355                         <label>
1356                                 <span class="title"><?php _e( 'Title' ); ?></span>
1357                                 <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span>
1358                         </label>
1359
1360                         <label>
1361                                 <span class="title"><?php _e( 'Slug' ); ?></span>
1362                                 <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span>
1363                         </label>
1364
1365         <?php endif; // $bulk
1366         endif; // post_type_supports title ?>
1367
1368         <?php if ( !$bulk ) : ?>
1369                         <fieldset class="inline-edit-date">
1370                         <legend><span class="title"><?php _e( 'Date' ); ?></span></legend>
1371                                 <?php touch_time( 1, 1, 0, 1 ); ?>
1372                         </fieldset>
1373                         <br class="clear" />
1374         <?php endif; // $bulk
1375
1376                 if ( post_type_supports( $screen->post_type, 'author' ) ) :
1377                         $authors_dropdown = '';
1378
1379                         if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) :
1380                                 $users_opt = array(
1381                                         'hide_if_only_one_author' => false,
1382                                         'who' => 'authors',
1383                                         'name' => 'post_author',
1384                                         'class'=> 'authors',
1385                                         'multi' => 1,
1386                                         'echo' => 0,
1387                                         'show' => 'display_name_with_login',
1388                                 );
1389                                 if ( $bulk )
1390                                         $users_opt['show_option_none'] = __( '&mdash; No Change &mdash;' );
1391
1392                                 if ( $authors = wp_dropdown_users( $users_opt ) ) :
1393                                         $authors_dropdown  = '<label class="inline-edit-author">';
1394                                         $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
1395                                         $authors_dropdown .= $authors;
1396                                         $authors_dropdown .= '</label>';
1397                                 endif;
1398                         endif; // authors
1399         ?>
1400
1401         <?php if ( !$bulk ) echo $authors_dropdown;
1402         endif; // post_type_supports author
1403
1404         if ( !$bulk && $can_publish ) :
1405         ?>
1406
1407                         <div class="inline-edit-group wp-clearfix">
1408                                 <label class="alignleft">
1409                                         <span class="title"><?php _e( 'Password' ); ?></span>
1410                                         <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
1411                                 </label>
1412
1413                                 <em class="alignleft inline-edit-or">
1414                                         <?php
1415                                         /* translators: Between password field and private checkbox on post quick edit interface */
1416                                         _e( '&ndash;OR&ndash;' );
1417                                         ?>
1418                                 </em>
1419                                 <label class="alignleft inline-edit-private">
1420                                         <input type="checkbox" name="keep_private" value="private" />
1421                                         <span class="checkbox-title"><?php _e( 'Private' ); ?></span>
1422                                 </label>
1423                         </div>
1424
1425         <?php endif; ?>
1426
1427                 </div></fieldset>
1428
1429         <?php if ( count( $hierarchical_taxonomies ) && !$bulk ) : ?>
1430
1431                 <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col">
1432
1433         <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?>
1434
1435                         <span class="title inline-edit-categories-label"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
1436                         <input type="hidden" name="<?php echo ( $taxonomy->name === 'category' ) ? 'post_category[]' : 'tax_input[' . esc_attr( $taxonomy->name ) . '][]'; ?>" value="0" />
1437                         <ul class="cat-checklist <?php echo esc_attr( $taxonomy->name )?>-checklist">
1438                                 <?php wp_terms_checklist( null, array( 'taxonomy' => $taxonomy->name ) ) ?>
1439                         </ul>
1440
1441         <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?>
1442
1443                 </div></fieldset>
1444
1445         <?php endif; // count( $hierarchical_taxonomies ) && !$bulk ?>
1446
1447                 <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
1448
1449         <?php
1450                 if ( post_type_supports( $screen->post_type, 'author' ) && $bulk )
1451                         echo $authors_dropdown;
1452
1453                 if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) :
1454
1455                         if ( $post_type_object->hierarchical ) :
1456                 ?>
1457                         <label>
1458                                 <span class="title"><?php _e( 'Parent' ); ?></span>
1459         <?php
1460                 $dropdown_args = array(
1461                         'post_type'         => $post_type_object->name,
1462                         'selected'          => $post->post_parent,
1463                         'name'              => 'post_parent',
1464                         'show_option_none'  => __( 'Main Page (no parent)' ),
1465                         'option_none_value' => 0,
1466                         'sort_column'       => 'menu_order, post_title',
1467                 );
1468
1469                 if ( $bulk )
1470                         $dropdown_args['show_option_no_change'] =  __( '&mdash; No Change &mdash;' );
1471
1472                 /**
1473                  * Filter the arguments used to generate the Quick Edit page-parent drop-down.
1474                  *
1475                  * @since 2.7.0
1476                  *
1477                  * @see wp_dropdown_pages()
1478                  *
1479                  * @param array $dropdown_args An array of arguments.
1480                  */
1481                 $dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args );
1482
1483                 wp_dropdown_pages( $dropdown_args );
1484         ?>
1485                         </label>
1486
1487         <?php
1488                         endif; // hierarchical
1489
1490                         if ( !$bulk ) : ?>
1491
1492                         <label>
1493                                 <span class="title"><?php _e( 'Order' ); ?></span>
1494                                 <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order ?>" /></span>
1495                         </label>
1496
1497         <?php   endif; // !$bulk
1498
1499                         if ( 'page' === $screen->post_type ) :
1500         ?>
1501
1502                         <label>
1503                                 <span class="title"><?php _e( 'Template' ); ?></span>
1504                                 <select name="page_template">
1505         <?php   if ( $bulk ) : ?>
1506                                         <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1507         <?php   endif; // $bulk ?>
1508                                 <?php
1509                                         /** This filter is documented in wp-admin/includes/meta-boxes.php */
1510                                         $default_title = apply_filters( 'default_page_template_title',  __( 'Default Template' ), 'quick-edit' );
1511                                 ?>
1512                                         <option value="default"><?php echo esc_html( $default_title ); ?></option>
1513                                         <?php page_template_dropdown() ?>
1514                                 </select>
1515                         </label>
1516
1517         <?php
1518                         endif; // page post_type
1519                 endif; // page-attributes
1520         ?>
1521
1522         <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?>
1523
1524         <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
1525                 <?php if ( current_user_can( $taxonomy->cap->assign_terms ) ) : ?>
1526                         <label class="inline-edit-tags">
1527                                 <span class="title"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
1528                                 <textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr( $taxonomy->name )?>]" class="tax_input_<?php echo esc_attr( $taxonomy->name )?>"></textarea>
1529                         </label>
1530                 <?php endif; ?>
1531
1532         <?php endforeach; //$flat_taxonomies as $taxonomy ?>
1533
1534         <?php endif; // count( $flat_taxonomies ) && !$bulk  ?>
1535
1536         <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) :
1537                 if ( $bulk ) : ?>
1538
1539                         <div class="inline-edit-group wp-clearfix">
1540                 <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
1541                         <label class="alignleft">
1542                                 <span class="title"><?php _e( 'Comments' ); ?></span>
1543                                 <select name="comment_status">
1544                                         <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1545                                         <option value="open"><?php _e( 'Allow' ); ?></option>
1546                                         <option value="closed"><?php _e( 'Do not allow' ); ?></option>
1547                                 </select>
1548                         </label>
1549                 <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
1550                         <label class="alignright">
1551                                 <span class="title"><?php _e( 'Pings' ); ?></span>
1552                                 <select name="ping_status">
1553                                         <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1554                                         <option value="open"><?php _e( 'Allow' ); ?></option>
1555                                         <option value="closed"><?php _e( 'Do not allow' ); ?></option>
1556                                 </select>
1557                         </label>
1558                 <?php endif; ?>
1559                         </div>
1560
1561         <?php else : // $bulk ?>
1562
1563                         <div class="inline-edit-group wp-clearfix">
1564                         <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
1565                                 <label class="alignleft">
1566                                         <input type="checkbox" name="comment_status" value="open" />
1567                                         <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span>
1568                                 </label>
1569                         <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
1570                                 <label class="alignleft">
1571                                         <input type="checkbox" name="ping_status" value="open" />
1572                                         <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span>
1573                                 </label>
1574                         <?php endif; ?>
1575                         </div>
1576
1577         <?php endif; // $bulk
1578         endif; // post_type_supports comments or pings ?>
1579
1580                         <div class="inline-edit-group wp-clearfix">
1581                                 <label class="inline-edit-status alignleft">
1582                                         <span class="title"><?php _e( 'Status' ); ?></span>
1583                                         <select name="_status">
1584         <?php if ( $bulk ) : ?>
1585                                                 <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1586         <?php endif; // $bulk ?>
1587                                         <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?>
1588                                                 <option value="publish"><?php _e( 'Published' ); ?></option>
1589                                                 <option value="future"><?php _e( 'Scheduled' ); ?></option>
1590         <?php if ( $bulk ) : ?>
1591                                                 <option value="private"><?php _e( 'Private' ) ?></option>
1592         <?php endif; // $bulk ?>
1593                                         <?php endif; ?>
1594                                                 <option value="pending"><?php _e( 'Pending Review' ); ?></option>
1595                                                 <option value="draft"><?php _e( 'Draft' ); ?></option>
1596                                         </select>
1597                                 </label>
1598
1599         <?php if ( 'post' === $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?>
1600
1601         <?php   if ( $bulk ) : ?>
1602
1603                                 <label class="alignright">
1604                                         <span class="title"><?php _e( 'Sticky' ); ?></span>
1605                                         <select name="sticky">
1606                                                 <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1607                                                 <option value="sticky"><?php _e( 'Sticky' ); ?></option>
1608                                                 <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option>
1609                                         </select>
1610                                 </label>
1611
1612         <?php   else : // $bulk ?>
1613
1614                                 <label class="alignleft">
1615                                         <input type="checkbox" name="sticky" value="sticky" />
1616                                         <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span>
1617                                 </label>
1618
1619         <?php   endif; // $bulk ?>
1620
1621         <?php endif; // 'post' && $can_publish && current_user_can( 'edit_others_cap' ) ?>
1622
1623                         </div>
1624
1625         <?php
1626
1627         if ( $bulk && current_theme_supports( 'post-formats' ) && post_type_supports( $screen->post_type, 'post-formats' ) ) {
1628                 $post_formats = get_theme_support( 'post-formats' );
1629
1630                 ?>
1631                 <label class="alignleft">
1632                 <span class="title"><?php _ex( 'Format', 'post format' ); ?></span>
1633                 <select name="post_format">
1634                         <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1635                         <option value="0"><?php echo get_post_format_string( 'standard' ); ?></option>
1636                         <?php
1637                         if ( is_array( $post_formats[0] ) ) {
1638                                 foreach ( $post_formats[0] as $format ) {
1639                                         ?>
1640                                         <option value="<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></option>
1641                                         <?php
1642                                 }
1643                         }
1644                         ?>
1645                 </select></label>
1646         <?php
1647
1648         }
1649
1650         ?>
1651
1652                 </div></fieldset>
1653
1654         <?php
1655                 list( $columns ) = $this->get_column_info();
1656
1657                 foreach ( $columns as $column_name => $column_display_name ) {
1658                         if ( isset( $core_columns[$column_name] ) )
1659                                 continue;
1660
1661                         if ( $bulk ) {
1662
1663                                 /**
1664                                  * Fires once for each column in Bulk Edit mode.
1665                                  *
1666                                  * @since 2.7.0
1667                                  *
1668                                  * @param string  $column_name Name of the column to edit.
1669                                  * @param WP_Post $post_type   The post type slug.
1670                                  */
1671                                 do_action( 'bulk_edit_custom_box', $column_name, $screen->post_type );
1672                         } else {
1673
1674                                 /**
1675                                  * Fires once for each column in Quick Edit mode.
1676                                  *
1677                                  * @since 2.7.0
1678                                  *
1679                                  * @param string $column_name Name of the column to edit.
1680                                  * @param string $post_type   The post type slug.
1681                                  */
1682                                 do_action( 'quick_edit_custom_box', $column_name, $screen->post_type );
1683                         }
1684
1685                 }
1686         ?>
1687                 <p class="submit inline-edit-save">
1688                         <button type="button" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></button>
1689                         <?php if ( ! $bulk ) {
1690                                 wp_nonce_field( 'inlineeditnonce', '_inline_edit', false );
1691                                 ?>
1692                                 <button type="button" class="button-primary save alignright"><?php _e( 'Update' ); ?></button>
1693                                 <span class="spinner"></span>
1694                         <?php } else {
1695                                 submit_button( __( 'Update' ), 'button-primary alignright', 'bulk_edit', false );
1696                         } ?>
1697                         <input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" />
1698                         <input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" />
1699                         <?php if ( ! $bulk && ! post_type_supports( $screen->post_type, 'author' ) ) { ?>
1700                                 <input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
1701                         <?php } ?>
1702                         <span class="error" style="display:none"></span>
1703                         <br class="clear" />
1704                 </p>
1705                 </td></tr>
1706         <?php
1707                 $bulk++;
1708                 }
1709 ?>
1710                 </tbody></table></form>
1711 <?php
1712         }
1713 }