diff --git a/wp-admin/includes/default-list-tables.php b/wp-admin/includes/default-list-tables.php index 3e523d612f..6706ec31d0 100644 --- a/wp-admin/includes/default-list-tables.php +++ b/wp-admin/includes/default-list-tables.php @@ -12,15 +12,24 @@ require_once('list-table.php'); */ class WP_Posts_Table extends WP_List_Table { - + /** * Wether the items should be displayed hierarchically or linearly * * @since 3.1.0 * @var bool - * @access private + * @access protected */ - var $_hierarchical_display; + var $hierarchical_display; + + /** + * Holds the number of pending comments for each post + * + * @since 3.1.0 + * @var bool + * @access protected + */ + var $comment_pending_count; function WP_Posts_Table() { global $post_type_object, $post_type, $current_screen; @@ -53,9 +62,9 @@ class WP_Posts_Table extends WP_List_Table { $avail_post_stati = wp_edit_posts_query(); - $this->_hierarchical_display = ( $post_type_object->hierarchical && 0 === strpos( get_query_var( 'orderby' ), 'menu_order' ) ); + $this->hierarchical_display = ( $post_type_object->hierarchical && 0 === strpos( get_query_var( 'orderby' ), 'menu_order' ) ); - $total_items = $this->_hierarchical_display ? $wp_query->post_count : $wp_query->found_posts; + $total_items = $this->hierarchical_display ? $wp_query->post_count : $wp_query->found_posts; $edit_per_page = 'edit_' . $post_type . '_per_page'; $per_page = (int) get_user_option( $edit_per_page ); @@ -64,7 +73,7 @@ class WP_Posts_Table extends WP_List_Table { $per_page = apply_filters( $edit_per_page, $per_page ); $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type ); - if ( $this->_hierarchical_display ) + if ( $this->hierarchical_display ) $total_pages = ceil( $total_items / $per_page ); else $total_pages = $wp_query->max_num_pages; @@ -205,7 +214,7 @@ class WP_Posts_Table extends WP_List_Table { if ( empty( $posts ) ) $posts = $wp_query->posts; - if ( $this->_hierarchical_display ) { + if ( $this->hierarchical_display ) { $this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page ); } else { $this->_display_rows( $posts ); @@ -223,14 +232,10 @@ class WP_Posts_Table extends WP_List_Table { foreach ( $posts as $a_post ) $post_ids[] = $a_post->ID; - $comment_pending_count = get_pending_comments_num( $post_ids ); + $this->comment_pending_count = get_pending_comments_num( $post_ids ); - foreach ( $posts as $post ) { - if ( empty( $comment_pending_count[$post->ID] ) ) - $comment_pending_count[$post->ID] = 0; - - $this->_single_row( $post, $comment_pending_count[$post->ID], $mode ); - } + foreach ( $posts as $post ) + $this->single_row( $post ); } function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) { @@ -284,7 +289,7 @@ class WP_Posts_Table extends WP_List_Table { break; if ( $count >= $start ) - echo "\t" . $this->_single_row_hierarchical( $page, $level ); + echo "\t" . $this->single_row( $page, $level ); $count++; @@ -299,7 +304,7 @@ class WP_Posts_Table extends WP_List_Table { if ( $count >= $end ) break; if ( $count >= $start ) - echo "\t" . $this->_single_row_hierarchical( $op, 0 ); + echo "\t" . $this->single_row( $op, 0 ); $count++; } } @@ -345,13 +350,13 @@ class WP_Posts_Table extends WP_List_Table { } $num_parents = count( $my_parents ); while ( $my_parent = array_pop( $my_parents ) ) { - echo "\t" . $this->_single_row_hierarchical( $my_parent, $level - $num_parents ); + echo "\t" . $this->single_row( $my_parent, $level - $num_parents ); $num_parents--; } } if ( $count >= $start ) - echo "\t" . $this->_single_row_hierarchical( $page, $level ); + echo "\t" . $this->single_row( $page, $level ); $count++; @@ -361,185 +366,8 @@ class WP_Posts_Table extends WP_List_Table { unset( $children_pages[$parent] ); //required in order to keep track of orphans } - /** - * display one row if the page doesn't have any children - * otherwise, display the row and its children in subsequent rows - * - * @since unknown - * - * @param unknown_type $page - * @param unknown_type $level - */ - function _single_row_hierarchical( $page, $level = 0 ) { - global $post, $current_screen; - static $rowclass; - - $post = $page; - setup_postdata( $page ); - - if ( 0 == $level && (int) $page->post_parent > 0 ) { - //sent level 0 by accident, by default, or because we don't know the actual level - $find_main_page = (int) $page->post_parent; - while ( $find_main_page > 0 ) { - $parent = get_page( $find_main_page ); - - if ( is_null( $parent ) ) - break; - - $level++; - $find_main_page = (int) $parent->post_parent; - - if ( !isset( $parent_name ) ) - $parent_name = $parent->post_title; - } - } - - $page->post_title = esc_html( $page->post_title ); - $pad = str_repeat( '— ', $level ); - $id = (int) $page->ID; - $rowclass = 'alternate' == $rowclass ? '' : 'alternate'; - $title = _draft_or_post_title(); - $post_type = $page->post_type; - $post_type_object = get_post_type_object( $post_type ); -?> - -get_column_headers(); - - foreach ( $columns as $column_name => $column_display_name ) { - $class = "class=\"$column_name column-$column_name\""; - - $style = ''; - if ( in_array( $column_name, $hidden ) ) - $style = ' style="display:none;"'; - - $attributes = "$class$style"; - - switch ( $column_name ) { - - case 'cb': - ?> - cap->edit_post, $page->ID ) ) { ?> - post_date && 'date' == $column_name ) { - $t_time = $h_time = __( 'Unpublished' ); - $time_diff = 0; - } else { - $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) ); - $m_time = $page->post_date; - $time = get_post_time( 'G', true ); - - $time_diff = time() - $time; - - if ( $time_diff > 0 && $time_diff < 24*60*60 ) - $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); - else - $h_time = mysql2date( __( 'Y/m/d' ), $m_time ); - } - echo ''; - echo '' . apply_filters( 'post_date_column_time', $h_time, $page, $column_name, '' ) . ''; - echo '
'; - if ( 'publish' == $page->post_status ) { - _e( 'Published' ); - } elseif ( 'future' == $page->post_status ) { - if ( $time_diff > 0 ) - echo '' . __( 'Missed schedule' ) . ''; - else - _e( 'Scheduled' ); - } else { - _e( 'Last Modified' ); - } - echo ''; - break; - case 'title': - $attributes = 'class="post-title page-title column-title"' . $style; - $edit_link = get_edit_post_link( $page->ID ); - ?> - >cap->edit_post, $page->ID ) && $post->post_status != 'trash' ) { ?>labels->parent_item_colon . ' ' . esc_html( $parent_name ) : ''; ?> - cap->edit_post, $page->ID ) && $post->post_status != 'trash' ) { - $actions['edit'] = '' . __( 'Edit' ) . ''; - $actions['inline'] = '' . __( 'Quick Edit' ) . ''; - } - if ( current_user_can( $post_type_object->cap->delete_post, $page->ID ) ) { - if ( $post->post_status == 'trash' ) - $actions['untrash'] = "post_type . '_' . $page->ID ) . "'>" . __( 'Restore' ) . ""; - elseif ( EMPTY_TRASH_DAYS ) - $actions['trash'] = "" . __( 'Trash' ) . ""; - if ( $post->post_status == 'trash' || !EMPTY_TRASH_DAYS ) - $actions['delete'] = "post_type . '_' . $page->ID ) . "'>" . __( 'Delete Permanently' ) . ""; - } - if ( in_array( $post->post_status, array( 'pending', 'draft' ) ) ) { - if ( current_user_can( $post_type_object->cap->edit_post, $page->ID ) ) - $actions['view'] = '' . __( 'Preview' ) . ''; - } elseif ( $post->post_status != 'trash' ) { - $actions['view'] = '' . __( 'View' ) . ''; - } - $actions = apply_filters( 'page_row_actions', $actions, $page ); - $action_count = count( $actions ); - - $i = 0; - echo '
'; - foreach ( $actions as $action => $link ) { - ++$i; - ( $i == $action_count ) ? $sep = '' : $sep = ' | '; - echo "$link$sep"; - } - echo '
'; - - get_inline_data( $post ); - echo ''; - break; - - case 'comments': - ?> - >
- ID ); - $pending_phrase = sprintf( __( '%s pending' ), number_format( $left ) ); - if ( $left ) - echo ''; - comments_number( - "" - . /* translators: comment count link */ _x( '0', 'comment count' ) . '', - "" - . /* translators: comment count link */ _x( '1', 'comment count' ) . '', - "" - . /* translators: comment count link: % will be substituted by comment count */ _x( '%', 'comment count' ) . '' - ); - if ( $left ) - echo ''; - ?> -
- - > - - > - - - - -ID ); $title = _draft_or_post_title(); $post_type_object = get_post_type_object( $post->post_type ); + $can_edit_post = current_user_can( 'edit_post', $post->ID ); ?> post_status ); ?> iedit' valign="top"> - cap->edit_post, $post->ID ) ) { ?> + hierarchical_display ) { + $attributes = 'class="post-title page-title column-title"' . $style; + + if ( 0 == $level && (int) $post->post_parent > 0 ) { + //sent level 0 by accident, by default, or because we don't know the actual level + $find_main_page = (int) $post->post_parent; + while ( $find_main_page > 0 ) { + $parent = get_page( $find_main_page ); + + if ( is_null( $parent ) ) + break; + + $level++; + $find_main_page = (int) $parent->post_parent; + + if ( !isset( $parent_name ) ) + $parent_name = $parent->post_title; + } + } + + $post->post_title = esc_html( $post->post_title ); + $pad = str_repeat( '— ', $level ); +?> + >post_status != 'trash' ) { ?>labels->parent_item_colon . ' ' . esc_html( $parent_name ) : ''; ?> + + >post_status != 'trash' ) { ?> +post_status ) { + $actions['edit'] = '' . __( 'Edit' ) . ''; + $actions['inline hide-if-no-js'] = '' . __( 'Quick Edit' ) . ''; + } + if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) { + if ( 'trash' == $post->post_status ) + $actions['untrash'] = "ID ) ), 'untrash-' . $post->post_type . '_' . $post->ID ) . "'>" . __( 'Restore' ) . ""; + elseif ( EMPTY_TRASH_DAYS ) + $actions['trash'] = "" . __( 'Trash' ) . ""; + if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS ) + $actions['delete'] = "" . __( 'Delete Permanently' ) . ""; + } + if ( in_array( $post->post_status, array( 'pending', 'draft' ) ) ) { + if ( $can_edit_post ) + $actions['view'] = '' . __( 'Preview' ) . ''; + } elseif ( 'trash' != $post->post_status ) { + $actions['view'] = '' . __( 'View' ) . ''; + } + + $actions = apply_filters( $this->hierarchical_display ? 'page_row_actions' : 'post_row_actions', $actions, $post ); + $action_count = count( $actions ); + $i = 0; + echo '
'; + foreach ( $actions as $action => $link ) { + ++$i; + ( $i == $action_count ) ? $sep = '' : $sep = ' | '; + echo "$link$sep"; + } + echo '
'; + + get_inline_data( $post ); + break; + case 'date': if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) { $t_time = $h_time = __( 'Unpublished' ); @@ -610,59 +510,19 @@ class WP_Posts_Table extends WP_List_Table { echo ''; break; - case 'title': - $attributes = 'class="post-title column-title"' . $style; - ?> - >cap->edit_post, $post->ID ) && $post->post_status != 'trash' ) { ?> - cap->edit_post, $post->ID ) && 'trash' != $post->post_status ) { - $actions['edit'] = '' . __( 'Edit' ) . ''; - $actions['inline hide-if-no-js'] = '' . __( 'Quick Edit' ) . ''; - } - if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) { - if ( 'trash' == $post->post_status ) - $actions['untrash'] = "ID ) ), 'untrash-' . $post->post_type . '_' . $post->ID ) . "'>" . __( 'Restore' ) . ""; - elseif ( EMPTY_TRASH_DAYS ) - $actions['trash'] = "" . __( 'Trash' ) . ""; - if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS ) - $actions['delete'] = "" . __( 'Delete Permanently' ) . ""; - } - if ( in_array( $post->post_status, array( 'pending', 'draft' ) ) ) { - if ( current_user_can( $post_type_object->cap->edit_post, $post->ID ) ) - $actions['view'] = '' . __( 'Preview' ) . ''; - } elseif ( 'trash' != $post->post_status ) { - $actions['view'] = '' . __( 'View' ) . ''; - } - $actions = apply_filters( 'post_row_actions', $actions, $post ); - $action_count = count( $actions ); - $i = 0; - echo '
'; - foreach ( $actions as $action => $link ) { - ++$i; - ( $i == $action_count ) ? $sep = '' : $sep = ' | '; - echo "$link$sep"; - } - echo '
'; - - get_inline_data( $post ); - ?> - - >post_type}&category_name={$c->slug}'> " . esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'category', 'display' ) ) . ''; - echo join( ', ', $out ); + foreach ( $categories as $c ) { + $out[] = sprintf( '%s', + add_query_arg( array( 'post_type' => $post->post_type, 'category_name' => $c->slug ), 'edit.php' ), + esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'category', 'display' ) ) + ); + } + echo join( ', ', $out ); } else { _e( 'Uncategorized' ); } @@ -676,8 +536,12 @@ class WP_Posts_Table extends WP_List_Table { $tags = get_the_tags( $post->ID ); if ( !empty( $tags ) ) { $out = array(); - foreach ( $tags as $c ) - $out[] = " " . esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'post_tag', 'display' ) ) . ''; + foreach ( $tags as $c ) { + $out[] = sprintf( '%s', + add_query_arg( array( 'post_type' => $post->post_type, 'tag' => $c->slug ), 'edit.php' ), + esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'tag', 'display' ) ) + ); + } echo join( ', ', $out ); } else { _e( 'No Tags' ); @@ -690,6 +554,7 @@ class WP_Posts_Table extends WP_List_Table { ?> >
comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0; $pending_phrase = sprintf( __( '%s pending' ), number_format( $pending_comments ) ); if ( $pending_comments ) echo ''; @@ -710,25 +575,12 @@ class WP_Posts_Table extends WP_List_Table { case 'author': ?> - > - - - - cap->edit_post, $post->ID ) ) { echo "" . __( 'Edit' ) . ""; } ?> - - cap->delete_post, $post->ID ) ) { echo "ID ) . "' class='delete'>" . __( 'Delete' ) . ""; } ?> + >%s', + add_query_arg( array( 'post_type' => $post->post_type, 'author' => get_the_author_meta( 'ID' ) ), 'edit.php' ), + get_the_author() + ); + ?>