Fix errors when bulk actions executed on empty list, props nacin, see #11184

git-svn-id: http://svn.automattic.com/wordpress/trunk@12317 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-12-03 01:43:49 +00:00
parent 60c6ba72c1
commit ae20d06e94
8 changed files with 40 additions and 23 deletions

View File

@ -34,17 +34,20 @@ case 'addcat':
break; break;
case 'delete': case 'delete':
if ( !isset( $_GET['cat_ID'] ) ) {
wp_redirect('categories.php');
exit;
}
$cat_ID = (int) $_GET['cat_ID']; $cat_ID = (int) $_GET['cat_ID'];
check_admin_referer('delete-category_' . $cat_ID); check_admin_referer('delete-category_' . $cat_ID);
if ( !current_user_can('manage_categories') ) if ( !current_user_can('manage_categories') )
wp_die(__('Cheatin’ uh?')); wp_die(__('Cheatin’ uh?'));
$cat_name = get_cat_name($cat_ID);
// Don't delete the default cats. // Don't delete the default cats.
if ( $cat_ID == get_option('default_category') ) if ( $cat_ID == get_option('default_category') )
wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name)); wp_die( sprintf( __("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), get_cat_name($cat_ID) ) );
wp_delete_category($cat_ID); wp_delete_category($cat_ID);
@ -59,18 +62,20 @@ case 'bulk-delete':
if ( !current_user_can('manage_categories') ) if ( !current_user_can('manage_categories') )
wp_die( __('You are not allowed to delete categories.') ); wp_die( __('You are not allowed to delete categories.') );
foreach ( (array) $_GET['delete'] as $cat_ID ) { $cats = (array) $_GET['delete'];
$cat_name = get_cat_name($cat_ID); $default_cat = get_option('default_category');
foreach ( $cats as $cat_ID ) {
$cat_ID = (int) $cat_ID;
// Don't delete the default cats. // Don't delete the default cat.
if ( $cat_ID == get_option('default_category') ) if ( $cat_ID == $default_cat )
wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name)); wp_die( sprintf( __("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), get_cat_name($cat_ID) ) );
wp_delete_category($cat_ID); wp_delete_category($cat_ID);
} }
wp_safe_redirect( wp_get_referer() ); wp_safe_redirect( wp_get_referer() );
exit(); exit;
break; break;
case 'edit': case 'edit':

View File

@ -18,13 +18,14 @@ if ( isset($_GET['action']) && isset($_GET['delete']) ) {
wp_die(__('Cheatin&#8217; uh?')); wp_die(__('Cheatin&#8217; uh?'));
if ( 'delete' == $doaction ) { if ( 'delete' == $doaction ) {
foreach( (array) $_GET['delete'] as $cat_ID ) { $cats = (array) $_GET['delete'];
$cat_name = get_term_field('name', $cat_ID, 'link_category'); $default_cat_id = get_option('default_link_category');
$default_cat_id = get_option('default_link_category');
foreach( $cats as $cat_ID ) {
$cat_ID = (int) $cat_ID;
// Don't delete the default cats. // Don't delete the default cats.
if ( $cat_ID == $default_cat_id ) if ( $cat_ID == $default_cat_id )
wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name)); wp_die( sprintf( __("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), get_term_field('name', $cat_ID, 'link_category') ) );
wp_delete_term($cat_ID, 'link_category', array('default' => $default_cat_id)); wp_delete_term($cat_ID, 'link_category', array('default' => $default_cat_id));
} }

View File

@ -44,6 +44,11 @@ case 'addtag':
break; break;
case 'delete': case 'delete':
if ( !isset( $_GET['tag_ID'] ) ) {
wp_redirect("edit-tags.php?taxonomy=$taxonomy");
exit;
}
$tag_ID = (int) $_GET['tag_ID']; $tag_ID = (int) $_GET['tag_ID'];
check_admin_referer('delete-tag_' . $tag_ID); check_admin_referer('delete-tag_' . $tag_ID);
@ -70,8 +75,8 @@ case 'bulk-delete':
if ( !current_user_can('manage_categories') ) if ( !current_user_can('manage_categories') )
wp_die(__('Cheatin&#8217; uh?')); wp_die(__('Cheatin&#8217; uh?'));
$tags = $_GET['delete_tags']; $tags = (array) $_GET['delete_tags'];
foreach( (array) $tags as $tag_ID ) { foreach( $tags as $tag_ID ) {
wp_delete_term( $tag_ID, $taxonomy); wp_delete_term( $tag_ID, $taxonomy);
} }

View File

@ -74,7 +74,7 @@ inlineEditPost = {
}, },
setBulk : function() { setBulk : function() {
var te = '', type = this.type, tax; var te = '', type = this.type, tax, c = true;
this.revert(); this.revert();
$('#bulk-edit td').attr('colspan', $('.widefat:first thead th:visible').length); $('#bulk-edit td').attr('colspan', $('.widefat:first thead th:visible').length);
@ -83,12 +83,16 @@ inlineEditPost = {
$('tbody th.check-column input[type="checkbox"]').each(function(i){ $('tbody th.check-column input[type="checkbox"]').each(function(i){
if ( $(this).attr('checked') ) { if ( $(this).attr('checked') ) {
c = false;
var id = $(this).val(), theTitle; var id = $(this).val(), theTitle;
theTitle = $('#inline_'+id+' .post_title').text() || inlineEditL10n.notitle; theTitle = $('#inline_'+id+' .post_title').text() || inlineEditL10n.notitle;
te += '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>'; te += '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>';
} }
}); });
if ( c )
return this.revert();
$('#bulk-titles').html(te); $('#bulk-titles').html(te);
$('#bulk-titles a').click(function() { $('#bulk-titles a').click(function() {
var id = $(this).attr('id').substr(1); var id = $(this).attr('id').substr(1);

File diff suppressed because one or more lines are too long

View File

@ -18,13 +18,14 @@ if ( isset($_GET['action']) && isset($_GET['linkcheck']) ) {
wp_die( __('You do not have sufficient permissions to edit the links for this blog.') ); wp_die( __('You do not have sufficient permissions to edit the links for this blog.') );
if ( 'delete' == $doaction ) { if ( 'delete' == $doaction ) {
foreach ( (array) $_GET['linkcheck'] as $link_id ) { $bulklinks = (array) $_GET['linkcheck'];
foreach ( $bulklinks as $link_id ) {
$link_id = (int) $link_id; $link_id = (int) $link_id;
wp_delete_link($link_id); wp_delete_link($link_id);
} }
wp_redirect( wp_get_referer() ); wp_safe_redirect( wp_get_referer() );
exit; exit;
} }
} elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) { } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {

View File

@ -64,7 +64,7 @@ if ( !empty($action) ) {
check_admin_referer('bulk-manage-plugins'); check_admin_referer('bulk-manage-plugins');
$plugins = (array) $_POST['checked']; $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
$plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); //Only activate plugins which are not already active. $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); //Only activate plugins which are not already active.
if ( empty($plugins) ) { if ( empty($plugins) ) {
wp_redirect("plugins.php?plugin_status=$status&paged=$page"); wp_redirect("plugins.php?plugin_status=$status&paged=$page");
@ -115,7 +115,7 @@ if ( !empty($action) ) {
check_admin_referer('bulk-manage-plugins'); check_admin_referer('bulk-manage-plugins');
$plugins = (array) $_POST['checked']; $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
$plugins = array_filter($plugins, 'is_plugin_active'); //Do not deactivate plugins which are already deactivated. $plugins = array_filter($plugins, 'is_plugin_active'); //Do not deactivate plugins which are already deactivated.
if ( empty($plugins) ) { if ( empty($plugins) ) {
wp_redirect("plugins.php?plugin_status=$status&paged=$page"); wp_redirect("plugins.php?plugin_status=$status&paged=$page");
@ -138,7 +138,8 @@ if ( !empty($action) ) {
check_admin_referer('bulk-manage-plugins'); check_admin_referer('bulk-manage-plugins');
$plugins = (array) $_REQUEST['checked']; //$_POST = from the plugin form; $_GET = from the FTP details screen. //$_POST = from the plugin form; $_GET = from the FTP details screen.
$plugins = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
$plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); //Do not allow to delete Activated plugins. $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); //Do not allow to delete Activated plugins.
if ( empty($plugins) ) { if ( empty($plugins) ) {
wp_redirect("plugins.php?plugin_status=$status&paged=$page"); wp_redirect("plugins.php?plugin_status=$status&paged=$page");

View File

@ -342,7 +342,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'theme-preview', "/wp-admin/js/theme-preview$suffix.js", array( 'thickbox', 'jquery' ), '20090319' ); $scripts->add( 'theme-preview', "/wp-admin/js/theme-preview$suffix.js", array( 'thickbox', 'jquery' ), '20090319' );
$scripts->add_data( 'theme-preview', 'group', 1 ); $scripts->add_data( 'theme-preview', 'group', 1 );
$scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'suggest' ), '20091016' ); $scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'suggest' ), '20091202' );
$scripts->add_data( 'inline-edit-post', 'group', 1 ); $scripts->add_data( 'inline-edit-post', 'group', 1 );
$scripts->localize( 'inline-edit-post', 'inlineEditL10n', array( $scripts->localize( 'inline-edit-post', 'inlineEditL10n', array(
'error' => __('Error while saving the changes.'), 'error' => __('Error while saving the changes.'),