Skip to content
Snippets Groups Projects
Commit 944c9c64 authored by Erick Hitter's avatar Erick Hitter
Browse files

Generalize redirect method as it'll be needed by other bulk processes

parent af942186
No related branches found
No related tags found
No related merge requests found
......@@ -30,14 +30,17 @@ class Delete_All {
* Handle a request to delete all trashed items for a given post type
*/
public static function process( $vars ) {
// Special keys are used to trigger this request, and we need to remove them on redirect
$extra_keys = array( 'delete_all', 'delete_all2', );
$action_scheduled = self::action_next_scheduled( self::CRON_EVENT, $vars->post_type );
if ( empty( $action_scheduled ) ) {
wp_schedule_single_event( time(), self::CRON_EVENT, array( $vars ) );
self::redirect( true );
Main::do_admin_redirect( self::ADMIN_NOTICE_KEY, true, $extra_keys );
} else {
self::redirect( false );
Main::do_admin_redirect( self::ADMIN_NOTICE_KEY, false, $extra_keys );
}
}
......@@ -92,25 +95,6 @@ class Delete_All {
}
}
/**
* Redirect, including a flag to indicate if the bulk process was scheduled successfully
*
* @param bool $succeeded Whether or not the bulk-delete was scheduled
*/
public static function redirect( $succeeded = false ) {
$redirect = wp_unslash( $_SERVER['REQUEST_URI'] );
// Remove arguments that could re-trigger this bulk-edit
$redirect = remove_query_arg( array( '_wp_http_referer', '_wpnonce', 'delete_all', 'delete_all2', ), $redirect );
// Add a flag for the admin notice
$redirect = add_query_arg( self::ADMIN_NOTICE_KEY, $succeeded ? 1 : -1, $redirect );
$redirect = esc_url_raw( $redirect );
wp_safe_redirect( $redirect );
exit;
}
/**
* Let the user know what's going on
*/
......
......@@ -154,6 +154,29 @@ class Main {
unset( $_REQUEST['delete_all'] );
unset( $_REQUEST['delete_all2'] );
}
/**
* Redirect, including a flag to indicate if the bulk process was scheduled successfully
*
* @param string $return_key Key to include in redirect URL to flag request's origin, use for admin feedback, etc.
* @param bool $succeeded Whether or not the bulk-delete was scheduled
* @param array $extra_keys Array of additional action keys to remove from redirect URL. Optional.
*/
public static function do_admin_redirect( $return_key, $succeeded = false, $extra_keys = array() ) {
$redirect = wp_unslash( $_SERVER['REQUEST_URI'] );
// Remove arguments that could re-trigger this bulk-edit
$action_keys = array( '_wp_http_referer', '_wpnonce', 'action', 'action2', );
$action_keys = array_merge( $action_keys, $extra_keys );
$redirect = remove_query_arg( $action_keys, $redirect );
// Add a flag for the admin notice
$redirect = add_query_arg( $return_key, $succeeded ? 1 : -1, $redirect );
$redirect = esc_url_raw( $redirect );
wp_safe_redirect( $redirect );
exit;
}
}
Main::load();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment