Move edit.php bulk actions code to a handler in the list table class. see #16166.
git-svn-id: https://develop.svn.wordpress.org/trunk@17276 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
166014d76e
commit
aa8519609e
@ -38,93 +38,7 @@ unset( $_redirect );
|
|||||||
$doaction = $wp_list_table->current_action();
|
$doaction = $wp_list_table->current_action();
|
||||||
|
|
||||||
if ( $doaction ) {
|
if ( $doaction ) {
|
||||||
check_admin_referer('bulk-posts');
|
$wp_list_table->do_bulk_actions( $doaction );
|
||||||
|
|
||||||
$sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
|
|
||||||
$sendback = $wp_list_table->add_query_args( $sendback );
|
|
||||||
if ( strpos($sendback, 'post.php') !== false )
|
|
||||||
$sendback = admin_url($post_new_file);
|
|
||||||
|
|
||||||
if ( 'delete_all' == $doaction ) {
|
|
||||||
$post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['post_status']);
|
|
||||||
if ( get_post_status_object($post_status) ) // Check the post status exists first
|
|
||||||
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) );
|
|
||||||
$doaction = 'delete';
|
|
||||||
} elseif ( isset( $_REQUEST['media'] ) ) {
|
|
||||||
$post_ids = $_REQUEST['media'];
|
|
||||||
} elseif ( isset( $_REQUEST['ids'] ) ) {
|
|
||||||
$post_ids = explode( ',', $_REQUEST['ids'] );
|
|
||||||
} elseif ( !empty( $_REQUEST['post'] ) ) {
|
|
||||||
$post_ids = array_map('intval', $_REQUEST['post']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !isset( $post_ids ) ) {
|
|
||||||
wp_redirect( admin_url("edit.php?post_type=$post_type") );
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ( $doaction ) {
|
|
||||||
case 'trash':
|
|
||||||
$trashed = 0;
|
|
||||||
foreach( (array) $post_ids as $post_id ) {
|
|
||||||
if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
|
|
||||||
wp_die( __('You are not allowed to move this item to the Trash.') );
|
|
||||||
|
|
||||||
if ( !wp_trash_post($post_id) )
|
|
||||||
wp_die( __('Error in moving to Trash.') );
|
|
||||||
|
|
||||||
$trashed++;
|
|
||||||
}
|
|
||||||
$sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids) ), $sendback );
|
|
||||||
break;
|
|
||||||
case 'untrash':
|
|
||||||
$untrashed = 0;
|
|
||||||
foreach( (array) $post_ids as $post_id ) {
|
|
||||||
if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
|
|
||||||
wp_die( __('You are not allowed to restore this item from the Trash.') );
|
|
||||||
|
|
||||||
if ( !wp_untrash_post($post_id) )
|
|
||||||
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 ) {
|
|
||||||
$post_del = & get_post($post_id);
|
|
||||||
|
|
||||||
if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
|
|
||||||
wp_die( __('You are not allowed to delete this item.') );
|
|
||||||
|
|
||||||
if ( $post_del->post_type == 'attachment' ) {
|
|
||||||
if ( ! wp_delete_attachment($post_id) )
|
|
||||||
wp_die( __('Error in deleting...') );
|
|
||||||
} else {
|
|
||||||
if ( !wp_delete_post($post_id) )
|
|
||||||
wp_die( __('Error in deleting...') );
|
|
||||||
}
|
|
||||||
$deleted++;
|
|
||||||
}
|
|
||||||
$sendback = add_query_arg('deleted', $deleted, $sendback);
|
|
||||||
break;
|
|
||||||
case 'edit':
|
|
||||||
$done = bulk_edit_posts($_REQUEST);
|
|
||||||
|
|
||||||
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 );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback );
|
|
||||||
|
|
||||||
wp_redirect($sendback);
|
|
||||||
exit();
|
|
||||||
} elseif ( ! empty($_REQUEST['_wp_http_referer']) ) {
|
} elseif ( ! empty($_REQUEST['_wp_http_referer']) ) {
|
||||||
wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
|
wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
|
||||||
exit;
|
exit;
|
||||||
|
@ -1013,6 +1013,105 @@ class WP_Posts_List_Table extends WP_List_Table {
|
|||||||
</tbody></table></form>
|
</tbody></table></form>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function do_bulk_actions( $doaction = null ) {
|
||||||
|
if ( null === $doaction )
|
||||||
|
$doaction = $this->current_action();
|
||||||
|
|
||||||
|
if ( ! $doaction )
|
||||||
|
return;
|
||||||
|
|
||||||
|
check_admin_referer('bulk-posts');
|
||||||
|
|
||||||
|
$sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
|
||||||
|
if ( strpos($sendback, 'post.php') !== false )
|
||||||
|
$sendback = admin_url($post_new_file);
|
||||||
|
|
||||||
|
if ( 'delete_all' == $doaction ) {
|
||||||
|
$post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['post_status']);
|
||||||
|
if ( get_post_status_object($post_status) ) // Check the post status exists first
|
||||||
|
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) );
|
||||||
|
$doaction = 'delete';
|
||||||
|
} elseif ( isset( $_REQUEST['media'] ) ) {
|
||||||
|
$post_ids = $_REQUEST['media'];
|
||||||
|
} elseif ( isset( $_REQUEST['ids'] ) ) {
|
||||||
|
$post_ids = explode( ',', $_REQUEST['ids'] );
|
||||||
|
} elseif ( !empty( $_REQUEST['post'] ) ) {
|
||||||
|
$post_ids = array_map('intval', $_REQUEST['post']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !isset( $post_ids ) ) {
|
||||||
|
wp_redirect( admin_url("edit.php?post_type=$post_type") );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ( $doaction ) {
|
||||||
|
case 'trash':
|
||||||
|
$trashed = 0;
|
||||||
|
foreach( (array) $post_ids as $post_id ) {
|
||||||
|
if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
|
||||||
|
wp_die( __('You are not allowed to move this item to the Trash.') );
|
||||||
|
|
||||||
|
if ( !wp_trash_post($post_id) )
|
||||||
|
wp_die( __('Error in moving to Trash.') );
|
||||||
|
|
||||||
|
$trashed++;
|
||||||
|
}
|
||||||
|
$sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids) ), $sendback );
|
||||||
|
break;
|
||||||
|
case 'untrash':
|
||||||
|
$untrashed = 0;
|
||||||
|
foreach( (array) $post_ids as $post_id ) {
|
||||||
|
if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
|
||||||
|
wp_die( __('You are not allowed to restore this item from the Trash.') );
|
||||||
|
|
||||||
|
if ( !wp_untrash_post($post_id) )
|
||||||
|
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 ) {
|
||||||
|
$post_del = & get_post($post_id);
|
||||||
|
|
||||||
|
if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
|
||||||
|
wp_die( __('You are not allowed to delete this item.') );
|
||||||
|
|
||||||
|
if ( $post_del->post_type == 'attachment' ) {
|
||||||
|
if ( ! wp_delete_attachment($post_id) )
|
||||||
|
wp_die( __('Error in deleting...') );
|
||||||
|
} else {
|
||||||
|
if ( !wp_delete_post($post_id) )
|
||||||
|
wp_die( __('Error in deleting...') );
|
||||||
|
}
|
||||||
|
$deleted++;
|
||||||
|
}
|
||||||
|
$sendback = add_query_arg('deleted', $deleted, $sendback);
|
||||||
|
break;
|
||||||
|
case 'edit':
|
||||||
|
$done = bulk_edit_posts($_REQUEST);
|
||||||
|
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
$sendback = apply_filters( "bulk_actions-posts-$doaction", $sendback, $doaction );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sendback = remove_query_arg( array( 'action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view' ), $sendback );
|
||||||
|
$sendback = $this->add_query_args( $sendback );
|
||||||
|
wp_redirect( $sendback );
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user