Skip to content

Commit

Permalink
Merge pull request #43 from jimmitjoo/master
Browse files Browse the repository at this point in the history
Make it possible to enable Gutenberg editor for custom post types
  • Loading branch information
aprokopenko authored Jan 14, 2019
2 parents 1303e4e + 661600d commit 293db6a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion 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 @@ -107,6 +108,15 @@ abstract class Post_Type {
*/
protected $is_hierarchical = false;

/**
* 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 $has_rest_api = false;

/**
* Specify where to redirect singular post type page
* IF has_singular == false AND is_searchable == true THEN we need to redirect page from search results to some other page
Expand Down Expand Up @@ -134,7 +144,7 @@ abstract class Post_Type {

/**
* Admin menu vertical position
* Be very carefull and do not add more than 5 Post Types to same number!
* Be very careful and do not add more than 5 Post Types to same number!
* affect: menu_position
*
* @var integer
Expand Down Expand Up @@ -264,6 +274,11 @@ public function register() {
);
$labels = array_merge( $labels, $this->labels );

// 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(
'labels' => $labels,
'hierarchical' => $this->is_hierarchical,
Expand All @@ -283,6 +298,7 @@ public function register() {
'with_front' => ( ! $this->rewrite_singular || $this->redirect ),
),
'query_var' => $this->query_var,
'show_in_rest' => $this->has_rest_api,
);

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

0 comments on commit 293db6a

Please sign in to comment.