From c588bdd2d4cc0c05a80546f187693f94c71ca984 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Thu, 26 Oct 2017 11:38:05 +1100 Subject: [PATCH] Don't show the classic editor dropdown on unsupported post types. (#3146) Also adds a new `gutenberg_can_edit_post_type` filter, so plugins can disable Gutenberg by post type. --- gutenberg.php | 19 ++++++----------- lib/register.php | 53 +++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/gutenberg.php b/gutenberg.php index 3a93cfd2c91103..0ed4d2c47f6894 100644 --- a/gutenberg.php +++ b/gutenberg.php @@ -136,18 +136,7 @@ function gutenberg_init( $return, $post ) { return false; } - $post_type = $post->post_type; - $post_type_object = get_post_type_object( $post_type ); - - if ( 'attachment' === $post_type ) { - return false; - } - - if ( ! $post_type_object->show_in_rest ) { - return false; - } - - if ( ! post_type_supports( $post_type, 'editor' ) ) { + if ( ! gutenberg_can_edit_post( $post ) ) { return false; } @@ -349,7 +338,7 @@ function gutenberg_add_edit_link_filters() { * @return array Updated post actions. */ function gutenberg_add_edit_link( $actions, $post ) { - if ( 'trash' === $post->post_status || ! post_type_supports( $post->post_type, 'editor' ) ) { + if ( ! gutenberg_can_edit_post( $post ) ) { return $actions; } @@ -420,6 +409,10 @@ function gutenberg_modify_add_new_button_url( $url, $path ) { * @since 1.5.0 */ function gutenberg_replace_default_add_new_button() { + global $typenow; + if ( ! gutenberg_can_edit_post_type( $typenow ) ) { + return; + } ?>