-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerm_Meta.php
More file actions
59 lines (54 loc) · 1019 Bytes
/
Copy pathTerm_Meta.php
File metadata and controls
59 lines (54 loc) · 1019 Bytes
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
<?php
/**
* The Term Meta class.
*
* @package Schedule_Terms
*/
namespace Torounit\WP\Schedule_Terms;
/**
* Term Meta class.
*/
class Term_Meta {
/**
* Term meta key.
*
* @var string
*/
private $meta_key;
/**
* The single instance of the class.
*
* @param string $meta_key The meta key.
*/
public function __construct( string $meta_key ) {
$this->meta_key = $meta_key;
add_action( 'init', array( $this, 'init' ), 100 );
}
/**
* Init.
*/
public function init() {
$this->register_term_meta( $this->meta_key );
}
/**
* Register Term meta.s
*
* @param string $meta_key The meta key.
*/
public function register_term_meta( string $meta_key ) {
foreach ( get_taxonomies() as $taxonomy ) {
register_term_meta(
$taxonomy,
$meta_key,
array(
'show_in_rest' => true,
'single' => true,
'type' => 'boolean',
'sanitize_callback' => function ( $value ) {
return (bool) $value;
},
)
);
}
}
}