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

Simplify how bulk actions are intercepted by using hooks from subclasses

parent 2bece6e9
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ class Delete_All {
* Register this bulk process' hooks
*/
public static function register_hooks() {
add_action( Main::build_hook( 'delete_all' ), array( __CLASS__, 'process' ) );
add_action( self::CRON_EVENT, array( __CLASS__, 'process_via_cron' ) );
add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) );
......
......@@ -3,6 +3,11 @@
namespace Automattic\WP\Bulk_Edit_Cron_Offload;
class Main {
/**
* Prefix for bulk-process hook invoked by request-specific classes
*/
const ACTION = 'a8c_bulk_edit_cron_';
/**
* Register action
*/
......@@ -23,39 +28,19 @@ class Main {
check_admin_referer( 'bulk-posts' );
// Parse request to determine what to do
$vars = self::capture_vars();
// Now what?
switch ( $vars->action ) {
case 'delete_all' :
self::skip_core_processing();
Delete_All::process( $vars );
break;
$vars = self::capture_vars();
$action = self::build_hook( $vars->action );
case 'trash' :
return;
break;
case 'untrash' :
return;
break;
case 'delete' :
return;
break;
case 'edit' :
return;
break;
if ( ! self::bulk_action_allowed( $vars->action ) ) {
return;
}
// Should only arrive here if loaded on the wrong admin screen
default :
error_log( var_export( get_current_screen(), true ) );
error_log( var_export( wp_debug_backtrace_summary( __CLASS__, null, false ), true ) );
// Pass request to a class to handle offloading to cron, UX, etc
do_action( $action, $vars );
return;
break;
// Only skip Core's default handling when
if ( has_action( $action ) ) {
self::skip_core_processing();
}
}
......@@ -132,6 +117,34 @@ class Main {
return $vars;
}
/**
* Validate action
*
* @param string $action Action parsed from request vars
* @return bool
*/
public static function bulk_action_allowed( $action ) {
$allowed_actions = array(
'delete',
'delete_all',
'edit',
'trash',
'untrash',
);
return in_array( $action, $allowed_actions, true );
}
/**
* Build a WP hook specific to a bulk request
*
* @param string $action Bulk action to offload
* @return string
*/
public static function build_hook( $action ) {
return self::ACTION . $action;
}
/**
* Unset flags Core uses to trigger bulk processing
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment