WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/27/2010 08:27:45 AM (9 years ago)
Author:
nacin
Message:

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 #8466.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/list-table-posts.php

    r15958 r16003  
    2222     *
    2323     * @since 3.1.0
    24      * @var bool
     24     * @var int
    2525     * @access protected
    2626     */
     
    3131     *
    3232     * @since 3.1.0
    33      * @var bool
     33     * @var int
    3434     * @access private
    3535     */
    3636    var $user_posts_count;
     37
     38    /**
     39     * Holds the number of posts which are sticky.
     40     *
     41     * @since 3.1.0
     42     * @var int
     43     * @access private
     44     */
     45    var $sticky_posts_count = 0;
    3746
    3847    function WP_Posts_Table() {
     
    5261            $this->user_posts_count = $wpdb->get_var( $wpdb->prepare( "
    5362                SELECT COUNT( 1 ) FROM $wpdb->posts
    54                 WHERE post_type = '%s' AND post_status NOT IN ( 'trash', 'auto-draft' )
     63                WHERE post_type = %s AND post_status NOT IN ( 'trash', 'auto-draft' )
    5564                AND post_author = %d
    5665            ", $post_type, get_current_user_id() ) );
    5766
    58             if ( $this->user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) )
     67            if ( $this->user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) )
    5968                $_GET['author'] = get_current_user_id();
     69        }
     70
     71        if ( $sticky_posts = get_option( 'sticky_posts' ) ) {
     72            $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
     73            $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 ) );
    6074        }
    6175
     
    140154            $total_posts -= $num_posts->$state;
    141155
    142         $class = empty($class) && empty($_REQUEST['post_status']) ? ' class="current"' : '';
     156        $class = empty( $class ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : '';
    143157        $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>';
    144158
     
    158172
    159173            $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>';
     174        }
     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 ) );
    160184        }
    161185
Note: See TracChangeset for help on using the changeset viewer.