diff --git a/wp-admin/includes/class-wp-list-table.php b/wp-admin/includes/class-wp-list-table.php index a633752c8c..d8b4f19416 100644 --- a/wp-admin/includes/class-wp-list-table.php +++ b/wp-admin/includes/class-wp-list-table.php @@ -1006,6 +1006,38 @@ class WP_List_Table { return count( $columns ) - count( $hidden ); } + /** + * If 'orderby' is set, return it. + * + * @access protected + * @since 4.4.0 + * + * @return string The value of 'orderby' or empty string. + */ + protected function get_orderby() { + if ( isset( $_GET['orderby'] ) ) { + return $_GET['orderby']; + } + + return ''; + } + + /** + * If 'order' is 'desc', return it. Else return 'asc'. + * + * @access protected + * @since 4.4.0 + * + * @return string 'desc' or 'asc'. + */ + protected function get_order() { + if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) { + return 'desc'; + } + + return 'asc'; + } + /** * Print column headers, accounting for hidden and sortable columns. * @@ -1022,15 +1054,8 @@ class WP_List_Table { $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); $current_url = remove_query_arg( 'paged', $current_url ); - if ( isset( $_GET['orderby'] ) ) - $current_orderby = $_GET['orderby']; - else - $current_orderby = ''; - - if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) - $current_order = 'desc'; - else - $current_order = 'asc'; + $current_orderby = $this->get_orderby(); + $current_order = $this->get_order(); if ( ! empty( $columns['cb'] ) ) { static $cb_counter = 1; diff --git a/wp-admin/includes/class-wp-posts-list-table.php b/wp-admin/includes/class-wp-posts-list-table.php index 2b4938f38e..a63668b586 100644 --- a/wp-admin/includes/class-wp-posts-list-table.php +++ b/wp-admin/includes/class-wp-posts-list-table.php @@ -120,6 +120,30 @@ class WP_Posts_List_Table extends WP_List_Table { return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts ); } + /** + * Get the value of the 'orderby' query var. + * + * @access protected + * @since 4.4.0 + * + * @return string The value of 'orderby'. + */ + protected function get_orderby() { + return strtolower( get_query_var( 'orderby' ) ); + } + + /** + * Get the value of the 'order' query var. + * + * @access protected + * @since 4.4.0 + * + * @return string The value of 'order'. + */ + protected function get_order() { + return strtolower( get_query_var( 'order' ) ); + } + /** * * @global array $avail_post_stati @@ -130,6 +154,7 @@ class WP_Posts_List_Table extends WP_List_Table { public function prepare_items() { global $avail_post_stati, $wp_query, $per_page, $mode; + // is going to call wp() $avail_post_stati = wp_edit_posts_query(); $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' === $wp_query->query['orderby'] ); diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 7ed2a66112..bf49ed4fc8 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -1004,15 +1004,21 @@ function wp_edit_posts_query( $q = false ) { $perm = 'readable'; } - if ( isset($q['orderby']) ) + if ( isset( $q['orderby'] ) ) { $orderby = $q['orderby']; - elseif ( isset($q['post_status']) && in_array($q['post_status'], array('pending', 'draft')) ) + } elseif ( isset( $q['post_status'] ) && in_array( $q['post_status'], array( 'pending', 'draft' ) ) ) { $orderby = 'modified'; + } else { + $orderby = 'date'; + } - if ( isset($q['order']) ) + if ( isset( $q['order'] ) ) { $order = $q['order']; - elseif ( isset($q['post_status']) && 'pending' == $q['post_status'] ) + } elseif ( isset( $q['post_status'] ) && 'pending' == $q['post_status'] ) { $order = 'ASC'; + } else { + $order = 'desc'; + } $per_page = "edit_{$post_type}_per_page"; $posts_per_page = (int) get_user_option( $per_page ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 3748d0d626..4bff212b71 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-34727'; +$wp_version = '4.4-alpha-34728'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.