Fix bulk edit, some cleanup and message fixes for moving in/out of the trash, see #4529

git-svn-id: http://svn.automattic.com/wordpress/trunk@11807 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-08-12 10:57:15 +00:00
parent 0fc380223a
commit 52f4940dfb
6 changed files with 160 additions and 152 deletions

View File

@ -13,17 +13,23 @@ if ( !current_user_can('edit_pages') )
wp_die(__('Cheatin’ uh?'));
// Handle bulk actions
if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) || isset($_GET['bulk_edit']) ) {
check_admin_referer('bulk-pages');
$sendback = wp_get_referer();
if ( strpos($sendback, 'page.php') !== false )
$sendback = admin_url('page-new.php');
if ( isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
$post_status = $wpdb->escape($_GET['post_status']);
$post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = '$post_status'" );
$post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_GET['post_status']);
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = %s", $post_status ) );
$doaction = 'delete';
} elseif ( ($_GET['action'] != -1 || $_GET['action2'] != -1) && isset($_GET['post']) ) {
$post_ids = $_GET['post'];
$post_ids = array_map( 'intval', (array) $_GET['post'] );
$doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
} else wp_redirect($_SERVER['HTTP_REFERER']);
} else {
wp_redirect( admin_url('edit-pages.php') );
}
switch ( $doaction ) {
case 'trash':
@ -37,64 +43,56 @@ if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delet
$trashed++;
}
$sendback = add_query_arg('trashed', $trashed, $sendback);
break;
case 'untrash':
$untrashed = 0;
foreach( (array) $post_ids as $post_id ) {
if ( !current_user_can('delete_page', $post_id) )
wp_die( __('You are not allowed to remove this page from the trash.') );
wp_die( __('You are not allowed to restore this page from the trash.') );
if ( !wp_untrash_post($post_id) )
wp_die( __('Error in removing from trash...') );
wp_die( __('Error in restoring from trash...') );
$untrashed++;
}
$sendback = add_query_arg('untrashed', $untrashed, $sendback);
break;
case 'delete':
$deleted = 0;
foreach( (array) $post_ids as $post_id_del ) {
$post_del = & get_post($post_id_del);
foreach( (array) $post_ids as $post_id ) {
$post_del = & get_post($post_id);
if ( !current_user_can('delete_page', $post_id_del) )
if ( !current_user_can('delete_page', $post_id) )
wp_die( __('You are not allowed to delete this page.') );
if ( $post_del->post_type == 'attachment' ) {
if ( ! wp_delete_attachment($post_id_del) )
if ( ! wp_delete_attachment($post_id) )
wp_die( __('Error in deleting...') );
} else {
if ( !wp_delete_post($post_id_del) )
if ( !wp_delete_post($post_id) )
wp_die( __('Error in deleting...') );
}
$deleted++;
}
$sendback = add_query_arg('deleted', $deleted, $sendback);
break;
case 'edit':
if ( -1 == $_GET['_status'] ) {
$_GET['post_status'] = null;
unset($_GET['_status'], $_GET['post_status']);
} else {
$_GET['post_status'] = $_GET['_status'];
}
$_GET['post_type'] = 'page';
$done = bulk_edit_posts($_GET);
break;
}
$sendback = wp_get_referer();
if (strpos($sendback, 'page.php') !== false) $sendback = admin_url('page-new.php');
elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
if ( isset($done) ) {
if ( is_array($done) ) {
$done['updated'] = count( $done['updated'] );
$done['skipped'] = count( $done['skipped'] );
$done['locked'] = count( $done['locked'] );
$sendback = add_query_arg( $done, $sendback );
}
if ( isset($deleted) )
$sendback = add_query_arg('deleted', $deleted, $sendback);
elseif ( isset($trashed) )
$sendback = add_query_arg('trashed', $trashed, $sendback);
elseif ( isset($untrashed) )
$sendback = add_query_arg('untrashed', $untrashed, $sendback);
break;
}
if ( isset($_GET['action']) )
$sendback = remove_query_arg( array('action', 'action2', 'post_parent', 'page_template', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view', 'post_type'), $sendback );
wp_redirect($sendback);
exit();
} elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
@ -181,7 +179,7 @@ $_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated'
<?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
endif; ?>
<form id="posts-filter" action="" method="get">
<form id="posts-filter" action="<?php echo admin_url('edit-pages.php'); ?>" method="get">
<ul class="subsubsub">
<?php

View File

@ -21,25 +21,29 @@ if ( $_redirect = intval( max( @$_GET['p'], @$_GET['attachment_id'], @$_GET['pag
}
// Handle bulk actions
if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) || isset($_GET['bulk_edit']) ) {
check_admin_referer('bulk-posts');
$sendback = wp_get_referer();
if ( strpos($sendback, 'post.php') !== false )
$sendback = admin_url('post-new.php');
if ( isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
$post_status = $wpdb->escape($_GET['post_status']);
$post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='post' AND post_status = '$post_status'" );
$post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_GET['post_status']);
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='post' AND post_status = %s", $post_status ) );
$doaction = 'delete';
} elseif ( ($_GET['action'] != -1 || $_GET['action2'] != -1) && isset($_GET['post']) ) {
$post_ids = $_GET['post'];
$post_ids = array_map( 'intval', (array) $_GET['post'] );
$doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
} else wp_redirect($_SERVER['HTTP_REFERER']);
} else {
wp_redirect( admin_url('edit.php') );
}
switch ( $doaction ) {
case 'trash':
$trashed = 0;
foreach( (array) $post_ids as $post_id ) {
$post_del = & get_post($post_id);
if ( !current_user_can('delete_post', $post_id_del) )
if ( !current_user_can('delete_post', $post_id) )
wp_die( __('You are not allowed to move this post to the trash.') );
if ( !wp_trash_post($post_id) )
@ -47,66 +51,55 @@ if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delet
$trashed++;
}
$sendback = add_query_arg('trashed', $trashed, $sendback);
break;
case 'untrash':
$untrashed = 0;
foreach( (array) $post_ids as $post_id ) {
$post_del = & get_post($post_id);
if ( !current_user_can('delete_post', $post_id_del) )
wp_die( __('You are not allowed to remove this post from the trash.') );
if ( !current_user_can('delete_post', $post_id) )
wp_die( __('You are not allowed to restore this post from the trash.') );
if ( !wp_untrash_post($post_id) )
wp_die( __('Error in removing from trash...') );
wp_die( __('Error in restoring from trash...') );
$untrashed++;
}
$sendback = add_query_arg('untrashed', $untrashed, $sendback);
break;
case 'delete':
$deleted = 0;
foreach( (array) $post_ids as $post_id_del ) {
$post_del = & get_post($post_id_del);
foreach( (array) $post_ids as $post_id ) {
$post_del = & get_post($post_id);
if ( !current_user_can('delete_post', $post_id_del) )
if ( !current_user_can('delete_post', $post_id) )
wp_die( __('You are not allowed to delete this post.') );
if ( $post_del->post_type == 'attachment' ) {
if ( ! wp_delete_attachment($post_id_del) )
if ( ! wp_delete_attachment($post_id) )
wp_die( __('Error in deleting...') );
} else {
if ( !wp_delete_post($post_id_del) )
if ( !wp_delete_post($post_id) )
wp_die( __('Error in deleting...') );
}
$deleted++;
}
$sendback = add_query_arg('deleted', $deleted, $sendback);
break;
case 'edit':
if ( -1 == $_GET['_status'] ) {
$_GET['post_status'] = null;
unset($_GET['_status'], $_GET['post_status']);
} else {
$_GET['post_status'] = $_GET['_status'];
}
$done = bulk_edit_posts($_GET);
break;
}
$sendback = wp_get_referer();
if ( strpos($sendback, 'post.php') !== false ) $sendback = admin_url('post-new.php');
elseif ( strpos($sendback, 'attachments.php') !== false ) $sendback = admin_url('attachments.php');
if ( isset($done) ) {
if ( is_array($done) ) {
$done['updated'] = count( $done['updated'] );
$done['skipped'] = count( $done['skipped'] );
$done['locked'] = count( $done['locked'] );
$sendback = add_query_arg( $done, $sendback );
}
if ( isset($deleted) )
$sendback = add_query_arg('deleted', $deleted, $sendback);
elseif ( isset($trashed) )
$sendback = add_query_arg('trashed', $trashed, $sendback);
elseif ( isset($untrashed) )
$sendback = add_query_arg('untrashed', $untrashed, $sendback);
break;
}
if ( isset($_GET['action']) )
$sendback = remove_query_arg( array('action', 'action2', 'cat', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view', 'post_type'), $sendback );
wp_redirect($sendback);
exit();
} elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
@ -179,7 +172,7 @@ $_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated'
</p></div>
<?php } ?>
<form id="posts-filter" action="" method="get">
<form id="posts-filter" action="<?php echo admin_url('edit.php'); ?>" method="get">
<ul class="subsubsub">
<?php

View File

@ -236,6 +236,14 @@ function bulk_edit_posts( $post_data = null ) {
wp_die( __('You are not allowed to edit posts.') );
}
if ( -1 == $post_data['_status'] ) {
$post_data['post_status'] = null;
unset($post_data['post_status']);
} else {
$post_data['post_status'] = $post_data['_status'];
}
unset($post_data['_status']);
$post_IDs = array_map( 'intval', (array) $post_data['post'] );
$reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tags_input', 'post_category', 'sticky' );
@ -298,7 +306,7 @@ function bulk_edit_posts( $post_data = null ) {
$post_data['ID'] = $post_ID;
$updated[] = wp_update_post( $post_data );
if ( current_user_can( 'edit_others_posts' ) && isset( $post_data['sticky'] ) ) {
if ( isset( $post_data['sticky'] ) && current_user_can( 'edit_others_posts' ) ) {
if ( 'sticky' == $post_data['sticky'] )
stick_post( $post_ID );
else

View File

@ -52,8 +52,6 @@ function redirect_page($page_ID) {
$location = add_query_arg( 'message', 3, wp_get_referer() );
$location = explode('#', $location);
$location = $location[0] . '#postcustom';
} elseif ($action == 'editattachment') {
$location = 'attachments.php';
} else {
$location = add_query_arg( 'message', 1, get_edit_post_link( $page_ID, 'url' ) );
}
@ -82,8 +80,14 @@ case 'edit':
$page_ID = $post_ID = $p = (int) $_GET['post'];
$post = get_post_to_edit($page_ID);
if ( empty($post->ID) ) wp_die( __('You attempted to edit a page that doesn&#8217;t exist. Perhaps it was deleted?') );
if ( $post->post_status == 'trash' ) wp_die( __('You can&#8217;t edit this page because it is in the Trash. Please move it out of the Trash and try again.') );
if ( empty($post->ID) )
wp_die( __('You attempted to edit a page that doesn&#8217;t exist. Perhaps it was deleted?') );
if ( !current_user_can('edit_page', $page_ID) )
wp_die( __('You are not allowed to edit this page.') );
if ( 'trash' == $post->post_status )
wp_die( __('You can&#8217;t edit this page because it is in the Trash. Please move it out of the Trash and try again.') );
if ( 'page' != $post->post_type ) {
wp_redirect( get_edit_post_link( $post_ID, 'url' ) );
@ -97,7 +101,6 @@ case 'edit':
wp_enqueue_script('media-upload');
wp_enqueue_script('word-count');
if ( current_user_can('edit_page', $page_ID) ) {
if ( $last = wp_check_post_lock( $post->ID ) ) {
$last_user = get_userdata( $last );
$last_user_name = $last_user ? $last_user->display_name : __('Somebody');
@ -108,10 +111,6 @@ case 'edit':
wp_set_post_lock( $post->ID );
wp_enqueue_script('autosave');
}
}
if ( !current_user_can('edit_page', $page_ID) )
die ( __('You are not allowed to edit this page.') );
include('edit-page-form.php');
break;
@ -142,7 +141,7 @@ case 'editpost':
break;
case 'trash':
$post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
$post_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']);
check_admin_referer('trash-page_' . $post_id);
$post = & get_post($post_id);
@ -151,38 +150,42 @@ case 'trash':
wp_die( __('You are not allowed to move this page to the trash.') );
if ( !wp_trash_post($post_id) )
wp_die( __('Error in removing from trash...') );
wp_die( __('Error in moving to trash...') );
$sendback = wp_get_referer();
if (strpos($sendback, 'page.php') !== false) $sendback = admin_url('edit-pages.php?trashed=1');
elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
else $sendback = add_query_arg('trashed', 1, $sendback);
if ( strpos($sendback, 'page.php') !== false )
$sendback = admin_url('edit-pages.php?trashed=1');
else
$sendback = add_query_arg('trashed', 1, $sendback);
wp_redirect($sendback);
exit();
break;
case 'untrash':
$post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
$post_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']);
check_admin_referer('untrash-page_' . $post_id);
$post = & get_post($post_id);
if ( !current_user_can('delete_page', $page_id) )
wp_die( __('You are not allowed to remove this page form the trash.') );
wp_die( __('You are not allowed to move this page out of the trash.') );
if ( !wp_untrash_post($post_id) )
wp_die( __('Error in removing from trash...') );
wp_die( __('Error in restoring from trash...') );
$sendback = wp_get_referer();
if (strpos($sendback, 'page.php') !== false) $sendback = admin_url('edit-pages.php?untrashed=1');
elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
else $sendback = add_query_arg('untrashed', 1, $sendback);
if ( strpos($sendback, 'page.php') !== false )
$sendback = admin_url('edit-pages.php?untrashed=1');
else
$sendback = add_query_arg('untrashed', 1, $sendback);
wp_redirect($sendback);
exit();
break;
case 'delete':
$page_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
$page_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']);
check_admin_referer('delete-page_' . $page_id);
$page = & get_post($page_id);
@ -199,9 +202,11 @@ case 'delete':
}
$sendback = wp_get_referer();
if (strpos($sendback, 'page.php') !== false) $sendback = admin_url('edit-pages.php?deleted=1');
elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
else $sendback = add_query_arg('deleted', 1, $sendback);
if ( strpos($sendback, 'page.php') !== false )
$sendback = admin_url('edit-pages.php?deleted=1');
else
$sendback = add_query_arg('deleted', 1, $sendback);
wp_redirect($sendback);
exit();
break;

View File

@ -55,8 +55,6 @@ function redirect_post($post_ID = '') {
$location = add_query_arg( 'message', 3, wp_get_referer() );
$location = explode('#', $location);
$location = $location[0] . '#postcustom';
} elseif ($action == 'editattachment') {
$location = 'attachments.php';
} elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) {
$location = "post.php?action=edit&post=$post_ID&message=7";
} else {
@ -115,8 +113,14 @@ case 'edit':
$post_ID = $p = (int) $_GET['post'];
$post = get_post($post_ID);
if ( empty($post->ID) ) wp_die( __('You attempted to edit a post that doesn&#8217;t exist. Perhaps it was deleted?') );
if ( $post->post_status == 'trash' ) wp_die( __('You can&#8217;t edit this post because it is in the Trash. Please move it out of the Trash and try again.') );
if ( empty($post->ID) )
wp_die( __('You attempted to edit a post that doesn&#8217;t exist. Perhaps it was deleted?') );
if ( !current_user_can('edit_post', $post_ID) )
wp_die( __('You are not allowed to edit this post.') );
if ( 'trash' == $post->post_status )
wp_die( __('You can&#8217;t edit this post because it is in the Trash. Please restore it and try again.') );
if ( 'post' != $post->post_type ) {
wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
@ -132,7 +136,6 @@ case 'edit':
wp_enqueue_script( 'admin-comments' );
enqueue_comment_hotkeys_js();
if ( current_user_can('edit_post', $post_ID) ) {
if ( $last = wp_check_post_lock( $post->ID ) ) {
$last_user = get_userdata( $last );
$last_user_name = $last_user ? $last_user->display_name : __('Somebody');
@ -143,13 +146,8 @@ case 'edit':
wp_set_post_lock( $post->ID );
wp_enqueue_script('autosave');
}
}
$title = __('Edit Post');
if ( !current_user_can('edit_post', $post_ID) )
die ( __('You are not allowed to edit this post.') );
$post = get_post_to_edit($post_ID);
include('edit-form-advanced.php');
@ -183,7 +181,7 @@ case 'editpost':
break;
case 'trash':
$post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
$post_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']);
check_admin_referer('trash-post_' . $post_id);
$post = & get_post($post_id);
@ -195,29 +193,33 @@ case 'trash':
wp_die( __('Error in moving to trash...') );
$sendback = wp_get_referer();
if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('edit.php?trashed=1');
elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
else $sendback = add_query_arg('trashed', 1, $sendback);
if ( strpos($sendback, 'post.php') !== false )
$sendback = admin_url('edit.php?trashed=1');
else
$sendback = add_query_arg('trashed', 1, $sendback);
wp_redirect($sendback);
exit();
break;
case 'untrash':
$post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
$post_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']);
check_admin_referer('untrash-post_' . $post_id);
$post = & get_post($post_id);
if ( !current_user_can('delete_post', $post_id) )
wp_die( __('You are not allowed to remove this post from the trash.') );
wp_die( __('You are not allowed to move this post out of the trash.') );
if ( ! wp_untrash_post($post_id) )
wp_die( __('Error in removing from trash...') );
wp_die( __('Error in restoring from trash...') );
$sendback = wp_get_referer();
if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('edit.php?untrashed=1');
elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
else $sendback = add_query_arg('untrashed', 1, $sendback);
if ( strpos($sendback, 'post.php') !== false )
$sendback = admin_url('edit.php?untrashed=1');
else
$sendback = add_query_arg('untrashed', 1, $sendback);
wp_redirect($sendback);
exit();
break;
@ -240,9 +242,11 @@ case 'delete':
}
$sendback = wp_get_referer();
if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('edit.php?deleted=1');
elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
else $sendback = add_query_arg('deleted', 1, $sendback);
if ( strpos($sendback, 'post.php') !== false )
$sendback = admin_url('edit.php?deleted=1');
else
$sendback = add_query_arg('deleted', 1, $sendback);
wp_redirect($sendback);
exit();
break;

View File

@ -99,7 +99,7 @@ if ( isset($_GET['find_detached'] ) ) {
case 'untrash':
foreach( (array) $post_ids as $post_id ) {
if ( !current_user_can('delete_post', $post_id) )
wp_die( __('You are not allowed to remove this post from the trash.') );
wp_die( __('You are not allowed to move this post out of the trash.') );
if ( !wp_untrash_post($post_id) )
wp_die( __('Error in restoring from trash...') );