Post List Table: Ensure that edit.php with no query string produces the proper markup and links in the date column header.

Add 2 methods to `WP_List_Table`, `->get_orderby()` and `->get_order()`. Override the methods in `WP_Posts_List_Table`.

`WP_Posts_List_Table` calls `wp_edit_posts_query()` in `->prepare_items()` which is a wrapper for `wp()`. As such, we can obtain `orderby` and `order` via `get_query_var()`, instead of the URL.

Fixes #25493.


Built from https://develop.svn.wordpress.org/trunk@34728


git-svn-id: http://core.svn.wordpress.org/trunk@34692 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-10-01 02:10:25 +00:00
parent ec9ec3138e
commit 594a208753
4 changed files with 70 additions and 14 deletions

View File

@ -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;

View File

@ -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'] );

View File

@ -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 );

View File

@ -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.