Skip to content

Commit

Permalink
Make it more obvious that we enable the rest api, and make it more ob…
Browse files Browse the repository at this point in the history
…vious that we add support for gutenberg
  • Loading branch information
jimmitjoo committed Jan 12, 2019
1 parent 6649db9 commit 661600d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions framework/Objects/Post_Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ abstract class Post_Type {

const SUPPORTS_TITLE = 'title';
const SUPPORTS_EDITOR = 'editor';
const SUPPORTS_GUTENBERG = self::SUPPORTS_EDITOR;
const SUPPORTS_AUTHOR = 'author';
const SUPPORTS_FEATURED_IMAGE = 'thumbnail';
const SUPPORTS_EXCERPT = 'excerpt';
Expand Down Expand Up @@ -108,13 +109,13 @@ abstract class Post_Type {
protected $is_hierarchical = false;

/**
* Ability to enable the Gutenberg editor
* Please be aware that this makes the post_type to show up in the REST API
* Ability to display the CPT in the REST API
* Please be aware that this enable the CPT to use Gutenberg if supporting editor in WP 5.0 and up
* affect: show_in_rest
*
* @var boolean
*/
protected $enable_gutenberg = false;
protected $has_rest_api = false;

/**
* Specify where to redirect singular post type page
Expand Down Expand Up @@ -273,8 +274,9 @@ public function register() {
);
$labels = array_merge( $labels, $this->labels );

if ( ! in_array( 'editor', $this->supports ) && $this->enable_gutenberg ) {
$this->supports = array_push($this->supports, 'editor');
// If we should support gutenberg, we need to enable the rest api.
if ( self::SUPPORTS_GUTENBERG === 'editor' && ! $this->has_rest_api ) {
$this->has_rest_api = true;
}

$args = array(
Expand All @@ -296,7 +298,7 @@ public function register() {
'with_front' => ( ! $this->rewrite_singular || $this->redirect ),
),
'query_var' => $this->query_var,
'show_in_rest' => $this->enable_gutenberg,
'show_in_rest' => $this->has_rest_api,
);

if ( ! empty( $this->taxonomies ) && is_array( $this->taxonomies ) ) {
Expand Down

0 comments on commit 661600d

Please sign in to comment.