Submit the form when setting items per page option so it's visible straight away

git-svn-id: http://svn.automattic.com/wordpress/trunk@10987 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-04-17 12:46:53 +00:00
parent f14080686d
commit 3650836f09
6 changed files with 51 additions and 33 deletions

View File

@ -41,6 +41,8 @@ nocache_headers();
update_category_cache();
save_screen_options();
$posts_per_page = get_option('posts_per_page');
$what_to_show = get_option('what_to_show');
$date_format = get_option('date_format');

View File

@ -318,4 +318,46 @@ jQuery('#template').submit(function(){
<?php
}
?>
/**
* Saves option for number of rows when listing posts, pages, comments, etc.
*
* @since 2.8
**/
function save_screen_options() {
if ( isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options']) ) {
check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' );
if ( !$user = wp_get_current_user() )
return;
$option = $_POST['wp_screen_options']['option'];
$value = $_POST['wp_screen_options']['value'];
if ( !preg_match( '/^[a-z_-]+$/', $option ) )
return;
$option = str_replace('-', '_', $option);
switch ( $option ) {
case 'edit_per_page':
case 'edit_pages_per_page':
case 'edit_comments_per_page':
case 'upload_per_page':
case 'categories_per_page':
case 'edit_tags_per_page':
$value = (int) $value;
if ( $value < 1 || $value > 999 )
return;
break;
default:
$value = apply_filters('set-screen-option', false, $option, $value);
if ( false === $value )
return;
break;
}
update_usermeta($user->ID, $option, $value);
wp_redirect( remove_query_arg( array('pagenum', 'apage', 'paged'), wp_get_referer() ) );
exit;
}
}

View File

@ -3394,7 +3394,7 @@ function screen_meta($screen) {
if ( $show_screen ) :
?>
<div id="screen-options-wrap" class="hidden">
<form id="adv-settings" action="" method="get">
<form id="adv-settings" action="" method="post">
<h5><?php _e('Show on screen') ?></h5>
<div class="metabox-prefs">
<?php
@ -3559,7 +3559,9 @@ function screen_options($screen) {
$return = '<h5>' . __('Options') . "</h5>\n";
$return .= "<div class='screen-options'>\n";
if ( !empty($per_page_label) )
$return .= "<label for='$option'>$per_page_label</label> <input type='text' class='screen-per-page' name='$option' id='$option' maxlength='3' value='$per_page' />\n";
$return .= "<label for='$option'>$per_page_label</label> <input type='text' class='screen-per-page' name='wp_screen_options[value]' id='$option' maxlength='3' value='$per_page' />\n";
$return .= "<input type='submit' class='button' value='" . __('Apply') . "' />";
$return .= "<input type='hidden' name='wp_screen_options[option]' value='$option' />";
$return .= "</div>\n";
return $return;
}

View File

@ -116,34 +116,6 @@ columns = {
$(document).ready(function(){columns.init();});
screenOptions = {
init : function() {
$('.screen-per-page').change(function() {
var option = this.id, value = parseInt($(this).val(), 10);
if ( isNaN(value) ) {
$(this).val('');
return;
}
screenOptions.save_screen_option(option, value);
}).parents('form').submit(function(e) {
e.preventDefault();
return false;
});
},
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);
// stub for doing better warnings

File diff suppressed because one or more lines are too long

View File

@ -60,7 +60,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'utils', "/wp-admin/js/utils$suffix.js", false, '20090102' );
$scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), '20090406' );
$scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), '20090416' );
$scripts->add_data( 'common', 'group', 1 );
$scripts->localize( 'common', 'commonL10n', array(
'warnDelete' => __("You are about to delete the selected items.\n 'Cancel' to stop, 'OK' to delete."),