@@ -59,6 +59,7 @@ abstract class Post_Type {
5959
6060 const SUPPORTS_TITLE = 'title ' ;
6161 const SUPPORTS_EDITOR = 'editor ' ;
62+ const SUPPORTS_GUTENBERG = self ::SUPPORTS_EDITOR ;
6263 const SUPPORTS_AUTHOR = 'author ' ;
6364 const SUPPORTS_FEATURED_IMAGE = 'thumbnail ' ;
6465 const SUPPORTS_EXCERPT = 'excerpt ' ;
@@ -107,6 +108,15 @@ abstract class Post_Type {
107108 */
108109 protected $ is_hierarchical = false ;
109110
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+
110120 /**
111121 * Specify where to redirect singular post type page
112122 * 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 {
134144
135145 /**
136146 * 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!
138148 * affect: menu_position
139149 *
140150 * @var integer
@@ -264,6 +274,11 @@ public function register() {
264274 );
265275 $ labels = array_merge ( $ labels , $ this ->labels );
266276
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+
267282 $ args = array (
268283 'labels ' => $ labels ,
269284 'hierarchical ' => $ this ->is_hierarchical ,
@@ -283,6 +298,7 @@ public function register() {
283298 'with_front ' => ( ! $ this ->rewrite_singular || $ this ->redirect ),
284299 ),
285300 'query_var ' => $ this ->query_var ,
301+ 'show_in_rest ' => $ this ->has_rest_api ,
286302 );
287303
288304 if ( ! empty ( $ this ->taxonomies ) && is_array ( $ this ->taxonomies ) ) {
0 commit comments