-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathacp-select-formatter-post_title.php
More file actions
64 lines (55 loc) · 1.63 KB
/
acp-select-formatter-post_title.php
File metadata and controls
64 lines (55 loc) · 1.63 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
/**
* This filter modifies the post label shown in select2 dropdown menus when selecting a post.
* For example, this select2 menu is used by inline editing and smart filtering for relational
* columns such as "Parent Page" or custom post-relationship fields.
* The default displayed value is the post title.
*/
/**
* @param string $label The formatted post label. Default is the post title.
* @param WP_Post $post
*
* @return string
*/
function acp_select_formatter_post_title(string $label, WP_Post $post): string
{
// Modify label
// $label = $post->post_name;
return $label;
}
add_filter('acp/select/formatter/post_title', 'acp_select_formatter_post_title', 10, 2);
/**
* Example: append the post status to the label so editors can distinguish
* draft and published posts in the dropdown.
*
* e.g. "My Page [draft]"
*/
add_filter(
'acp/select/formatter/post_title',
static function (string $label, WP_Post $post): string {
if ($post->post_status !== 'publish') {
$label .= ' [' . $post->post_status . ']';
}
return $label;
},
10,
2
);
/**
* Example: prefix the post type label for sites where multiple post types
* appear in the same dropdown.
*
* e.g. "Product: Blue T-Shirt"
*/
add_filter(
'acp/select/formatter/post_title',
static function (string $label, WP_Post $post): string {
$post_type_object = get_post_type_object($post->post_type);
if ($post_type_object && $post_type_object->name !== 'post') {
$label = $post_type_object->labels->singular_name . ': ' . $label;
}
return $label;
},
10,
2
);