-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathacp-search-is_active.php
59 lines (47 loc) · 1.47 KB
/
acp-search-is_active.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* Hook to enable/disable smart filtering completely. Can easily be checked on specific list screen or other conditionals like User Roles
*/
/**
* Enable Smart Filtering for all list screens
*/
add_filter('acp/search/is_active', '__return_true');
/**
* Disable Smart Filtering for all list screens
*/
add_filter('acp/search/is_active', '__return_false');
/**
* Disable Smart Filtering for the media list table
*/
function acp_search_disable_for_media(bool $is_active, AC\ListScreen $list_screen): bool
{
if ('attachment' === $list_screen->get_post_type()) {
$is_active = false;
}
return $is_active;
}
add_filter('acp/search/is_active', 'acp_search_disable_for_media', 10, 2);
/**
* Disable Smart Filtering on a custom post type list table
*/
function acp_search_disable_for_custom_post_type(bool $is_active, AC\ListScreen $list_screen): bool
{
if ('my_custom_post_type' === $list_screen->get_post_type()) {
$is_active = false;
}
return $is_active;
}
add_filter('acp/search/is_active', 'acp_search_disable_for_custom_post_type', 10, 2);
/**
* Disable Smart Filtering for specific user roles
*/
function acp_search_disable_for_authors(bool $is_active): bool
{
$user = wp_get_current_user();
// Disable smart filter for users with the role 'author'
if (in_array('author', $user->roles, true)) {
$is_active = false;
}
return $is_active;
}
add_filter('acp/search/is_active', 'acp_search_disable_for_authors');