-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-custom-post-type.php
More file actions
89 lines (73 loc) · 3.26 KB
/
Copy pathclass-custom-post-type.php
File metadata and controls
89 lines (73 loc) · 3.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
if ( ! class_exists( 'Helios_Register_Custom_Post_Type' ) ) :
class Helios_Register_Custom_Post_Type {
private $data;
public function __construct( $cpt_data ) {
$this->data = $cpt_data;
$this::add_custom_post();
if ( isset( $cpt_data->taxonomies ) )
$this::add_taxonomy();
}
public function add_custom_post() {
$data = $this->data;
$name = $data->labels['name'];
$singular = $data->labels['singular'];
$plural = $data->labels['plural'];
$labels = array(
'name' => $name,
'singular_name' => $singular,
'add_new' => 'Add New',
'add_new_item' => sprintf( 'Add New %s', $singular ),
'edit_item' => sprintf( 'Edit %s', $singular ),
'new_item' => sprintf( 'New %s', $singular ),
'all_items' => sprintf( 'All %s', $plural ),
'view_item' => sprintf( 'View %s', $singular ),
'search_items' => sprintf( 'Search %s', $plural ),
'not_found' => sprintf( 'No %s found', $plural ),
'not_found_in_trash' => sprintf( 'No %ss found in the Trash', $plural ),
'parent_item_colon' => '',
'menu_name' => $name
);
$args = array(
'labels' => $labels,
'description' => $data->description,
'public' => ! isset( $data->public ) ? true : $data->public,
'menu_position' => isset( $data->position ) ? $data->position : null,
'menu_icon' => isset( $data->menu_icon ) ? $data->menu_icon : null,
'supports' => $data->supports,
'has_archive' => ! isset( $data->archive ) ? true : $data->archive,
'taxonomies' => isset( $data->tax ) ? $data->tax : array(),
'publicly_queryable' => isset( $data->publicly_queryable ) ? $data->publicly_queryable : true,
'show_in_rest' => isset( $data->show_in_rest ) ? $data->show_in_rest : true
);
register_post_type( $data->id, $args );
}
public function add_taxonomy() {
$data = $this->data;
foreach( $data->taxonomies as $tax ) {
$name = $tax->name;
$singular = $tax->singular;
$plural = $tax->plural;
$labels = array(
'name' => $name,
'singular_name' => $singular,
'search_items' => sprintf( 'Search %s', $plural ),
'all_items' => sprintf( 'All %s', $plural ),
'parent_item' => sprintf( 'Parent %s', $singular ),
'parent_item_colon' => sprintf( 'Parent %s:', $singular ),
'edit_item' => sprintf( 'Edit %s', $singular ),
'update_item' => sprintf( 'Update %s', $singular ),
'add_new_item' => sprintf( 'Add New %s', $singular ),
'new_item_name' => sprintf( 'New %s', $singular ),
'menu_name' => sprintf( '%s', $plural ),
);
$args = array(
'labels' => $labels,
'hierarchical' => ! isset( $tax->hierarchical ) ? true : $tax->hierarchical,
'show_admin_column' => ! isset( $tax->admin_column ) ? true : $tax->admin_column
);
register_taxonomy( $tax->id, $data->id, $args );
}
}
}
endif;