-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtemplate-functions-get-list-screens.php
More file actions
58 lines (49 loc) · 2.13 KB
/
template-functions-get-list-screens.php
File metadata and controls
58 lines (49 loc) · 2.13 KB
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
<?php
/**
* Fetch all list screens for a particular list table.
*/
function example_loaded_ac_get_list_screens()
{
/**
* @see https://docs.admincolumns.com/article/66-how-to-find-the-list-screen-id
* The "List Screen Key" can be found by opening the screen options in the top-right corner of the
* admin columns settings page. Enable the "List screen Key" by clicking the checkbox next to it.
* The list screen Key will now be visible in the right sidebar.
*/
$table_id = "<TABLE ID GOES HERE>"; // e.g. page, post, wp-users, wp-comments, wp-media, wp-taxonomy_category etc.
$list_screens = ac_get_list_screens($table_id);
}
add_action('wp_loaded', 'example_loaded_ac_get_list_screens');
/**
* Example usage of ac_get_list_screens() function.
* @uses AC\Column
* @uses AC\ListScreen
*/
function example_ac_get_list_screens()
{
$list_screens = ac_get_list_screens('page');
foreach ($list_screens as $list_screen) {
/**
* @var $list_screen AC\ListScreen
*/
echo $list_screen->get_label(); // e.g. 'Posts', 'Users', 'Comments'
echo $list_screen->get_table_id(); // e.g. 'post', 'page', 'my-custom-post-type', 'wp-users', 'wp-comments'
echo $list_screen->get_meta_type(); // e.g. 'post', 'user' or 'comment
echo $list_screen->get_post_type(); // e.g. 'post', 'page' (if applicable)
echo $list_screen->get_title(); // USer defined label e.g. 'My list view', 'Another list view'
$columns = $list_screen->get_columns(); // array of column objects
foreach ($columns as $column) {
/**
* @var $column AC\Column
*/
echo $column->get_type(); // e.g. 'column-title', 'column-meta'
echo $column->get_label(); // e.g. 'Title', 'Author', 'Date'
/**
* @var AC\Column\Context $context
*/
echo $context->get_label(); // User defined label e.g. 'My Column Label'
echo $context->all(); // All stored column settings. e.g. 'width', 'label', 'image_size' etc.
}
}
}
add_action('wp_loaded', 'example_ac_get_list_screens');