-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtemplate-functions-get-column.php
More file actions
64 lines (55 loc) · 2.26 KB
/
template-functions-get-column.php
File metadata and controls
64 lines (55 loc) · 2.26 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
59
60
61
62
63
64
<?php
/**
* Fetch a single column object
*/
function example_loaded_get_column()
{
/**
* @see https://docs.admincolumns.com/article/65-how-to-find-the-column-id
* The "Column Name" can be found by going to the column editor and clicking the three dots menu. Enable the "Column Info" by clicking the checkbox.
* The Column Name will now be visible for each column.
*/
$column_name = "<COLUMN NAME GOES HERE>"; // e.g. '5f2a7bb898468'
/**
* @see https://docs.admincolumns.com/article/66-how-to-find-the-list-screen-id
* TThe "List screen ID" can be found by going to the column editor and clicking the three dots menu. Enable the "Column Info" by clicking the checkbox.
* The list screen ID will now be visible.
*/
$list_screen_id = "<LIST SCREEN ID GOES HERE>"; // e.g. '5eeca96a61826'
/**
* @var AC\Column|null $column
* @see https://docs.admincolumns.com/article/53-class-ac-column
* The AC\Column object encapsulates all the information and functionality related to a single column in an
* admin list view. It defines how the column should be displayed, what data it should contain, and
* how it should behave.
*/
$column = ac_get_column($column_name, $list_screen_id);
}
add_action('wp_loaded', 'example_loaded_get_column');
/**
* Example usage of ac_get_column() function.
* @uses AC\Column
* @uses AC\ListScreen
* @uses AC\Column\Context
*/
function example_get_column()
{
$column = ac_get_column(
'5f2a7bb898468', // Column ID
'5eeca96a61826' // List screen ID
);
if ($column) {
/**
* @var AC\Column\Context $context
* @see https://docs.admincolumns.com/article/53-class-ac-column
*/
$context = $column->get_context();
echo $context->get_label(); // Output: My Title Label
echo $context->get_type_label(); // Output: Title
echo $context->get_type(); // Output: column-title
echo $context->get('width'); // Output: Width of the column in pixels or percentage
$options = $context->all(); // Output: All stored options for the column (e.g. width, label, image_size)
print_r($options);
}
}
add_action('wp_loaded', 'example_get_column');