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
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
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
08ed1473
Commit
08ed1473
authored
7 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Prepare for custom actions `handle_bulk_actions-{$screen_id}`
parent
61fdec99
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
includes/class-main.php
+27
-12
27 additions, 12 deletions
includes/class-main.php
with
27 additions
and
12 deletions
includes/class-main.php
+
27
−
12
View file @
08ed1473
...
@@ -32,6 +32,7 @@ class Main {
...
@@ -32,6 +32,7 @@ class Main {
public
static
function
load
()
{
public
static
function
load
()
{
add_action
(
self
::
CRON_EVENT
,
array
(
__CLASS__
,
'do_cron'
)
);
add_action
(
self
::
CRON_EVENT
,
array
(
__CLASS__
,
'do_cron'
)
);
// TODO: add for upload.php and edit-comments.php. Anything else?
add_action
(
'load-edit.php'
,
array
(
__CLASS__
,
'intercept'
)
);
add_action
(
'load-edit.php'
,
array
(
__CLASS__
,
'intercept'
)
);
add_action
(
'admin_notices'
,
array
(
__CLASS__
,
'admin_notices'
)
);
add_action
(
'admin_notices'
,
array
(
__CLASS__
,
'admin_notices'
)
);
...
@@ -62,13 +63,14 @@ class Main {
...
@@ -62,13 +63,14 @@ class Main {
$vars
=
self
::
capture_vars
();
$vars
=
self
::
capture_vars
();
$action
=
self
::
build_hook
(
$vars
->
action
);
$action
=
self
::
build_hook
(
$vars
->
action
);
if
(
!
self
::
bulk_action_allowed
(
$vars
->
action
)
)
{
// What kind of actions is this?
return
;
if
(
self
::
is_core_action
(
$vars
->
action
)
)
{
}
// Nothing to do, unless we're emptying the trash.
if
(
empty
(
$vars
->
posts
)
&&
'delete_all'
!==
$vars
->
action
)
{
// Nothing to do, unless we're emptying the trash.
self
::
do_admin_redirect
(
self
::
ADMIN_NOTICE_KEY
,
false
);
if
(
empty
(
$vars
->
posts
)
&&
'delete_all'
!==
$vars
->
action
)
{
}
self
::
do_admin_redirect
(
self
::
ADMIN_NOTICE_KEY
,
false
);
}
else
{
// Do something special to offload custom things?
}
}
// Pass request to a class to handle offloading to cron, UX, etc.
// Pass request to a class to handle offloading to cron, UX, etc.
...
@@ -99,11 +101,24 @@ class Main {
...
@@ -99,11 +101,24 @@ class Main {
* Capture relevant variables
* Capture relevant variables
*/
*/
private
static
function
capture_vars
()
{
private
static
function
capture_vars
()
{
$vars
=
array_merge
(
array
(
'action'
,
'user_id'
),
self
::
get_supported_vars
()
);
$vars
=
array
(
'action'
,
'user_id'
,
'current_screen'
);
// Extra data that normally would be available from the context.
$vars
=
array_merge
(
$vars
,
self
::
get_supported_vars
()
);
$vars
=
(
object
)
array_fill_keys
(
$vars
,
null
);
$vars
=
(
object
)
array_fill_keys
(
$vars
,
null
);
// All permissions checks must be re-implemented!
$vars
->
user_id
=
get_current_user_id
();
$vars
->
user_id
=
get_current_user_id
();
// Some dynamic hooks need screen data, but we don't need help and other private data.
// Fortunately, Core's private convention is used in the \WP_Screen class.
$screen
=
get_current_screen
();
$screen
=
get_object_vars
(
$screen
);
$screen
=
array_filter
(
$screen
,
function
(
$key
)
{
return
0
!==
strpos
(
$key
,
'_'
);
},
ARRAY_FILTER_USE_KEY
);
$vars
->
current_screen
=
(
object
)
$screen
;
unset
(
$screen
);
// Remainder of data comes from $_REQUEST
if
(
isset
(
$_REQUEST
[
'delete_all'
]
)
||
isset
(
$_REQUEST
[
'delete_all2'
]
)
)
{
if
(
isset
(
$_REQUEST
[
'delete_all'
]
)
||
isset
(
$_REQUEST
[
'delete_all2'
]
)
)
{
$vars
->
action
=
'delete_all'
;
$vars
->
action
=
'delete_all'
;
}
elseif
(
isset
(
$_REQUEST
[
'action'
]
)
&&
'-1'
!==
$_REQUEST
[
'action'
]
)
{
}
elseif
(
isset
(
$_REQUEST
[
'action'
]
)
&&
'-1'
!==
$_REQUEST
[
'action'
]
)
{
...
@@ -202,13 +217,13 @@ class Main {
...
@@ -202,13 +217,13 @@ class Main {
}
}
/**
/**
*
Validate
action
*
Is this one of Core's default actions, or a custom
action
*
*
* @param string $action Action parsed from request vars.
* @param string $action Action parsed from request vars.
* @return bool
* @return bool
*/
*/
public
static
function
bulk_action_allowed
(
$action
)
{
public
static
function
is_core_action
(
$action
)
{
$
allowed
_actions
=
array
(
$
core
_actions
=
array
(
'delete'
,
// class Delete_Permanently.
'delete'
,
// class Delete_Permanently.
'delete_all'
,
// class Delete_All.
'delete_all'
,
// class Delete_All.
'edit'
,
// class Edit.
'edit'
,
// class Edit.
...
@@ -216,7 +231,7 @@ class Main {
...
@@ -216,7 +231,7 @@ class Main {
'untrash'
,
// class Restore_From_Trash.
'untrash'
,
// class Restore_From_Trash.
);
);
return
in_array
(
$action
,
$
allowed
_actions
,
true
);
return
in_array
(
$action
,
$
core
_actions
,
true
);
}
}
/**
/**
...
...
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