Ticket #8466: 8466.2.diff

File 8466.2.diff, 4.4 KB (added by nacin, 3 years ago)

Patch refreshed against [15742].

Line 
1Index: wp-admin/includes/default-list-tables.php
2===================================================================
3--- wp-admin/includes/default-list-tables.php   (revision 15742)
4+++ wp-admin/includes/default-list-tables.php   (working copy)
5@@ -24,7 +24,7 @@
6         * Holds the number of pending comments for each post
7         *
8         * @since 3.1.0
9-        * @var bool
10+        * @var int
11         * @access protected
12         */
13        var $comment_pending_count;
14@@ -33,11 +33,20 @@
15         * Holds the number of posts for this user
16         *
17         * @since 3.1.0
18-        * @var bool
19+        * @var int
20         * @access private
21         */
22        var $user_posts_count;
23 
24+       /**
25+        * Holds the number of posts which are sticky.
26+        *
27+        * @since 3.1.0
28+        * @var int
29+        * @access private
30+        */
31+       var $sticky_posts_count = 0;
32+
33        function WP_Posts_Table() {
34                global $post_type_object, $post_type, $current_screen, $wpdb;
35 
36@@ -54,14 +63,19 @@
37                if ( !current_user_can( $post_type_object->cap->edit_others_posts ) ) {
38                        $this->user_posts_count = $wpdb->get_var( $wpdb->prepare( "
39                                SELECT COUNT( 1 ) FROM $wpdb->posts
40-                               WHERE post_type = '%s' AND post_status NOT IN ( 'trash', 'auto-draft' )
41+                               WHERE post_type = %s AND post_status NOT IN ( 'trash', 'auto-draft' )
42                                AND post_author = %d
43                        ", $post_type, get_current_user_id() ) );
44 
45-                       if ( $this->user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) )
46+                       if ( $this->user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) )
47                                $_GET['author'] = get_current_user_id();
48                }
49 
50+               if ( $sticky_posts = get_option( 'sticky_posts' ) ) {
51+                       $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
52+                       $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 ) );
53+               }
54+
55                parent::WP_List_Table( array(
56                        'screen' => $current_screen,
57                        'plural' => 'posts',
58@@ -142,7 +156,7 @@
59                foreach ( get_post_stati( array('show_in_admin_all_list' => false) ) as $state )
60                        $total_posts -= $num_posts->$state;
61 
62-               $class = empty($class) && empty($_REQUEST['post_status']) ? ' class="current"' : '';
63+               $class = empty( $class ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : '';
64                $status_links['all'] = "<li><a href='edit.php?post_type=$post_type{$allposts}'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>';
65 
66                foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
67@@ -161,7 +175,17 @@
68 
69                        $status_links[$status_name] = "<li><a href='edit.php?post_status=$status_name&amp;post_type=$post_type'$class>" . sprintf( _n( $status->label_count[0], $status->label_count[1], $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '</a>';
70                }
71-               
72+
73+               if ( ! empty( $this->sticky_posts_count ) ) {
74+                       $class = ! empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : '';
75+                       
76+                       $sticky_link = array( 'sticky' => "<li><a href='edit.php?post_type=$post_type&amp;show_sticky=1'$class>" . sprintf( _nx( 'Sticky <span class="count">(%s)</span>', 'Sticky <span class="count">(%s)</span>', $this->sticky_posts_count, 'posts' ), number_format_i18n( $this->sticky_posts_count ) ) . '</a>' );
77+
78+                       // Sticky comes after Publish, or if not listed, after All.
79+                       $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) );
80+                       $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
81+               }
82+
83                return $status_links;
84        }
85 
86Index: wp-admin/includes/post.php
87===================================================================
88--- wp-admin/includes/post.php  (revision 15737)
89+++ wp-admin/includes/post.php  (working copy)
90@@ -853,8 +853,11 @@
91                $query['posts_per_archive_page'] = -1;
92        }
93 
94-       wp( $query );
95+       if ( ! empty( $q['show_sticky'] ) )
96+               $query['post__in'] = (array) get_option( 'sticky_posts' );
97 
98+       query_posts( $query );
99+
100        return $avail_post_stati;
101 }
102 
103@@ -920,7 +923,7 @@
104        if ( isset($q['detached']) )
105                add_filter('posts_where', '_edit_attachments_query_helper');
106 
107-       wp($q);
108+       query_posts( $q );
109 
110        if ( isset($q['detached']) )
111                remove_filter('posts_where', '_edit_attachments_query_helper');