<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[15569] trunk/wp-admin/includes: Introduce WP_List_Table::
 get_items_per_page().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15569">15569</a></dd>
<dt>Author</dt> <dd>scribu</dd>
<dt>Date</dt> <dd>2010-09-05 15:15:46 +0000 (Sun, 05 Sep 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Introduce WP_List_Table::get_items_per_page(). See <a href="http://trac.wordpress.org/ticket/14579">#14579</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesdefaultlisttablesphp">trunk/wp-admin/includes/default-list-tables.php</a></li>
<li><a href="#trunkwpadminincludeslisttablephp">trunk/wp-admin/includes/list-table.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesdefaultlisttablesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/default-list-tables.php (15568 => 15569)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/default-list-tables.php        2010-09-05 14:54:55 UTC (rev 15568)
+++ trunk/wp-admin/includes/default-list-tables.php        2010-09-05 15:15:46 UTC (rev 15569)
</span><span class="lines">@@ -64,11 +64,7 @@
</span><span class="cx"> 
</span><span class="cx">                 $total_items = $this-&gt;hierarchical_display ? $wp_query-&gt;post_count : $wp_query-&gt;found_posts;
</span><span class="cx"> 
</span><del>-                $edit_per_page = 'edit_' . $post_type . '_per_page'; 
-                 $per_page = (int) get_user_option( $edit_per_page );
-                if ( empty( $per_page ) || $per_page &lt; 1 )
-                        $per_page = 20;
-                $per_page = apply_filters( $edit_per_page, $per_page ); 
</del><ins>+                $per_page = $this-&gt;get_items_per_page( 'edit_' . $post_type . '_per_page' );
</ins><span class="cx">                  $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type ); 
</span><span class="cx"> 
</span><span class="cx">                 if ( $this-&gt;hierarchical_display )
</span><span class="lines">@@ -1367,18 +1363,13 @@
</span><span class="cx">         function prepare_items() {
</span><span class="cx">                 global $taxonomy;
</span><span class="cx"> 
</span><del>-                $tags_per_page = (int) get_user_option( 'edit_' .  $taxonomy . '_per_page' );
</del><ins>+                $tags_per_page = $this-&gt;get_items_per_page( 'edit_' .  $taxonomy . '_per_page' );
</ins><span class="cx"> 
</span><del>-                if ( empty( $tags_per_page ) || $tags_per_page &lt; 1 )
-                        $tags_per_page = 20;
-
</del><span class="cx">                 if ( 'post_tag' == $taxonomy ) {
</span><span class="cx">                         $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
</span><span class="cx">                         $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter
</span><span class="cx">                 } elseif ( 'category' == $taxonomy ) {
</span><span class="cx">                         $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter
</span><del>-                } else {
-                        $tags_per_page = apply_filters( 'edit_' . $taxonomy . '_per_page', $tags_per_page );
</del><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 $search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : '';
</span><span class="lines">@@ -1707,10 +1698,7 @@
</span><span class="cx"> 
</span><span class="cx">                 $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
</span><span class="cx"> 
</span><del>-                $users_per_page = (int) get_user_option( 'users_per_page' );
-                if ( empty( $users_per_page ) || $users_per_page &lt; 1 )
-                        $users_per_page = 20;
-                $users_per_page = apply_filters( 'users_per_page', $users_per_page );
</del><ins>+                $users_per_page = $this-&gt;get_items_per_page( 'users_per_page' );
</ins><span class="cx"> 
</span><span class="cx">                 $paged = $this-&gt;get_pagenum();
</span><span class="cx"> 
</span><span class="lines">@@ -1961,13 +1949,7 @@
</span><span class="cx"> 
</span><span class="cx">                 $search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : '';
</span><span class="cx"> 
</span><del>-                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 &lt; 1 )
-                        $comments_per_page = 20;
</del><ins>+                $comments_per_page = $this-&gt;get_items_per_page( 'edit_comments_per_page' );
</ins><span class="cx">                 $comments_per_page = apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
</span><span class="cx"> 
</span><span class="cx">                 if ( isset( $_POST['number'] ) )
</span><span class="lines">@@ -2552,14 +2534,10 @@
</span><span class="cx"> 
</span><span class="cx">                 $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode'];
</span><span class="cx"> 
</span><ins>+                $per_page = $this-&gt;get_items_per_page( 'ms_sites_per_page' );
+
</ins><span class="cx">                 $pagenum = $this-&gt;get_pagenum();
</span><span class="cx"> 
</span><del>-                $per_page = (int) get_user_option( 'ms_sites_per_page' );
-                if ( empty( $per_page ) || $per_page &lt; 1 )
-                        $per_page = 20;
-
-                $per_page = apply_filters( 'ms_sites_per_page', $per_page );
-
</del><span class="cx">                 $s = isset( $_REQUEST['s'] ) ? stripslashes( trim( $_REQUEST[ 's' ] ) ) : '';
</span><span class="cx">                 $like_s = esc_sql( like_escape( $s ) );
</span><span class="cx"> 
</span><span class="lines">@@ -2836,7 +2814,7 @@
</span><span class="cx">                 ) );
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function check_permissions() {                        
</del><ins>+        function check_permissions() {
</ins><span class="cx">                 if ( !is_multisite() )
</span><span class="cx">                         wp_die( __( 'Multisite support is not enabled.' ) );
</span><span class="cx">         
</span><span class="lines">@@ -2849,14 +2827,10 @@
</span><span class="cx"> 
</span><span class="cx">                 $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode'];
</span><span class="cx"> 
</span><ins>+                $per_page = $this-&gt;get_items_per_page( 'ms_users_per_page' );
+
</ins><span class="cx">                 $pagenum = $this-&gt;get_pagenum();
</span><span class="cx"> 
</span><del>-                $per_page = (int) get_user_option( 'ms_users_per_page' );
-                if ( empty( $per_page ) || $per_page &lt; 1 )
-                        $per_page = 20;
-
-                $per_page = apply_filters( 'ms_users_per_page', $per_page );
-
</del><span class="cx">                 $s = isset( $_REQUEST['s'] ) ? stripslashes( trim( $_REQUEST[ 's' ] ) ) : '';
</span><span class="cx">                 $like_s = esc_sql( like_escape( $s ) );
</span><span class="cx"> 
</span><span class="lines">@@ -3207,12 +3181,9 @@
</span><span class="cx">                         }
</span><span class="cx">                         uasort( $this-&gt;items, '_order_plugins_callback' );
</span><span class="cx">                 }
</span><ins>+                
+                $plugins_per_page = $this-&gt;get_items_per_page( 'plugins_per_page', 999 );
</ins><span class="cx"> 
</span><del>-                $plugins_per_page = (int) get_user_option( 'plugins_per_page' );
-                if ( empty( $plugins_per_page ) || $plugins_per_page &lt; 1 )
-                        $plugins_per_page = 999;
-                $plugins_per_page = apply_filters( 'plugins_per_page', $plugins_per_page );
-
</del><span class="cx">                 $start = ( $page - 1 ) * $plugins_per_page;
</span><span class="cx"> 
</span><span class="cx">                 if ( $total_this_page &gt; $plugins_per_page )
</span></span></pre></div>
<a id="trunkwpadminincludeslisttablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/list-table.php (15568 => 15569)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/list-table.php        2010-09-05 14:54:55 UTC (rev 15568)
+++ trunk/wp-admin/includes/list-table.php        2010-09-05 15:15:46 UTC (rev 15569)
</span><span class="lines">@@ -326,6 +326,22 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><ins>+         * 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 &lt; 1 )
+                        $per_page = $default;
+
+                return (int) apply_filters( $option, $per_page );
+        }
+
+        /**
</ins><span class="cx">          * Display the pagination.
</span><span class="cx">          *
</span><span class="cx">          * @since 3.1.0
</span></span></pre>
</div>
</div>

</body>
</html>