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
2bece6e9
Commit
2bece6e9
authored
8 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Better organization
parent
c4459c61
No related branches found
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-delete-all.php
+55
-55
55 additions, 55 deletions
includes/class-delete-all.php
with
55 additions
and
55 deletions
includes/class-delete-all.php
+
55
−
55
View file @
2bece6e9
...
...
@@ -16,8 +16,8 @@ class Delete_All {
public
static
function
register_hooks
()
{
add_action
(
self
::
CRON_EVENT
,
array
(
__CLASS__
,
'process_via_cron'
)
);
add_filter
(
'posts_where'
,
array
(
__CLASS__
,
'hide_posts_pending_delete'
),
999
,
2
);
add_action
(
'admin_notices'
,
array
(
__CLASS__
,
'admin_notices'
)
);
add_filter
(
'posts_where'
,
array
(
__CLASS__
,
'hide_posts_pending_delete'
),
999
,
2
);
}
/**
...
...
@@ -35,45 +35,6 @@ 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
)
{
$events
=
get_option
(
'cron'
);
if
(
!
is_array
(
$events
)
)
{
return
array
();
}
foreach
(
$events
as
$timestamp
=>
$timestamp_events
)
{
// Skip non-event data that Core includes in the option
if
(
!
is_numeric
(
$timestamp
)
)
{
continue
;
}
foreach
(
$timestamp_events
as
$action
=>
$action_instances
)
{
if
(
$action
!==
$action_to_check
)
{
continue
;
}
foreach
(
$action_instances
as
$instance
=>
$instance_args
)
{
$vars
=
array_shift
(
$instance_args
[
'args'
]
);
if
(
$post_type
===
$vars
->
post_type
)
{
return
array
(
'timestamp'
=>
$timestamp
,
'args'
=>
$vars
,
);
}
}
}
}
// No matching event found
return
array
();
}
/**
* Cron callback to delete trashed items in a given post type
*/
...
...
@@ -143,6 +104,29 @@ class Delete_All {
exit
;
}
/**
* Let the user know what's going on
*/
public
static
function
admin_notices
()
{
if
(
!
isset
(
$_REQUEST
[
self
::
ADMIN_NOTICE_KEY
]
)
)
{
return
;
}
if
(
1
===
(
int
)
$_REQUEST
[
self
::
ADMIN_NOTICE_KEY
]
)
{
$class
=
'notice-success'
;
$message
=
__
(
'Success! The trash will be emptied soon.'
,
'automattic-bulk-edit-cron-offload'
);
}
else
{
$class
=
'notice-error'
;
$message
=
__
(
'A request to empty the trash is already pending for this post type.'
,
'automattic-bulk-edit-cron-offload'
);
}
?>
<div
class=
"notice
<?php
echo
esc_attr
(
$class
);
?>
"
>
<p>
<?php
echo
esc_html
(
$message
);
?>
</p>
</div>
<?php
}
/**
* When a delete is pending for a given post type, hide those posts in the admin
*/
...
...
@@ -167,26 +151,42 @@ class Delete_All {
}
/**
* Let the user know what's going on
* 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
*/
public
static
function
admin_notices
()
{
if
(
!
isset
(
$_REQUEST
[
self
::
ADMIN_NOTICE_KEY
]
)
)
{
return
;
private
static
function
action_next_scheduled
(
$action_to_check
,
$post_type
)
{
$events
=
get_option
(
'cron'
);
if
(
!
is_array
(
$events
)
)
{
return
array
();
}
if
(
1
===
(
int
)
$_REQUEST
[
self
::
ADMIN_NOTICE_KEY
]
)
{
$class
=
'notice-success'
;
$message
=
__
(
'Success! The trash will be emptied soon.'
,
'automattic-bulk-edit-cron-offload'
);
}
else
{
$class
=
'notice-error'
;
$message
=
__
(
'A request to empty the trash is already pending for this post type.'
,
'automattic-bulk-edit-cron-offload'
);
foreach
(
$events
as
$timestamp
=>
$timestamp_events
)
{
// Skip non-event data that Core includes in the option
if
(
!
is_numeric
(
$timestamp
)
)
{
continue
;
}
foreach
(
$timestamp_events
as
$action
=>
$action_instances
)
{
if
(
$action
!==
$action_to_check
)
{
continue
;
}
foreach
(
$action_instances
as
$instance
=>
$instance_args
)
{
$vars
=
array_shift
(
$instance_args
[
'args'
]
);
if
(
$post_type
===
$vars
->
post_type
)
{
return
array
(
'timestamp'
=>
$timestamp
,
'args'
=>
$vars
,
);
}
}
}
}
?>
<div
class=
"notice
<?php
echo
esc_attr
(
$class
);
?>
"
>
<p>
<?php
echo
esc_html
(
$message
);
?>
</p>
</div>
<?php
// No matching event found
return
array
();
}
}
...
...
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