X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/9e77185fafaf4e60e2b73821e0e4b9b1a11fb85f..53f4633144ed68c8b8fb5861f992b5489894a940:/wp-admin/includes/class-wp-posts-list-table.php?ds=inline diff --git a/wp-admin/includes/class-wp-posts-list-table.php b/wp-admin/includes/class-wp-posts-list-table.php index 5914aea9..04639347 100644 --- a/wp-admin/includes/class-wp-posts-list-table.php +++ b/wp-admin/includes/class-wp-posts-list-table.php @@ -45,6 +45,17 @@ class WP_Posts_List_Table extends WP_List_Table { */ private $sticky_posts_count = 0; + private $is_trash; + + /** + * Current level for output. + * + * @since 4.3.0 + * @access protected + * @var int + */ + protected $current_level = 0; + /** * Constructor. * @@ -53,6 +64,9 @@ class WP_Posts_List_Table extends WP_List_Table { * * @see WP_List_Table::__construct() for more information on default arguments. * + * @global object $post_type_object + * @global wpdb $wpdb + * * @param array $args An associative array of arguments. */ public function __construct( $args = array() ) { @@ -84,16 +98,38 @@ class WP_Posts_List_Table extends WP_List_Table { } } + /** + * Sets whether the table layout should be hierarchical or not. + * + * @since 4.2.0 + * + * @param bool $display Whether the table layout should be hierarchical. + */ + public function set_hierarchical_display( $display ) { + $this->hierarchical_display = $display; + } + + /** + * + * @return bool + */ public function ajax_user_can() { return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts ); } + /** + * + * @global array $avail_post_stati + * @global WP_Query $wp_query + * @global int $per_page + * @global string $mode + */ public function prepare_items() { global $avail_post_stati, $wp_query, $per_page, $mode; $avail_post_stati = wp_edit_posts_query(); - $this->hierarchical_display = ( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' == $wp_query->query['orderby'] ); + $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' == $wp_query->query['orderby'] ); $total_items = $this->hierarchical_display ? $wp_query->post_count : $wp_query->found_posts; @@ -124,10 +160,17 @@ class WP_Posts_List_Table extends WP_List_Table { ) ); } + /** + * + * @return bool + */ public function has_items() { return have_posts(); } + /** + * @access public + */ public function no_items() { if ( isset( $_REQUEST['post_status'] ) && 'trash' == $_REQUEST['post_status'] ) echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash; @@ -135,6 +178,27 @@ class WP_Posts_List_Table extends WP_List_Table { echo get_post_type_object( $this->screen->post_type )->labels->not_found; } + /** + * Determine if the current view is the "All" view. + * + * @since 4.2.0 + * + * @return bool Whether the current view is the "All" view. + */ + protected function is_base_request() { + if ( empty( $_GET ) ) { + return true; + } elseif ( 1 === count( $_GET ) && ! empty( $_GET['post_type'] ) ) { + return $this->screen->post_type === $_GET['post_type']; + } + } + + /** + * + * @global array $locked_post_status This seems to be deprecated. + * @global array $avail_post_stati + * @return array + */ protected function get_views() { global $locked_post_status, $avail_post_stati; @@ -155,6 +219,7 @@ class WP_Posts_List_Table extends WP_List_Table { $class = ' class="current"'; $status_links['mine'] = "" . sprintf( _nx( 'Mine (%s)', 'Mine (%s)', $this->user_posts_count, 'posts' ), number_format_i18n( $this->user_posts_count ) ) . ''; $allposts = '&all_posts=1'; + $class = ''; } $total_posts = array_sum( (array) $num_posts ); @@ -163,8 +228,21 @@ class WP_Posts_List_Table extends WP_List_Table { foreach ( get_post_stati( array('show_in_admin_all_list' => false) ) as $state ) $total_posts -= $num_posts->$state; - $class = empty( $class ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : ''; - $status_links['all'] = "" . sprintf( _nx( 'All (%s)', 'All (%s)', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . ''; + if ( empty( $class ) && ( ( $this->is_base_request() && ! $this->user_posts_count ) || isset( $_REQUEST['all_posts'] ) ) ) { + $class = ' class="current"'; + } + + $all_inner_html = sprintf( + _nx( + 'All (%s)', + 'All (%s)', + $total_posts, + 'posts' + ), + number_format_i18n( $total_posts ) + ); + + $status_links['all'] = "" . $all_inner_html . ''; foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) { $class = ''; @@ -196,22 +274,35 @@ class WP_Posts_List_Table extends WP_List_Table { return $status_links; } + /** + * + * @return array + */ protected function get_bulk_actions() { $actions = array(); + $post_type_obj = get_post_type_object( $this->screen->post_type ); - if ( $this->is_trash ) + if ( $this->is_trash ) { $actions['untrash'] = __( 'Restore' ); - else + } else { $actions['edit'] = __( 'Edit' ); + } - if ( $this->is_trash || !EMPTY_TRASH_DAYS ) - $actions['delete'] = __( 'Delete Permanently' ); - else - $actions['trash'] = __( 'Move to Trash' ); + if ( current_user_can( $post_type_obj->cap->delete_posts ) ) { + if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) { + $actions['delete'] = __( 'Delete Permanently' ); + } else { + $actions['trash'] = __( 'Move to Trash' ); + } + } return $actions; } + /** + * @global int $cat + * @param string $which + */ protected function extra_tablenav( $which ) { global $cat; ?> @@ -223,13 +314,15 @@ class WP_Posts_List_Table extends WP_List_Table { if ( is_object_in_taxonomy( $this->screen->post_type, 'category' ) ) { $dropdown_options = array( - 'show_option_all' => __( 'View all categories' ), + 'show_option_all' => __( 'All categories' ), 'hide_empty' => 0, 'hierarchical' => 1, 'show_count' => 0, 'orderby' => 'name', 'selected' => $cat ); + + echo ''; wp_dropdown_categories( $dropdown_options ); } @@ -254,6 +347,10 @@ class WP_Posts_List_Table extends WP_List_Table { view_switcher( $mode ); } + /** + * + * @return array + */ protected function get_table_classes() { - return array( 'widefat', 'fixed', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' ); + return array( 'widefat', 'fixed', 'striped', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' ); } + /** + * + * @return array + */ public function get_columns() { $post_type = $this->screen->post_type; @@ -294,7 +403,7 @@ class WP_Posts_List_Table extends WP_List_Table { /** * Filter the taxonomy columns in the Posts list table. * - * The dynamic portion of the hook name, $post_type, refers to the post + * The dynamic portion of the hook name, `$post_type`, refers to the post * type slug. * * @since 3.5.0 @@ -318,7 +427,7 @@ class WP_Posts_List_Table extends WP_List_Table { $post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all'; if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) ) - $posts_columns['comments'] = ''; + $posts_columns['comments'] = '' . __( 'Comments' ) . ''; $posts_columns['date'] = __( 'Date' ); @@ -348,17 +457,19 @@ class WP_Posts_List_Table extends WP_List_Table { /** * Filter the columns displayed in the Posts list table for a specific post type. * - * The dynamic portion of the hook name, $post_type, refers to the post type slug. + * The dynamic portion of the hook name, `$post_type`, refers to the post type slug. * * @since 3.0.0 * * @param array $post_columns An array of column names. */ - $posts_columns = apply_filters( "manage_{$post_type}_posts_columns", $posts_columns ); - - return $posts_columns; + return apply_filters( "manage_{$post_type}_posts_columns", $posts_columns ); } + /** + * + * @return array + */ protected function get_sortable_columns() { return array( 'title' => 'title', @@ -368,6 +479,12 @@ class WP_Posts_List_Table extends WP_List_Table { ); } + /** + * @global WP_Query $wp_query + * @global int $per_page + * @param array $posts + * @param int $level + */ public function display_rows( $posts = array(), $level = 0 ) { global $wp_query, $per_page; @@ -383,6 +500,11 @@ class WP_Posts_List_Table extends WP_List_Table { } } + /** + * @global string $mode + * @param array $posts + * @param int $level + */ private function _display_rows( $posts, $level = 0 ) { global $mode; @@ -398,6 +520,13 @@ class WP_Posts_List_Table extends WP_List_Table { $this->single_row( $post, $level ); } + /** + * @global wpdb $wpdb + * @global WP_Post $post + * @param array $pages + * @param int $pagenum + * @param int $per_page + */ private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) { global $wpdb; @@ -407,7 +536,7 @@ class WP_Posts_List_Table extends WP_List_Table { $pages = get_pages( array( 'sort_column' => 'menu_order' ) ); if ( ! $pages ) - return false; + return; } /* @@ -443,20 +572,20 @@ class WP_Posts_List_Table extends WP_List_Table { $count = 0; $start = ( $pagenum - 1 ) * $per_page; $end = $start + $per_page; + $to_display = array(); foreach ( $pages as $page ) { if ( $count >= $end ) break; if ( $count >= $start ) { - echo "\t"; - $this->single_row( $page, $level ); + $to_display[$page->ID] = $level; } $count++; if ( isset( $children_pages ) ) - $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page ); + $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display ); } // If it is the last pagenum and there are orphaned pages, display them with paging as well. @@ -467,14 +596,25 @@ class WP_Posts_List_Table extends WP_List_Table { break; if ( $count >= $start ) { - echo "\t"; - $this->single_row( $op, 0 ); + $to_display[$op->ID] = 0; } $count++; } } } + + $ids = array_keys( $to_display ); + _prime_post_caches( $ids ); + + if ( ! isset( $GLOBALS['post'] ) ) { + $GLOBALS['post'] = reset( $ids ); + } + + foreach ( $to_display as $page_id => $level ) { + echo "\t"; + $this->single_row( $page_id, $level ); + } } /** @@ -482,6 +622,7 @@ class WP_Posts_List_Table extends WP_List_Table { * together with paging support * * @since 3.1.0 (Standalone function exists since 2.6.0) + * @since 4.2.0 Added the `$to_display` parameter. * * @param array $children_pages * @param int $count @@ -489,9 +630,9 @@ class WP_Posts_List_Table extends WP_List_Table { * @param int $level * @param int $pagenum * @param int $per_page + * @param array $to_display List of pages to be displayed. Passed by reference. */ - private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page ) { - + private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) { if ( ! isset( $children_pages[$parent] ) ) return; @@ -499,7 +640,6 @@ class WP_Posts_List_Table extends WP_List_Table { $end = $start + $per_page; foreach ( $children_pages[$parent] as $page ) { - if ( $count >= $end ) break; @@ -508,7 +648,13 @@ class WP_Posts_List_Table extends WP_List_Table { $my_parents = array(); $my_parent = $page->post_parent; while ( $my_parent ) { - $my_parent = get_post( $my_parent ); + // Get the ID from the list or the attribute if my_parent is an object + $parent_id = $my_parent; + if ( is_object( $my_parent ) ) { + $parent_id = $my_parent->ID; + } + + $my_parent = get_post( $parent_id ); $my_parents[] = $my_parent; if ( !$my_parent->post_parent ) break; @@ -516,383 +662,469 @@ class WP_Posts_List_Table extends WP_List_Table { } $num_parents = count( $my_parents ); while ( $my_parent = array_pop( $my_parents ) ) { - echo "\t"; - $this->single_row( $my_parent, $level - $num_parents ); + $to_display[$my_parent->ID] = $level - $num_parents; $num_parents--; } } if ( $count >= $start ) { - echo "\t"; - $this->single_row( $page, $level ); + $to_display[$page->ID] = $level; } $count++; - $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page ); + $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display ); } unset( $children_pages[$parent] ); //required in order to keep track of orphans } - public function single_row( $post, $level = 0 ) { + /** + * Handles the checkbox column output. + * + * @since 4.3.0 + * @access public + * + * @param WP_Post $post The current WP_Post object. + */ + public function column_cb( $post ) { + if ( current_user_can( 'edit_post', $post->ID ) ): ?> + + +
+ '; + echo $this->column_title( $post ); + echo $this->handle_row_actions( $post, 'title', $primary ); + echo ''; + } + + /** + * Handles the title column output. + * + * @since 4.3.0 + * @access public + * + * @global string $mode + * + * @param WP_Post $post The current WP_Post object. + */ + public function column_title( $post ) { global $mode; - static $alternate; - $global_post = get_post(); - $GLOBALS['post'] = $post; - setup_postdata( $post ); + if ( $this->hierarchical_display ) { + if ( 0 === $this->current_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_post( $find_main_page ); - $edit_link = get_edit_post_link( $post->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 ); + if ( is_null( $parent ) ) { + break; + } - $alternate = 'alternate' == $alternate ? '' : 'alternate'; - $classes = $alternate . ' iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' ); + $this->current_level++; + $find_main_page = (int) $parent->post_parent; - $lock_holder = wp_check_post_lock( $post->ID ); - if ( $lock_holder ) { - $classes .= ' wp-locked'; - $lock_holder = get_userdata( $lock_holder ); + if ( ! isset( $parent_name ) ) { + /** This filter is documented in wp-includes/post-template.php */ + $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID ); + } + } + } } - if ( $post->post_parent ) { - $count = count( get_post_ancestors( $post->ID ) ); - $classes .= ' level-'. $count; - } else { - $classes .= ' level-0'; + $pad = str_repeat( '— ', $this->current_level ); + echo ""; + + $format = get_post_format( $post->ID ); + if ( $format ) { + $label = get_post_format_string( $format ); + + echo '' . $label . ": "; } - ?> -