-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathacp-select-formatter-term_name.php
More file actions
57 lines (50 loc) · 1.47 KB
/
acp-select-formatter-term_name.php
File metadata and controls
57 lines (50 loc) · 1.47 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
<?php
/**
* This filter modifies the term label shown in select2 dropdown menus when selecting a term.
* For example, this select2 menu is used by inline editing and smart filtering for taxonomy
* columns such as "Categories" or "Tags".
* The default displayed value is the term name, prefixed with parent term names for hierarchical
* taxonomies (e.g. "Parent » Child").
*/
/**
* @param string $label The formatted term label. Default is the term name (with parent hierarchy for nested terms).
* @param WP_Term $term
*
* @return string
*/
function acp_select_formatter_term_name(string $label, WP_Term $term): string
{
// Modify label
// $label = $term->slug;
return $label;
}
add_filter('acp/select/formatter/term_name', 'acp_select_formatter_term_name', 10, 2);
/**
* Example: append the post count to each term label so editors can see
* how many posts are assigned to each term.
*
* e.g. "News (14)"
*/
add_filter(
'acp/select/formatter/term_name',
static function (string $label, WP_Term $term): string {
$label .= ' (' . $term->count . ')';
return $label;
},
10,
2
);
/**
* Example: show only the term's own name, without the parent hierarchy prefix,
* to keep the dropdown concise for deeply nested taxonomies.
*
* e.g. "Child" instead of "Parent » Child"
*/
add_filter(
'acp/select/formatter/term_name',
static function (string $label, WP_Term $term): string {
return $term->name;
},
10,
2
);