Making WordPress.org


Ignore:
Timestamp:
04/11/2016 11:33:19 AM (10 years ago)
Author:
obenland
Message:

Plugin Directory: Make sure pagination in plugin list works.

See #1570.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/list-table/class-plugin-posts.php

    r2860 r2927  
    1313         */
    1414         protected $plugin_meta;
     15
     16        /**
     17         *
     18         * @global array    $avail_post_stati
     19         * @global WP_Query $wp_query
     20         * @global int      $per_page
     21         * @global string   $mode
     22         */
     23        public function prepare_items() {
     24                global $avail_post_stati, $wp_query, $per_page, $mode;
     25
     26                $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' === $wp_query->query['orderby'] );
     27
     28                $post_type = $this->screen->post_type;
     29                $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
     30
     31                /** This filter is documented in wp-admin/includes/post.php */
     32                $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
     33
     34                if ( $this->hierarchical_display ) {
     35                        $total_items = $wp_query->post_count;
     36                } elseif ( $wp_query->found_posts || $this->get_pagenum() === 1 ) {
     37                        $total_items = $wp_query->found_posts;
     38                } else {
     39                        $post_counts = (array) wp_count_posts( $post_type, 'readable' );
     40
     41                        if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'] , $avail_post_stati ) ) {
     42                                $total_items = $post_counts[ $_REQUEST['post_status'] ];
     43                        } elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) {
     44                                $total_items = $this->sticky_posts_count;
     45                        } elseif ( isset( $_GET['author'] ) && $_GET['author'] == get_current_user_id() ) {
     46                                $total_items = $this->user_posts_count;
     47                        } else {
     48                                $total_items = array_sum( $post_counts );
     49
     50                                // Subtract post types that are not included in the admin all list.
     51                                foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
     52                                        $total_items -= $post_counts[ $state ];
     53                                }
     54                        }
     55                }
     56
     57                if ( ! empty( $_REQUEST['mode'] ) ) {
     58                        $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
     59                        set_user_setting( 'posts_list_mode', $mode );
     60                } else {
     61                        $mode = get_user_setting( 'posts_list_mode', 'list' );
     62                }
     63
     64                $this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] === 'trash';
     65
     66                $this->set_pagination_args( array(
     67                        'total_items' => $total_items,
     68                        'per_page' => $per_page
     69                ) );
     70        }
    1571
    1672        /**
Note: See TracChangeset for help on using the changeset viewer.