diff --git a/wp-admin/includes/list-table-posts.php b/wp-admin/includes/list-table-posts.php
index a1b90fffa4..1275c2af14 100644
--- a/wp-admin/includes/list-table-posts.php
+++ b/wp-admin/includes/list-table-posts.php
@@ -21,7 +21,7 @@ class WP_Posts_Table extends WP_List_Table {
* Holds the number of pending comments for each post
*
* @since 3.1.0
- * @var bool
+ * @var int
* @access protected
*/
var $comment_pending_count;
@@ -30,11 +30,20 @@ class WP_Posts_Table extends WP_List_Table {
* Holds the number of posts for this user
*
* @since 3.1.0
- * @var bool
+ * @var int
* @access private
*/
var $user_posts_count;
+ /**
+ * Holds the number of posts which are sticky.
+ *
+ * @since 3.1.0
+ * @var int
+ * @access private
+ */
+ var $sticky_posts_count = 0;
+
function WP_Posts_Table() {
global $post_type_object, $post_type, $current_screen, $wpdb;
@@ -51,14 +60,19 @@ class WP_Posts_Table extends WP_List_Table {
if ( !current_user_can( $post_type_object->cap->edit_others_posts ) ) {
$this->user_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' )
+ WHERE post_type = %s AND post_status NOT IN ( 'trash', 'auto-draft' )
AND post_author = %d
", $post_type, get_current_user_id() ) );
- if ( $this->user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) )
+ if ( $this->user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) )
$_GET['author'] = get_current_user_id();
}
+ if ( $sticky_posts = get_option( 'sticky_posts' ) ) {
+ $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
+ $this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND ID IN ($sticky_posts)", $post_type ) );
+ }
+
parent::WP_List_Table( array(
'screen' => $current_screen,
'plural' => 'posts',
@@ -139,7 +153,7 @@ class WP_Posts_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']) ? ' class="current"' : '';
+ $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 ) ) . '';
foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
@@ -159,6 +173,16 @@ class WP_Posts_Table extends WP_List_Table {
$status_links[$status_name] = "" . sprintf( _n( $status->label_count[0], $status->label_count[1], $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '';
}
+ if ( ! empty( $this->sticky_posts_count ) ) {
+ $class = ! empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : '';
+
+ $sticky_link = array( 'sticky' => "" . sprintf( _nx( 'Sticky (%s)', 'Sticky (%s)', $this->sticky_posts_count, 'posts' ), number_format_i18n( $this->sticky_posts_count ) ) . '' );
+
+ // Sticky comes after Publish, or if not listed, after All.
+ $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) );
+ $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
+ }
+
return $status_links;
}
diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php
index f6884e623e..424399d617 100644
--- a/wp-admin/includes/post.php
+++ b/wp-admin/includes/post.php
@@ -853,6 +853,9 @@ function wp_edit_posts_query( $q = false ) {
$query['posts_per_archive_page'] = -1;
}
+ if ( ! empty( $q['show_sticky'] ) )
+ $query['post__in'] = (array) get_option( 'sticky_posts' );
+
wp( $query );
return $avail_post_stati;
@@ -920,7 +923,7 @@ function wp_edit_attachments_query( $q = false ) {
if ( isset($q['detached']) )
add_filter('posts_where', '_edit_attachments_query_helper');
- wp($q);
+ wp( $q );
if ( isset($q['detached']) )
remove_filter('posts_where', '_edit_attachments_query_helper');
diff --git a/wp-includes/classes.php b/wp-includes/classes.php
index b0c4c1ac2a..2038dc7818 100644
--- a/wp-includes/classes.php
+++ b/wp-includes/classes.php
@@ -36,7 +36,7 @@ class WP {
* @since 2.0.0
* @var array
*/
- var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page');
+ var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page', 'post__in', 'post__not_in');
/**
* Extra query variables set by the user.