<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[16003] trunk: Add a 'Sticky' filter on the edit posts page.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/16003">16003</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2010-10-27 08:27:45 +0000 (Wed, 27 Oct 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add a 'Sticky' filter on the edit posts page. Add post_in and post_not_in as private query vars in the WP class to support this. fixes <a href="http://trac.wordpress.org/ticket/8466">#8466</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludeslisttablepostsphp">trunk/wp-admin/includes/list-table-posts.php</a></li>
<li><a href="#trunkwpadminincludespostphp">trunk/wp-admin/includes/post.php</a></li>
<li><a href="#trunkwpincludesclassesphp">trunk/wp-includes/classes.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludeslisttablepostsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/list-table-posts.php (16002 => 16003)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/list-table-posts.php        2010-10-27 08:19:28 UTC (rev 16002)
+++ trunk/wp-admin/includes/list-table-posts.php        2010-10-27 08:27:45 UTC (rev 16003)
</span><span class="lines">@@ -21,7 +21,7 @@
</span><span class="cx">          * Holds the number of pending comments for each post
</span><span class="cx">          *
</span><span class="cx">          * @since 3.1.0
</span><del>-         * @var bool
</del><ins>+         * @var int
</ins><span class="cx">          * @access protected
</span><span class="cx">          */
</span><span class="cx">         var $comment_pending_count;
</span><span class="lines">@@ -30,11 +30,20 @@
</span><span class="cx">          * Holds the number of posts for this user
</span><span class="cx">          *
</span><span class="cx">          * @since 3.1.0
</span><del>-         * @var bool
</del><ins>+         * @var int
</ins><span class="cx">          * @access private
</span><span class="cx">          */
</span><span class="cx">         var $user_posts_count;
</span><span class="cx"> 
</span><ins>+        /**
+         * Holds the number of posts which are sticky.
+         *
+         * @since 3.1.0
+         * @var int
+         * @access private
+         */
+        var $sticky_posts_count = 0;
+
</ins><span class="cx">         function WP_Posts_Table() {
</span><span class="cx">                 global $post_type_object, $post_type, $current_screen, $wpdb;
</span><span class="cx"> 
</span><span class="lines">@@ -51,14 +60,19 @@
</span><span class="cx">                 if ( !current_user_can( $post_type_object-&gt;cap-&gt;edit_others_posts ) ) {
</span><span class="cx">                         $this-&gt;user_posts_count = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;
</span><span class="cx">                                 SELECT COUNT( 1 ) FROM $wpdb-&gt;posts
</span><del>-                                WHERE post_type = '%s' AND post_status NOT IN ( 'trash', 'auto-draft' )
</del><ins>+                                WHERE post_type = %s AND post_status NOT IN ( 'trash', 'auto-draft' )
</ins><span class="cx">                                 AND post_author = %d
</span><span class="cx">                         &quot;, $post_type, get_current_user_id() ) );
</span><span class="cx"> 
</span><del>-                        if ( $this-&gt;user_posts_count &amp;&amp; empty( $_REQUEST['post_status'] ) &amp;&amp; empty( $_REQUEST['all_posts'] ) &amp;&amp; empty( $_REQUEST['author'] ) )
</del><ins>+                        if ( $this-&gt;user_posts_count &amp;&amp; empty( $_REQUEST['post_status'] ) &amp;&amp; empty( $_REQUEST['all_posts'] ) &amp;&amp; empty( $_REQUEST['author'] ) &amp;&amp; empty( $_REQUEST['show_sticky'] ) )
</ins><span class="cx">                                 $_GET['author'] = get_current_user_id();
</span><span class="cx">                 }
</span><span class="cx"> 
</span><ins>+                if ( $sticky_posts = get_option( 'sticky_posts' ) ) {
+                        $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
+                        $this-&gt;sticky_posts_count = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT COUNT( 1 ) FROM $wpdb-&gt;posts WHERE post_type = %s AND ID IN ($sticky_posts)&quot;, $post_type ) );
+                }
+
</ins><span class="cx">                 parent::WP_List_Table( array(
</span><span class="cx">                         'screen' =&gt; $current_screen,
</span><span class="cx">                         'plural' =&gt; 'posts',
</span><span class="lines">@@ -139,7 +153,7 @@
</span><span class="cx">                 foreach ( get_post_stati( array('show_in_admin_all_list' =&gt; false) ) as $state )
</span><span class="cx">                         $total_posts -= $num_posts-&gt;$state;
</span><span class="cx"> 
</span><del>-                $class = empty($class) &amp;&amp; empty($_REQUEST['post_status']) ? ' class=&quot;current&quot;' : '';
</del><ins>+                $class = empty( $class ) &amp;&amp; empty( $_REQUEST['post_status'] ) &amp;&amp; empty( $_REQUEST['show_sticky'] ) ? ' class=&quot;current&quot;' : '';
</ins><span class="cx">                 $status_links['all'] = &quot;&lt;li&gt;&lt;a href='edit.php?post_type=$post_type{$allposts}'$class&gt;&quot; . sprintf( _nx( 'All &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'All &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '&lt;/a&gt;';
</span><span class="cx"> 
</span><span class="cx">                 foreach ( get_post_stati(array('show_in_admin_status_list' =&gt; true), 'objects') as $status ) {
</span><span class="lines">@@ -159,6 +173,16 @@
</span><span class="cx">                         $status_links[$status_name] = &quot;&lt;li&gt;&lt;a href='edit.php?post_status=$status_name&amp;amp;post_type=$post_type'$class&gt;&quot; . sprintf( _n( $status-&gt;label_count[0], $status-&gt;label_count[1], $num_posts-&gt;$status_name ), number_format_i18n( $num_posts-&gt;$status_name ) ) . '&lt;/a&gt;';
</span><span class="cx">                 }
</span><span class="cx"> 
</span><ins>+                if ( ! empty( $this-&gt;sticky_posts_count ) ) {
+                        $class = ! empty( $_REQUEST['show_sticky'] ) ? ' class=&quot;current&quot;' : '';
+
+                        $sticky_link = array( 'sticky' =&gt; &quot;&lt;li&gt;&lt;a href='edit.php?post_type=$post_type&amp;amp;show_sticky=1'$class&gt;&quot; . sprintf( _nx( 'Sticky &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Sticky &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', $this-&gt;sticky_posts_count, 'posts' ), number_format_i18n( $this-&gt;sticky_posts_count ) ) . '&lt;/a&gt;' );
+
+                        // 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 ) );
+                }
+
</ins><span class="cx">                 return $status_links;
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/post.php (16002 => 16003)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/post.php        2010-10-27 08:19:28 UTC (rev 16002)
+++ trunk/wp-admin/includes/post.php        2010-10-27 08:27:45 UTC (rev 16003)
</span><span class="lines">@@ -853,6 +853,9 @@
</span><span class="cx">                 $query['posts_per_archive_page'] = -1;
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        if ( ! empty( $q['show_sticky'] ) )
+                $query['post__in'] = (array) get_option( 'sticky_posts' );
+
</ins><span class="cx">         wp( $query );
</span><span class="cx"> 
</span><span class="cx">         return $avail_post_stati;
</span><span class="lines">@@ -920,7 +923,7 @@
</span><span class="cx">         if ( isset($q['detached']) )
</span><span class="cx">                 add_filter('posts_where', '_edit_attachments_query_helper');
</span><span class="cx"> 
</span><del>-        wp($q);
</del><ins>+        wp( $q );
</ins><span class="cx"> 
</span><span class="cx">         if ( isset($q['detached']) )
</span><span class="cx">                 remove_filter('posts_where', '_edit_attachments_query_helper');
</span></span></pre></div>
<a id="trunkwpincludesclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/classes.php (16002 => 16003)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/classes.php        2010-10-27 08:19:28 UTC (rev 16002)
+++ trunk/wp-includes/classes.php        2010-10-27 08:27:45 UTC (rev 16003)
</span><span class="lines">@@ -36,7 +36,7 @@
</span><span class="cx">          * @since 2.0.0
</span><span class="cx">          * @var array
</span><span class="cx">          */
</span><del>-        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');
</del><ins>+        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');
</ins><span class="cx"> 
</span><span class="cx">         /**
</span><span class="cx">          * Extra query variables set by the user.
</span></span></pre>
</div>
</div>

</body>
</html>