This repository has been archived by the owner on Jul 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCustom_Taxonomy.php
81 lines (68 loc) · 1.7 KB
/
Custom_Taxonomy.php
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace OmniBuilder;
class Custom_Taxonomy {
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $singular;
/**
* @var string
*/
private $plural;
/**
* @var Custom_Post_Type
*/
private $post_type;
/**
* @var array
*/
private $args;
/**
* @param string $name
* @param Custom_Post_Type $post_type
* @param array $args
*/
public function __construct( $name, Custom_Post_Type $post_type, array $args = array() ) {
$this->name = \Inflector::underscore( $name );
$this->plural = \Inflector::titleize($this->name);
$this->singular = \Inflector::singularize($this->plural);
$this->post_type = $post_type;
$this->args = $args;
if ( ! isset( $this->args['labels'] ) ) {
$this->args['labels'] = array(
'name' => __( $this->plural ),
'singular_name' => __( $this->singular ),
'search_items' => __( 'Search ' . $this->plural ),
'all_items' => __( 'All ' . $this->plural ),
'parent_item' => __( 'Parent ' . $this->singular ),
'parent_item_colon' => __( 'Parent ' . $this->singular ),
'edit_item' => __( 'Edit ' . $this->singular ),
'update_item' => __( 'Update ' . $this->singular ),
'add_new_item' => __( 'Add New ' . $this->singular ),
'new_item_name' => __( 'New ' . $this->singular . ' Name' ),
'menu_name' => __( $this->plural )
);
}
$this->subscribe();
}
/**
* @return void
*/
public function register_taxonomy() {
register_taxonomy(
$this->name,
$this->post_type->get_name(),
$this->args
);
}
/**
* @return void
*/
protected function subscribe() {
add_action( 'init', array( &$this, 'register_taxonomy' ) );
}
}