Add per page option to Screen Options for comments, posts, pages, and media.

git-svn-id: http://svn.automattic.com/wordpress/trunk@10847 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-03-27 22:47:47 +00:00
parent f8926b2ad9
commit 72a58f8025
7 changed files with 98 additions and 5 deletions

View File

@ -1021,6 +1021,34 @@ case 'meta-box-order':
if ( $page_columns ) if ( $page_columns )
update_usermeta($user->ID, "screen_layout_$page", $page_columns); update_usermeta($user->ID, "screen_layout_$page", $page_columns);
die('1');
break;
case 'set-screen-option':
if ( ! $user = wp_get_current_user() )
die(-1);
$option = $_POST['option'];
$value = $_POST['value'];
if ( !preg_match( '/^[a-z_-]+$/', $option ) )
die(-1);
$option = str_replace('-', '_', $option);
switch ( $option ) {
case 'edit_per_page':
case 'edit_pages_per_page':
case 'edit_comments_per_page':
case 'upload_per_page':
$value = (int) $value;
break;
default:
$value = apply_filters('set-screen-option', false, $option, $value);
if ( false === $value )
die(-1);
break;
}
update_usermeta($user->ID, $option, $value);
die('1'); die('1');
break; break;
case 'get-permalink': case 'get-permalink':

View File

@ -182,7 +182,10 @@ unset($status_links);
</p> </p>
<?php <?php
$comments_per_page = apply_filters('comments_per_page', 20, $comment_status); $comments_per_page = get_user_option('edit_comments_per_page');
if ( empty($comments_per_page) )
$comments_per_page = 20;
$comments_per_page = apply_filters('comments_per_page', $comments_per_page, $comment_status);
if ( isset( $_GET['apage'] ) ) if ( isset( $_GET['apage'] ) )
$page = abs( (int) $_GET['apage'] ); $page = abs( (int) $_GET['apage'] );

View File

@ -186,7 +186,8 @@ endif;
$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0; $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
if ( empty($pagenum) ) if ( empty($pagenum) )
$pagenum = 1; $pagenum = 1;
if( ! isset( $per_page ) || $per_page < 0 ) $per_page = get_user_option('edit_pages_per_page');
if ( empty( $per_page ) || $per_page < 0 )
$per_page = 20; $per_page = 20;
$num_pages = ceil($wp_query->post_count / $per_page); $num_pages = ceil($wp_query->post_count / $per_page);

View File

@ -815,7 +815,10 @@ function wp_edit_posts_query( $q = false ) {
$orderby = 'date'; $orderby = 'date';
} }
$posts_per_page = apply_filters('edit_posts_per_page', 15); $posts_per_page = get_user_option('edit_per_page');
if ( empty($posts_per_page) )
$posts_per_page = 15;
$posts_per_page = apply_filters('edit_posts_per_page', $posts_per_page);
wp("post_type=post&what_to_show=posts$post_status_q&posts_per_page=$posts_per_page&order=$order&orderby=$orderby"); wp("post_type=post&what_to_show=posts$post_status_q&posts_per_page=$posts_per_page&order=$order&orderby=$orderby");
@ -853,7 +856,10 @@ function wp_edit_attachments_query( $q = false ) {
$q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0; $q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
$q['post_type'] = 'attachment'; $q['post_type'] = 'attachment';
$q['post_status'] = 'any'; $q['post_status'] = 'any';
$q['posts_per_page'] = 15; $media_per_page = get_user_option('upload_per_page');
if ( empty($media_per_page) )
$media_per_page = 20;
$q['posts_per_page'] = $media_per_page;
$post_mime_types = array( // array( adj, noun ) $post_mime_types = array( // array( adj, noun )
'image' => array(__('Images'), __('Manage Images'), _n_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')), 'image' => array(__('Images'), __('Manage Images'), _n_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')),
'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')), 'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')),

View File

@ -3386,6 +3386,7 @@ function screen_meta($screen) {
<br class="clear" /> <br class="clear" />
</div> </div>
<?php echo screen_layout($screen); ?> <?php echo screen_layout($screen); ?>
<?php echo screen_options($screen); ?>
</form> </form>
</div> </div>
@ -3506,6 +3507,36 @@ function screen_layout($screen) {
return $return; return $return;
} }
function screen_options($screen) {
switch ( $screen ) {
case 'edit':
$per_page_label = __('Posts per page:');
break;
case 'edit-pages':
$per_page_label = __('Pages per page:');
break;
case 'edit-comments':
$per_page_label = __('Comments per page:');
break;
case 'upload':
$per_page_label = __('Media items per page:');
break;
default:
return '';
}
$per_page = get_user_option("${screen}_per_page");
if ( empty($per_page) )
$per_page = 20;
$return = '<h5>' . __('Options') . "</h5>\n";
$return .= "<div class='screen-options'>\n";
if ( !empty($per_page_label) )
$return .= "<label for='${screen}-per-page'>$per_page_label</label> <input type='text' class='screen-option small-text' name='${screen}_per_page' id='${screen}-per-page' value='$per_page' />\n";
$return .= "</div>\n";
return $return;
}
function screen_icon($name = '') { function screen_icon($name = '') {
global $parent_file, $hook_suffix; global $parent_file, $hook_suffix;

View File

@ -113,7 +113,31 @@ columns = {
}); });
} }
} }
$(document).ready(function(){columns.init();}); $(document).ready(function(){columns.init();});
screenOptions = {
init : function() {
$('.screen-option').change(function() {
var option = $(this).map(function() { return this.id; }).get();
var value = $(this).val();
screenOptions.save_screen_option(option, value);
});
},
save_screen_option : function (option, value) {
$.post(ajaxurl, {
action: 'set-screen-option',
option: option,
value: value,
screenoptionnonce: $('#screenoptionnonce').val(),
page: pagenow
});
}
}
$(document).ready(function(){screenOptions.init();});
})(jQuery); })(jQuery);
// stub for doing better warnings // stub for doing better warnings

File diff suppressed because one or more lines are too long