forked from codepress/admin-columns-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacp-horizontal_scrolling-enable.php
64 lines (52 loc) · 1.72 KB
/
acp-horizontal_scrolling-enable.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
<?php
/**
* This hooks allows you to enable or disable the Horizontal Scrolling feature per list screen
*/
/**
* @param bool $enabled
* @param AC\ListScreen $list_screen
*
* @return bool
*/
function acp_horizontal_scrolling_enable( $enabled, AC\ListScreen $list_screen ) {
return $enabled;
}
add_filter( 'acp/horizontal_scrolling/enable', 'acp_horizontal_scrolling_enable', 10, 2 );
// Anonymous function
add_filter( 'acp/horizontal_scrolling/enable', function ( $enabled, AC\ListScreen $list_screen ) {
return $enabled;
}, 10, 2 );
/**
* Enabled horizontal scrolling for every admin for every list screen
*/
add_filter( 'acp/horizontal_scrolling/enable', function () {
$user = wp_get_current_user();
return $user && ! $user->has_cap( 'manage_admin_columns' );
}, 10 );
/**
* Enabled horizontal scrolling for every list screen with more than 10 columns
*/
add_filter( 'acp/horizontal_scrolling/enable', function ( $enabled, AC\ListScreen $list_screen ) {
if ( count( $list_screen->get_columns() ) > 10 ) {
$enabled = true;
}
return $enabled;
}, 10, 2 );
/**
* Set horizontal scrolling based on different ListScreen properties
*/
add_filter( 'acp/horizontal_scrolling/enable', function ( $enabled, AC\ListScreen $list_screen ) {
// Check for specific post type
if ( $list_screen instanceof AC\ListScreen\Post && 'page' === $list_screen->get_post_type() ) {
$enabled = false;
}
// Check for specific ListScreen ID
if ( $list_screen->has_id() && $list_screen->get_id()->equals( new AC\Type\ListScreenId( '620f70285d50d' ) ) ) {
$enabled = false;
}
// The above check equals the following example
if ( '620f70285d50d' === $list_screen->get_layout_id() ) {
$enabled = false;
}
return $enabled;
}, 10, 2 );