Introduce WP_List_Table::get_items_per_page(). See #14579

git-svn-id: http://svn.automattic.com/wordpress/trunk@15569 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
scribu 2010-09-05 15:15:46 +00:00
parent babd60d5d5
commit c02669236e
2 changed files with 27 additions and 40 deletions

View File

@ -64,11 +64,7 @@ class WP_Posts_Table extends WP_List_Table {
$total_items = $this->hierarchical_display ? $wp_query->post_count : $wp_query->found_posts;
$edit_per_page = 'edit_' . $post_type . '_per_page';
$per_page = (int) get_user_option( $edit_per_page );
if ( empty( $per_page ) || $per_page < 1 )
$per_page = 20;
$per_page = apply_filters( $edit_per_page, $per_page );
$per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
$per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
if ( $this->hierarchical_display )
@ -1367,18 +1363,13 @@ class WP_Terms_Table extends WP_List_Table {
function prepare_items() {
global $taxonomy;
$tags_per_page = (int) get_user_option( 'edit_' . $taxonomy . '_per_page' );
if ( empty( $tags_per_page ) || $tags_per_page < 1 )
$tags_per_page = 20;
$tags_per_page = $this->get_items_per_page( 'edit_' . $taxonomy . '_per_page' );
if ( 'post_tag' == $taxonomy ) {
$tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
$tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter
} elseif ( 'category' == $taxonomy ) {
$tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter
} else {
$tags_per_page = apply_filters( 'edit_' . $taxonomy . '_per_page', $tags_per_page );
}
$search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : '';
@ -1707,10 +1698,7 @@ class WP_Users_Table extends WP_List_Table {
$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
$users_per_page = (int) get_user_option( 'users_per_page' );
if ( empty( $users_per_page ) || $users_per_page < 1 )
$users_per_page = 20;
$users_per_page = apply_filters( 'users_per_page', $users_per_page );
$users_per_page = $this->get_items_per_page( 'users_per_page' );
$paged = $this->get_pagenum();
@ -1961,13 +1949,7 @@ class WP_Comments_Table extends WP_List_Table {
$search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : '';
if ( isset( $_POST['per_page'] ) )
$comments_per_page = $_POST['per_page'];
else
$comments_per_page = (int) get_user_option( 'edit_comments_per_page' );
if ( empty( $comments_per_page ) || $comments_per_page < 1 )
$comments_per_page = 20;
$comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' );
$comments_per_page = apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
if ( isset( $_POST['number'] ) )
@ -2552,14 +2534,10 @@ class WP_Sites_Table extends WP_List_Table {
$mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode'];
$per_page = $this->get_items_per_page( 'ms_sites_per_page' );
$pagenum = $this->get_pagenum();
$per_page = (int) get_user_option( 'ms_sites_per_page' );
if ( empty( $per_page ) || $per_page < 1 )
$per_page = 20;
$per_page = apply_filters( 'ms_sites_per_page', $per_page );
$s = isset( $_REQUEST['s'] ) ? stripslashes( trim( $_REQUEST[ 's' ] ) ) : '';
$like_s = esc_sql( like_escape( $s ) );
@ -2849,14 +2827,10 @@ class WP_MS_Users_Table extends WP_List_Table {
$mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode'];
$per_page = $this->get_items_per_page( 'ms_users_per_page' );
$pagenum = $this->get_pagenum();
$per_page = (int) get_user_option( 'ms_users_per_page' );
if ( empty( $per_page ) || $per_page < 1 )
$per_page = 20;
$per_page = apply_filters( 'ms_users_per_page', $per_page );
$s = isset( $_REQUEST['s'] ) ? stripslashes( trim( $_REQUEST[ 's' ] ) ) : '';
$like_s = esc_sql( like_escape( $s ) );
@ -3208,10 +3182,7 @@ class WP_Plugins_Table extends WP_List_Table {
uasort( $this->items, '_order_plugins_callback' );
}
$plugins_per_page = (int) get_user_option( 'plugins_per_page' );
if ( empty( $plugins_per_page ) || $plugins_per_page < 1 )
$plugins_per_page = 999;
$plugins_per_page = apply_filters( 'plugins_per_page', $plugins_per_page );
$plugins_per_page = $this->get_items_per_page( 'plugins_per_page', 999 );
$start = ( $page - 1 ) * $plugins_per_page;

View File

@ -325,6 +325,22 @@ class WP_List_Table {
return max( 1, $pagenum );
}
/**
* Get number of items to display on a single page
*
* @since 3.1.0
* @access protected
*
* @return int
*/
function get_items_per_page( $option, $default = 20 ) {
$per_page = (int) get_user_option( $option );
if ( empty( $per_page ) || $per_page < 1 )
$per_page = $default;
return (int) apply_filters( $option, $per_page );
}
/**
* Display the pagination.
*