-
Notifications
You must be signed in to change notification settings - Fork 5
/
acp-search-is_active.php
74 lines (62 loc) · 1.8 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?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
*
* @param bool $is_active
* @param AC\ListScreen $list_screen
*
* @return bool
*/
function acp_search_disable_for_media($is_active, AC\ListScreen $list_screen)
{
if ($list_screen instanceof ACP\ListScreen\Media) {
$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
*
* @param bool $is_active
* @param AC\ListScreen $list_screen
*
* @return bool
*/
function acp_search_disable_for_custom_post_type($is_active, AC\ListScreen $list_screen)
{
// The following condition does the same: $list_screen->get_key() === 'my_custom_post_type'
if ($list_screen instanceof AC\ListScreenPost && '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
*
* @param bool $is_active
*
* @return bool
*/
function acp_search_disable_for_authors($is_active)
{
$user = wp_get_current_user();
// Disable smart filter for users with the role 'author'
if (in_array('author', (array)$user->roles)) {
$is_active = false;
}
return $is_active;
}
add_filter('acp/search/is_active', 'acp_search_disable_for_authors');