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
79f33fd2
Commit
79f33fd2
authored
7 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Switch to one cron event for all
parent
f534e293
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
includes/class-delete-all.php
+8
-11
8 additions, 11 deletions
includes/class-delete-all.php
includes/class-main.php
+29
-4
29 additions, 4 deletions
includes/class-main.php
includes/class-move-to-trash.php
+2
-2
2 additions, 2 deletions
includes/class-move-to-trash.php
with
39 additions
and
17 deletions
includes/class-delete-all.php
+
8
−
11
View file @
79f33fd2
...
...
@@ -14,8 +14,6 @@ class Delete_All {
/**
* Class constants
*/
const
CRON_EVENT
=
'bulk_edit_cron_offload_delete_all'
;
const
ADMIN_NOTICE_KEY
=
'bulk_edit_cron_offload_deleted_all'
;
/**
...
...
@@ -23,7 +21,7 @@ class Delete_All {
*/
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
(
Main
::
build_cron_hook
(
'delete_all'
)
,
array
(
__CLASS__
,
'process_via_cron'
)
);
add_action
(
'admin_notices'
,
array
(
__CLASS__
,
'admin_notices'
)
);
add_filter
(
'posts_where'
,
array
(
__CLASS__
,
'hide_posts_pending_delete'
),
999
,
2
);
...
...
@@ -43,10 +41,10 @@ class Delete_All {
// 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
);
$action_scheduled
=
self
::
action_next_scheduled
(
$vars
->
post_type
);
if
(
empty
(
$action_scheduled
)
)
{
Main
::
schedule_processing
(
self
::
CRON_EVENT
,
$vars
);
Main
::
schedule_processing
(
$vars
);
Main
::
do_admin_redirect
(
self
::
ADMIN_NOTICE_KEY
,
true
,
$extra_keys
);
}
else
{
Main
::
do_admin_redirect
(
self
::
ADMIN_NOTICE_KEY
,
false
,
$extra_keys
);
...
...
@@ -123,7 +121,7 @@ class Delete_All {
$message
=
__
(
'A request to empty the trash is already pending for this post type.'
,
'bulk-edit-cron-offload'
);
}
}
elseif
(
'edit'
===
$screen
->
base
&&
isset
(
$_REQUEST
[
'post_status'
]
)
&&
'trash'
===
$_REQUEST
[
'post_status'
]
)
{
if
(
self
::
action_next_scheduled
(
self
::
CRON_EVENT
,
$screen
->
post_type
)
)
{
if
(
self
::
action_next_scheduled
(
$screen
->
post_type
)
)
{
$class
=
'notice-warning'
;
$message
=
__
(
'A pending request to empty the trash will be processed soon.'
,
'bulk-edit-cron-offload'
);
}
...
...
@@ -161,7 +159,7 @@ class Delete_All {
return
$where
;
}
if
(
self
::
action_next_scheduled
(
self
::
CRON_EVENT
,
$q
->
get
(
'post_type'
)
)
)
{
if
(
self
::
action_next_scheduled
(
$q
->
get
(
'post_type'
)
)
)
{
$where
.
=
' AND 0=1'
;
}
...
...
@@ -195,7 +193,7 @@ class Delete_All {
}
// There isn't a pending purge, so one should be permitted.
if
(
!
self
::
action_next_scheduled
(
self
::
CRON_EVENT
,
$screen
->
post_type
)
)
{
if
(
!
self
::
action_next_scheduled
(
$screen
->
post_type
)
)
{
return
$caps
;
}
...
...
@@ -208,11 +206,10 @@ class Delete_All {
/**
* Find the next scheduled instance of a given action, regardless of arguments
*
* @param string $action_to_check Hook to search for.
* @param string $post_type Post type hook is scheduled for.
* @return array
*/
private
static
function
action_next_scheduled
(
$action_to_check
,
$post_type
)
{
private
static
function
action_next_scheduled
(
$post_type
)
{
$events
=
get_option
(
'cron'
);
if
(
!
is_array
(
$events
)
)
{
...
...
@@ -226,7 +223,7 @@ class Delete_All {
}
foreach
(
$timestamp_events
as
$action
=>
$action_instances
)
{
if
(
$action
!==
$action
_to_check
)
{
if
(
Main
::
CRON_EVENT
!==
$action
)
{
continue
;
}
...
...
This diff is collapsed.
Click to expand it.
includes/class-main.php
+
29
−
4
View file @
79f33fd2
...
...
@@ -17,12 +17,28 @@ class Main {
const
ACTION
=
'a8c_bulk_edit_cron_'
;
/**
* Register action
* Common cron action
*/
const
CRON_EVENT
=
'bulk_edit_cron_offload'
;
/**
* Register actions
*/
public
static
function
load
()
{
add_action
(
self
::
CRON_EVENT
,
array
(
__CLASS__
,
'do_cron'
)
);
add_action
(
'load-edit.php'
,
array
(
__CLASS__
,
'intercept'
)
);
}
/**
* Run appropriate cron callback
*
* @param object $vars Bulk-request variables.
*/
public
static
function
do_cron
(
$vars
)
{
do_action
(
self
::
build_cron_hook
(
$vars
->
action
),
$vars
);
}
/**
* Call appropriate handler
*/
...
...
@@ -152,6 +168,16 @@ class Main {
return
self
::
ACTION
.
$action
;
}
/**
* Build a cron hook specific to a bulk request
*
* @param string $action Bulk action to register cron callback for.
* @return string
*/
public
static
function
build_cron_hook
(
$action
)
{
return
self
::
ACTION
.
$action
.
'_callback'
;
}
/**
* Unset flags Core uses to trigger bulk processing
*/
...
...
@@ -188,12 +214,11 @@ class Main {
/**
* Create cron event
*
* @param string $event Cron action.
* @param object $vars Bulk-request variables.
* @return bool
*/
public
static
function
schedule_processing
(
$event
,
$vars
)
{
return
false
!==
wp_schedule_single_event
(
time
(),
$event
,
array
(
$vars
)
);
public
static
function
schedule_processing
(
$vars
)
{
return
false
!==
wp_schedule_single_event
(
time
(),
self
::
CRON_EVENT
,
array
(
$vars
)
);
}
}
...
...
This diff is collapsed.
Click to expand it.
includes/class-move-to-trash.php
+
2
−
2
View file @
79f33fd2
...
...
@@ -21,7 +21,7 @@ class Move_To_Trash {
*/
public
static
function
register_hooks
()
{
add_action
(
Main
::
build_hook
(
'trash'
),
array
(
__CLASS__
,
'process'
)
);
add_action
(
self
::
CRON_EVENT
,
array
(
__CLASS__
,
'process_via_cron'
)
);
add_action
(
Main
::
build_cron_hook
(
'trash'
)
,
array
(
__CLASS__
,
'process_via_cron'
)
);
}
/**
...
...
@@ -30,7 +30,7 @@ class Move_To_Trash {
* @param object $vars Bulk-request variables.
*/
public
static
function
process
(
$vars
)
{
Main
::
schedule_processing
(
self
::
CRON_EVENT
,
$vars
);
Main
::
schedule_processing
(
$vars
);
Main
::
do_admin_redirect
(
self
::
ADMIN_NOTICE_KEY
,
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