Introduce WP_List_Table::current_action() and use throughout admin list screens. See #14579

git-svn-id: https://develop.svn.wordpress.org/trunk@15642 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
scribu 2010-09-22 00:10:39 +00:00
parent 6121bb1234
commit 728285edbd
9 changed files with 155 additions and 105 deletions

View File

@ -12,20 +12,21 @@ require_once('./admin.php');
$wp_list_table = get_list_table('comments');
$wp_list_table->check_permissions();
if ( isset( $_REQUEST['doaction'] ) || isset( $_REQUEST['doaction2'] ) || isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
$doaction = $wp_list_table->current_action();
if ( $doaction ) {
check_admin_referer( 'bulk-comments' );
if ( ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) && !empty( $_REQUEST['pagegen_timestamp'] ) ) {
if ( 'delete_all' == $do_action && !empty( $_REQUEST['pagegen_timestamp'] ) ) {
$comment_status = $wpdb->escape( $_REQUEST['comment_status'] );
$delete_time = $wpdb->escape( $_REQUEST['pagegen_timestamp'] );
$comment_ids = $wpdb->get_col( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = '$comment_status' AND '$delete_time' > comment_date_gmt" );
$doaction = 'delete';
} elseif ( ( $_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1 ) && isset( $_REQUEST['delete_comments'] ) ) {
} elseif ( isset( $_REQUEST['delete_comments'] ) ) {
$comment_ids = $_REQUEST['delete_comments'];
$doaction = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2'];
} elseif ( $_REQUEST['doaction'] == 'undo' && isset( $_REQUEST['ids'] ) ) {
} elseif ( isset( $_REQUEST['ids'] ) ) {
$comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) );
$doaction = $_REQUEST['action'];
} else {
wp_redirect( wp_get_referer() );
}

View File

@ -22,10 +22,7 @@ if ( 'post' != $post_type ) {
$submenu_file = "edit-tags.php?taxonomy=$taxonomy";
}
if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' == $_REQUEST['action'] || 'delete' == $_REQUEST['action2'] ) )
$action = 'bulk-delete';
switch ( $action ) {
switch ( $wp_list_table->current_action() ) {
case 'add-tag':

View File

@ -21,21 +21,25 @@ if ( $_redirect = intval( max( @$_REQUEST['p'], @$_REQUEST['attachment_id'], @$_
}
// Handle bulk actions
if ( isset($_REQUEST['doaction']) || isset($_REQUEST['doaction2']) || isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2']) || isset($_REQUEST['bulk_edit']) ) {
$doaction = $wp_list_table->current_action();
if ( $doaction ) {
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 ( isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2']) ) {
$post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['post_status']);
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) );
if ( 'delete_all' == $doaction ) {
$post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
$doaction = 'delete';
} elseif ( ( $_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1 ) && ( isset($_REQUEST['post']) || isset($_REQUEST['ids']) ) ) {
$post_ids = isset($_REQUEST['post']) ? array_map( 'intval', (array) $_REQUEST['post'] ) : explode(',', $_REQUEST['ids']);
$doaction = ($_REQUEST['action'] != -1) ? $_REQUEST['action'] : $_REQUEST['action2'];
} else {
} elseif ( isset( $_REQUEST['media'] ) ) {
$post_ids = $_REQUEST['media'];
} elseif ( isset( $_REQUEST['ids'] ) ) {
$post_ids = explode( ',', $_REQUEST['ids'] );
}
if ( !isset( $post_ids ) ) {
wp_redirect( admin_url("edit.php?post_type=$post_type") );
}
@ -97,8 +101,7 @@ if ( isset($_REQUEST['doaction']) || isset($_REQUEST['doaction2']) || isset($_RE
break;
}
if ( isset($_REQUEST['action']) )
$sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback );
$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();

View File

@ -215,6 +215,13 @@ class WP_Posts_Table extends WP_List_Table {
}
}
function current_action() {
if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
return 'delete_all';
return parent::current_action();
}
function pagination( $which ) {
global $post_type_object, $mode;
@ -1080,6 +1087,19 @@ class WP_Media_Table extends WP_List_Table {
<?php
}
function current_action() {
if ( isset( $_REQUEST['find_detached'] ) )
return 'find_detached';
if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) )
return 'attach';
if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
return 'delete_all';
return parent::current_action();
}
function has_items() {
return have_posts();
}
@ -1482,6 +1502,13 @@ class WP_Terms_Table extends WP_List_Table {
return $actions;
}
function current_action() {
if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' == $_REQUEST['action'] || 'delete' == $_REQUEST['action2'] ) )
return 'bulk-delete';
return parent::current_action();
}
function get_columns() {
global $taxonomy;
@ -1861,6 +1888,13 @@ class WP_Users_Table extends WP_List_Table {
</div>
<?php
}
function current_action() {
if ( isset($_REQUEST['changeit']) && !empty($_REQUEST['new_role']) )
return 'promote';
return parent::current_action();
}
function get_columns() {
return array(
@ -2214,6 +2248,13 @@ class WP_Comments_Table extends WP_List_Table {
echo '</div>';
}
function current_action() {
if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
return 'delete_all';
return parent::current_action();
}
function get_columns() {
global $mode;
@ -3458,6 +3499,13 @@ class WP_Plugins_Table extends WP_List_Table {
<?php }
}
function current_action() {
if ( isset($_POST['clear-recent-list']) )
return 'clear-recent-list';
return parent::current_action();
}
function display_rows() {
global $status, $page;

View File

@ -246,6 +246,24 @@ class WP_List_Table {
echo "<input type='submit' value='" . esc_attr__( 'Apply' ) . "' name='doaction$two' id='doaction$two' class='button-secondary action' />\n";
}
/**
* Get the current action selected from the bulk actions dropdown.
*
* @since 3.1.0
* @access public
*
* @return string|bool The action name or False if no action was selected
*/
function current_action() {
if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] )
return $_REQUEST['action'];
if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] )
return $_REQUEST['action2'];
return false;
}
/**
* Generate row actions div
*

View File

@ -13,10 +13,10 @@ $wp_list_table = get_list_table('links');
$wp_list_table->check_permissions();
// Handle bulk deletes
if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['linkcheck'] ) ) {
check_admin_referer( 'bulk-bookmarks' );
$doaction = $wp_list_table->current_action();
$doaction = $_REQUEST['action'] ? $_REQUEST['action'] : $_REQUEST['action2'];
if ( $doaction && isset( $_REQUEST['linkcheck'] ) ) {
check_admin_referer( 'bulk-bookmarks' );
if ( 'delete' == $doaction ) {
$bulklinks = (array) $_REQUEST['linkcheck'];

View File

@ -12,21 +12,14 @@ require_once('./admin.php');
$wp_list_table = get_list_table('plugins');
$wp_list_table->check_permissions();
if ( isset($_POST['clear-recent-list']) )
$action = 'clear-recent-list';
elseif ( !empty($_REQUEST['action']) )
$action = $_REQUEST['action'];
elseif ( !empty($_REQUEST['action2']) )
$action = $_REQUEST['action2'];
else
$action = false;
$action = $wp_list_table->current_action();
$plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '';
//Clean up request URI from temporary args for screen options/paging uri's to work as expected.
// Clean up request URI from temporary args for screen options/paging uri's to work as expected.
$_SERVER['REQUEST_URI'] = remove_query_arg(array('error', 'deleted', 'activate', 'activate-multi', 'deactivate', 'deactivate-multi', '_error_nonce'), $_SERVER['REQUEST_URI']);
if ( !empty($action) ) {
if ( $action ) {
$network_wide = false;
if ( ( isset( $_GET['networkwide'] ) || 'network-activate-selected' == $action ) && is_multisite() && current_user_can( 'manage_network_plugins' ) )
$network_wide = true;

View File

@ -13,73 +13,18 @@ $wp_list_table = get_list_table('media');
$wp_list_table->check_permissions();
// Handle bulk actions
if ( isset($_REQUEST['find_detached']) ) {
$doaction = $wp_list_table->current_action();
if ( $doaction ) {
check_admin_referer('bulk-media');
if ( !current_user_can('edit_posts') )
wp_die( __('You are not allowed to scan for lost attachments.') );
$lost = $wpdb->get_col( "
SELECT ID FROM $wpdb->posts
WHERE post_type = 'attachment' AND post_parent > '0'
AND post_parent NOT IN (
SELECT ID FROM $wpdb->posts
WHERE post_type NOT IN ( 'attachment', '" . join( "', '", get_post_types( array( 'public' => false ) ) ) . "' )
)
" );
$_REQUEST['detached'] = 1;
} elseif ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) ) {
check_admin_referer( 'bulk-media' );
$parent_id = (int) $_REQUEST['found_post_id'];
if ( !$parent_id )
return;
$parent = &get_post( $parent_id );
if ( !current_user_can( 'edit_post', $parent_id ) )
wp_die( __( 'You are not allowed to edit this post.' ) );
$attach = array();
foreach ( (array) $_REQUEST['media'] as $att_id ) {
$att_id = (int) $att_id;
if ( !current_user_can( 'edit_post', $att_id ) )
continue;
$attach[] = $att_id;
clean_attachment_cache( $att_id );
}
if ( ! empty( $attach ) ) {
$attach = implode( ',', $attach );
$attached = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $attach )", $parent_id ) );
}
if ( isset( $attached ) ) {
$location = 'upload.php';
if ( $referer = wp_get_referer() ) {
if ( false !== strpos( $referer, 'upload.php' ) )
$location = $referer;
}
$location = add_query_arg( array( 'attached' => $attached ) , $location );
wp_redirect( $location );
exit;
}
} elseif ( isset( $_REQUEST['doaction'] ) || isset( $_REQUEST['doaction2'] ) || isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
check_admin_referer( 'bulk-media' );
if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
if ( 'delete_all' == $doaction ) {
$post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
$doaction = 'delete';
} elseif ( ( $_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1 ) && ( isset( $_REQUEST['media'] ) || isset( $_REQUEST['ids'] ) ) ) {
$post_ids = isset( $_REQUEST['media'] ) ? $_REQUEST['media'] : explode( ',', $_REQUEST['ids'] );
$doaction = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2'];
} else {
wp_redirect( $_SERVER['HTTP_REFERER'] );
} elseif ( isset( $_REQUEST['media'] ) ) {
$post_ids = $_REQUEST['media'];
} elseif ( isset( $_REQUEST['ids'] ) ) {
$post_ids = explode( ',', $_REQUEST['ids'] );
}
$location = 'upload.php';
@ -89,6 +34,58 @@ if ( isset($_REQUEST['find_detached']) ) {
}
switch ( $doaction ) {
case 'find_detached':
if ( !current_user_can('edit_posts') )
wp_die( __('You are not allowed to scan for lost attachments.') );
$lost = $wpdb->get_col( "
SELECT ID FROM $wpdb->posts
WHERE post_type = 'attachment' AND post_parent > '0'
AND post_parent NOT IN (
SELECT ID FROM $wpdb->posts
WHERE post_type NOT IN ( 'attachment', '" . join( "', '", get_post_types( array( 'public' => false ) ) ) . "' )
)
" );
$_REQUEST['detached'] = 1;
break;
case 'attach':
$parent_id = (int) $_REQUEST['found_post_id'];
if ( !$parent_id )
return;
$parent = &get_post( $parent_id );
if ( !current_user_can( 'edit_post', $parent_id ) )
wp_die( __( 'You are not allowed to edit this post.' ) );
$attach = array();
foreach ( (array) $_REQUEST['media'] as $att_id ) {
$att_id = (int) $att_id;
if ( !current_user_can( 'edit_post', $att_id ) )
continue;
$attach[] = $att_id;
clean_attachment_cache( $att_id );
}
if ( ! empty( $attach ) ) {
$attach = implode( ',', $attach );
$attached = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $attach )", $parent_id ) );
}
if ( isset( $attached ) ) {
$location = 'upload.php';
if ( $referer = wp_get_referer() ) {
if ( false !== strpos( $referer, 'upload.php' ) )
$location = $referer;
}
$location = add_query_arg( array( 'attached' => $attached ) , $location );
wp_redirect( $location );
exit;
}
break;
case 'trash':
foreach ( (array) $post_ids as $post_id ) {
if ( !current_user_can( 'delete_post', $post_id ) )

View File

@ -29,15 +29,6 @@ add_contextual_help($current_screen,
'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
);
$update = $doaction = '';
if ( isset($_REQUEST['action']) )
$doaction = $_REQUEST['action'] ? $_REQUEST['action'] : $_REQUEST['action2'];
if ( "-1" == $doaction ) {
if ( isset($_REQUEST['changeit']) && !empty($_REQUEST['new_role']) )
$doaction = 'promote';
}
if ( empty($_REQUEST) ) {
$referer = '<input type="hidden" name="wp_http_referer" value="'. esc_attr(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
} elseif ( isset($_REQUEST['wp_http_referer']) ) {
@ -48,7 +39,9 @@ if ( empty($_REQUEST) ) {
$referer = '';
}
switch ($doaction) {
$update = '';
switch ( $wp_list_table->current_action() ) {
/* Bulk Dropdown menu Role changes */
case 'promote':