WordPress.org

Make WordPress Core

Changeset 16003


Ignore:
Timestamp:
10/27/10 08:27:45 (3 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.

Location:
trunk
Files:
3 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 
  • trunk/wp-admin/includes/post.php

    r15940 r16003  
    854854    } 
    855855 
     856    if ( ! empty( $q['show_sticky'] ) ) 
     857        $query['post__in'] = (array) get_option( 'sticky_posts' ); 
     858 
    856859    wp( $query ); 
    857860 
     
    921924        add_filter('posts_where', '_edit_attachments_query_helper'); 
    922925 
    923     wp($q); 
     926    wp( $q ); 
    924927 
    925928    if ( isset($q['detached']) ) 
  • trunk/wp-includes/classes.php

    r15960 r16003  
    3737     * @var array 
    3838     */ 
    39     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'); 
     39    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'); 
    4040 
    4141    /** 
Note: See TracChangeset for help on using the changeset viewer.