Make WordPress Core

Ticket #8466: 8466.diff

File 8466.diff, 3.9 KB (added by nacin, 14 years ago)
  • wp-admin/includes/default-list-tables.php

     
    2424         * Holds the number of pending comments for each post
    2525         *
    2626         * @since 3.1.0
    27          * @var bool
     27         * @var int
    2828         * @access protected
    2929         */
    3030        var $comment_pending_count;
     
    3333         * Holds the number of posts for this user
    3434         *
    3535         * @since 3.1.0
    36          * @var bool
     36         * @var int
    3737         * @access private
    3838         */
    3939        var $user_posts_count;
    4040
     41        /**
     42         * Holds the number of posts which are sticky.
     43         *
     44         * @since 3.1.0
     45         * @var int
     46         * @access private
     47         */
     48        var $sticky_posts_count;
     49
    4150        function WP_Posts_Table() {
    4251                global $post_type_object, $post_type, $current_screen, $wpdb;
    4352
     
    5867                                AND post_author = %d
    5968                        ", $post_type, get_current_user_id() ) );
    6069
    61                         if ( $this->user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) )
     70                        if ( $this->user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) )
    6271                                $_GET['author'] = get_current_user_id();
    6372                }
    6473
     74                $this->sticky_posts_count = $post_type == 'post' ? count( (array) get_option( 'sticky_posts' ) ) : 0;
     75
    6576                parent::WP_List_Table( array(
    6677                        'screen' => $current_screen,
    6778                        'plural' => 'posts',
     
    142153                foreach ( get_post_stati( array('show_in_admin_all_list' => false) ) as $state )
    143154                        $total_posts -= $num_posts->$state;
    144155
    145                 $class = empty($class) && empty($_REQUEST['post_status']) ? ' class="current"' : '';
     156                $class = empty( $class ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : '';
    146157                $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>';
    147158
    148159                foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
     
    161172
    162173                        $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>';
    163174                }
    164                
     175
     176                if ( ! empty( $this->sticky_posts_count ) ) {
     177                        $class = ! empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : '';
     178                       
     179                        $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>' );
     180
     181                        // Sticky comes after Publish, or if not listed, after All.
     182                        $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) );
     183                        $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
     184                }
     185
    165186                return $status_links;
    166187        }
    167188
  • wp-admin/includes/post.php

     
    853853                $query['posts_per_archive_page'] = -1;
    854854        }
    855855
    856         wp( $query );
     856        if ( ! empty( $q['show_sticky'] ) )
     857                $query['post__in'] = (array) get_option( 'sticky_posts' );
    857858
     859        query_posts( $query );
     860
    858861        return $avail_post_stati;
    859862}
    860863
     
    920923        if ( isset($q['detached']) )
    921924                add_filter('posts_where', '_edit_attachments_query_helper');
    922925
    923         wp($q);
     926        query_posts( $q );
    924927
    925928        if ( isset($q['detached']) )
    926929                remove_filter('posts_where', '_edit_attachments_query_helper');