@@ -59,6 +59,7 @@ abstract class Post_Type {
59
59
60
60
const SUPPORTS_TITLE = 'title ' ;
61
61
const SUPPORTS_EDITOR = 'editor ' ;
62
+ const SUPPORTS_GUTENBERG = self ::SUPPORTS_EDITOR ;
62
63
const SUPPORTS_AUTHOR = 'author ' ;
63
64
const SUPPORTS_FEATURED_IMAGE = 'thumbnail ' ;
64
65
const SUPPORTS_EXCERPT = 'excerpt ' ;
@@ -107,6 +108,15 @@ abstract class Post_Type {
107
108
*/
108
109
protected $ is_hierarchical = false ;
109
110
111
+ /**
112
+ * Ability to display the CPT in the REST API
113
+ * Please be aware that this enable the CPT to use Gutenberg if supporting editor in WP 5.0 and up
114
+ * affect: show_in_rest
115
+ *
116
+ * @var boolean
117
+ */
118
+ protected $ has_rest_api = false ;
119
+
110
120
/**
111
121
* Specify where to redirect singular post type page
112
122
* IF has_singular == false AND is_searchable == true THEN we need to redirect page from search results to some other page
@@ -134,7 +144,7 @@ abstract class Post_Type {
134
144
135
145
/**
136
146
* Admin menu vertical position
137
- * Be very carefull and do not add more than 5 Post Types to same number!
147
+ * Be very careful and do not add more than 5 Post Types to same number!
138
148
* affect: menu_position
139
149
*
140
150
* @var integer
@@ -264,6 +274,11 @@ public function register() {
264
274
);
265
275
$ labels = array_merge ( $ labels , $ this ->labels );
266
276
277
+ // If we should support gutenberg, we need to enable the rest api.
278
+ if ( self ::SUPPORTS_GUTENBERG === 'editor ' && ! $ this ->has_rest_api ) {
279
+ $ this ->has_rest_api = true ;
280
+ }
281
+
267
282
$ args = array (
268
283
'labels ' => $ labels ,
269
284
'hierarchical ' => $ this ->is_hierarchical ,
@@ -283,6 +298,7 @@ public function register() {
283
298
'with_front ' => ( ! $ this ->rewrite_singular || $ this ->redirect ),
284
299
),
285
300
'query_var ' => $ this ->query_var ,
301
+ 'show_in_rest ' => $ this ->has_rest_api ,
286
302
);
287
303
288
304
if ( ! empty ( $ this ->taxonomies ) && is_array ( $ this ->taxonomies ) ) {
0 commit comments