Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Bulk Actions Cron Offload
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
WP Plugins
Bulk Actions Cron Offload
Commits
49ba1f03
Commit
49ba1f03
authored
8 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
includes/class-delete-all.php
+1
-0
1 addition, 0 deletions
includes/class-delete-all.php
includes/class-main.php
+43
-30
43 additions, 30 deletions
includes/class-main.php
with
44 additions
and
30 deletions
includes/class-delete-all.php
+
1
−
0
View file @
49ba1f03
...
...
@@ -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'
)
);
...
...
This diff is collapsed.
Click to expand it.
includes/class-main.php
+
43
−
30
View file @
49ba1f03
...
...
@@ -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
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment