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
d016d730
Commit
d016d730
authored
8 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Hide the "Empty Post" button when a purge is pending
parent
49f2e9b0
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
+42
-0
42 additions, 0 deletions
includes/class-delete-all.php
with
42 additions
and
0 deletions
includes/class-delete-all.php
+
42
−
0
View file @
d016d730
...
...
@@ -19,6 +19,11 @@ class Delete_All {
add_action
(
'admin_notices'
,
array
(
__CLASS__
,
'admin_notices'
)
);
add_filter
(
'posts_where'
,
array
(
__CLASS__
,
'hide_posts_pending_delete'
),
999
,
2
);
// Limit when caps are intercepted, given frequent execution of the `map_meta_cap` filter
add_action
(
'load-edit.php'
,
function
()
{
add_filter
(
'map_meta_cap'
,
array
(
__CLASS__
,
'hide_empty_trash_pending_delete'
),
10
,
2
);
}
);
}
/**
...
...
@@ -162,6 +167,43 @@ class Delete_All {
return
$where
;
}
/**
* Suppress "Empty Trash" button when purge is pending
*
* Core doesn't provide a filter specifically for this, but permissions are checked before showing the button
*
* @param array $caps User's capabilities
* @param string $cap Cap currently being checked
* @return array
*/
public
static
function
hide_empty_trash_pending_delete
(
$caps
,
$cap
)
{
// Button we're blocking only shows for the "trash" status, understandably
if
(
!
isset
(
$_REQUEST
[
'post_status'
]
)
||
'trash'
!==
$_REQUEST
[
'post_status'
]
)
{
return
$caps
;
}
// Get post type as Core envisions
$screen
=
get_current_screen
();
// Cap used to display button, per WP_Posts_List_Table::extra_tablenav()
$cap_to_block
=
get_post_type_object
(
$screen
->
post_type
)
->
cap
->
edit_others_posts
;
// The current cap isn't the one we're looking for
if
(
$cap
!==
$cap_to_block
)
{
return
$caps
;
}
// There isn't a pending purge, so one should be permitted
if
(
!
self
::
action_next_scheduled
(
self
::
CRON_EVENT
,
$screen
->
post_type
)
)
{
return
$caps
;
}
// Block the edit button by disallowing its cap
$caps
[]
=
'do_not_allow'
;
return
$caps
;
}
/**
* Find the next scheduled instance of a given action, regardless of arguments
*
...
...
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