1
|
|
|
<?php |
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Custom post type class |
6
|
|
|
* |
7
|
|
|
* @author Nirjhar Lo |
8
|
|
|
* @package wp-plugin-framework |
9
|
|
|
*/ |
10
|
|
|
if ( ! class_exists( 'PLUGIN_CPT' ) ) { |
11
|
|
|
|
12
|
|
|
class PLUGIN_CPT { |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var Array |
16
|
|
|
*/ |
17
|
|
|
private $labels; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var Array |
21
|
|
|
*/ |
22
|
|
|
private $args; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var String |
26
|
|
|
*/ |
27
|
|
|
private static $menu_svg = ''; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Integrate the shortcode |
32
|
|
|
* |
33
|
|
|
* @return Void |
34
|
|
|
*/ |
35
|
|
|
public function __construct() { |
36
|
|
|
|
37
|
|
|
$this->labels = $this->labels(); |
38
|
|
|
$this->args = $this->args( $this->labels ); |
39
|
|
|
|
40
|
|
|
$this->taxonomy_labels = $this->taxonomy_labels(); |
|
|
|
|
41
|
|
|
$this->taxonomy_args = $this->taxonomy_args( $this->taxonomy_labels ); |
|
|
|
|
42
|
|
|
|
43
|
|
|
//register_post_type( 'cpt_name', $this->args ); |
44
|
|
|
//add_filter( 'post_updated_messages', array( $this, 'group_updated_messages' ) ); |
45
|
|
|
|
46
|
|
|
//register_taxonomy( 'custom_tax', array( 'cpt_name' ), $this->taxonomy_args ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Define the labels |
52
|
|
|
* |
53
|
|
|
* @return Array |
54
|
|
|
*/ |
55
|
|
|
public function labels() { |
56
|
|
|
|
57
|
|
|
$labels = array( |
58
|
|
|
'name' => _x( '', 'Post Type General Name', 'textdomain' ), |
|
|
|
|
59
|
|
|
'singular_name' => _x( '', 'Post Type Singular Name', 'textdomain' ), |
60
|
|
|
'menu_name' => __( '', 'textdomain' ), |
|
|
|
|
61
|
|
|
'parent_item_colon' => __( '', 'textdomain' ), |
62
|
|
|
'all_items' => __( '', 'textdomain' ), |
63
|
|
|
'view_item' => __( '', 'textdomain' ), |
64
|
|
|
'add_new_item' => __( '', 'textdomain' ), |
65
|
|
|
'add_new' => __( '', 'textdomain' ), |
66
|
|
|
'edit_item' => __( '', 'textdomain' ), |
67
|
|
|
'update_item' => __( '', 'textdomain' ), |
68
|
|
|
'search_items' => __( '', 'textdomain' ), |
69
|
|
|
'not_found' => __( '', 'textdomain' ), |
70
|
|
|
'not_found_in_trash' => __( '', 'textdomain' ), |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
return $labels; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Define the arguments for custom post type |
79
|
|
|
* |
80
|
|
|
* @param Array $labels |
81
|
|
|
* |
82
|
|
|
* @return Array |
83
|
|
|
*/ |
84
|
|
|
public function args( $labels ) { |
85
|
|
|
|
86
|
|
|
$args = array( |
87
|
|
|
'label' => __( '', 'textdomain' ), |
|
|
|
|
88
|
|
|
'description' => __( '', 'textdomain' ), |
89
|
|
|
'labels' => $labels, |
90
|
|
|
'supports' => array( 'title', 'editor', 'thumbnail' ), |
91
|
|
|
'taxonomies' => array( 'custom_tax', 'post_tag' ), |
92
|
|
|
'hierarchical' => true, |
93
|
|
|
'public' => true, |
94
|
|
|
'rewrite' => array( 'slug' => 'slug_name' ), |
95
|
|
|
'show_ui' => true, |
96
|
|
|
'show_in_menu' => true, |
97
|
|
|
'menu_icon' => 'data:image/svg+xml;base64,' . self::$menu_svg, |
98
|
|
|
'show_in_nav_menus' => true, |
99
|
|
|
'show_in_admin_bar' => true, |
100
|
|
|
'menu_position' => 5, |
101
|
|
|
'can_export' => true, |
102
|
|
|
'has_archive' => true, |
103
|
|
|
'exclude_from_search' => false, |
104
|
|
|
'publicly_queryable' => true, |
105
|
|
|
'capability_type' => 'post', |
106
|
|
|
'show_in_rest' => true, |
107
|
|
|
//Controls WP REST API behaviour |
108
|
|
|
'rest_controller_class' => 'WP_REST_Posts_Controller', |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
return $args; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Modify the cpt messages |
117
|
|
|
* |
118
|
|
|
* @param Array $messages |
119
|
|
|
* |
120
|
|
|
* @return Array |
121
|
|
|
*/ |
122
|
|
|
public function cpt_updated_messages( $messages ) { |
123
|
|
|
|
124
|
|
|
global $post, $post_ID; |
125
|
|
|
|
126
|
|
|
$messages['cpt_name'] = array( |
127
|
|
|
0 => '', |
128
|
|
|
1 => sprintf( __( 'CPT updated. <a href="%s">View CPT</a>', 'textdomain' ), esc_url( get_permalink( $post_ID ) ) ), |
|
|
|
|
129
|
|
|
2 => __( 'field updated.', 'textdomain' ), |
130
|
|
|
3 => __( 'field deleted.', 'textdomain' ), |
131
|
|
|
4 => __( 'CPT updated.', 'textdomain' ), |
132
|
|
|
5 => ( isset( $_GET['revision'] ) ? sprintf( __( 'CPT restored to revision from %s', 'textdomain' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false ), |
|
|
|
|
133
|
|
|
6 => sprintf( __( 'CPT published. <a href="%s">View Cpt</a>', 'textdomain' ), esc_url( get_permalink( $post_ID ) ) ), |
134
|
|
|
7 => __( 'CPT saved.', 'textdomain' ), |
135
|
|
|
8 => sprintf( __( 'CPT submitted. <a target="_blank" href="%s">Preview cpt</a>', 'textdomain' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), |
|
|
|
|
136
|
|
|
9 => sprintf( __( 'CPT scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview cpt</a>', 'textdomain' ), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ) ), |
|
|
|
|
137
|
|
|
10 => sprintf( __( 'CPT draft updated. <a target="_blank" href="%s">Preview cpt</a>', 'textdomain' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), |
138
|
|
|
); |
139
|
|
|
|
140
|
|
|
return $messages; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Taxonomy labels |
146
|
|
|
* |
147
|
|
|
* @return Array |
148
|
|
|
*/ |
149
|
|
|
public function taxonomy_labels() { |
150
|
|
|
|
151
|
|
|
$labels = array( |
152
|
|
|
'name' => _x( 'Taxonomy', 'taxonomy general name', 'textdomain' ), |
|
|
|
|
153
|
|
|
'singular_name' => _x( 'Taxonomy', 'taxonomy singular name', 'textdomain' ), |
154
|
|
|
'search_items' => __( 'Search Taxonomy', 'textdomain' ), |
|
|
|
|
155
|
|
|
'all_items' => __( 'All Taxonomies', 'textdomain' ), |
156
|
|
|
'parent_item' => __( 'Parent Taxonomy', 'textdomain' ), |
157
|
|
|
'parent_item_colon' => __( 'Parent Taxonomy:', 'textdomain' ), |
158
|
|
|
'edit_item' => __( 'Edit Taxonomy', 'textdomain' ), |
159
|
|
|
'update_item' => __( 'Update Taxonomy', 'textdomain' ), |
160
|
|
|
'add_new_item' => __( 'Add New Taxonomy', 'textdomain' ), |
161
|
|
|
'new_item_name' => __( 'New Taxonomy Name', 'textdomain' ), |
162
|
|
|
'menu_name' => __( 'Taxonomy', 'textdomain' ), |
163
|
|
|
); |
164
|
|
|
|
165
|
|
|
return $labels; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Define the arguments for custom taxonomy |
171
|
|
|
* |
172
|
|
|
* @param Array $labels |
173
|
|
|
* |
174
|
|
|
* @return Array |
175
|
|
|
*/ |
176
|
|
|
public function taxonomy_args( $labels ) { |
177
|
|
|
|
178
|
|
|
$args = array( |
179
|
|
|
'hierarchical' => true, |
180
|
|
|
'labels' => $labels, |
181
|
|
|
'show_ui' => true, |
182
|
|
|
'show_admin_column' => true, |
183
|
|
|
'query_var' => true, |
184
|
|
|
'rewrite' => array( 'slug' => 'custom_tax' ), |
185
|
|
|
'show_in_rest' => true, |
186
|
|
|
'rest_base' => 'custom_tax', |
187
|
|
|
//Controls WP REST API behaviour |
188
|
|
|
'rest_controller_class' => 'WP_REST_Terms_Controller', |
189
|
|
|
); |
190
|
|
|
|
191
|
|
|
return $args; |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
|