diff --git a/includes/class-displayfeaturedimagegenesis-postmeta.php b/includes/class-displayfeaturedimagegenesis-postmeta.php index 446650f..36bf8fe 100644 --- a/includes/class-displayfeaturedimagegenesis-postmeta.php +++ b/includes/class-displayfeaturedimagegenesis-postmeta.php @@ -28,15 +28,6 @@ class Display_Featured_Image_Genesis_Post_Meta { */ protected $move = '_displayfeaturedimagegenesis_move'; - /** - * Add a new metabox only on Gutenberg screens. - * - * @since 3.0.0 - */ - public function maybe_add_metabox() { - add_action( 'add_meta_boxes', array( $this, 'add_metabox' ), 10, 2 ); - } - /** * For Gutenberg, add a new metabox, since the thumbnail hooks are no longer present. * Should eventually be replaced with a block. @@ -47,6 +38,9 @@ class Display_Featured_Image_Genesis_Post_Meta { * @param $post */ public function add_metabox( $post_type, $post ) { + if ( ! $this->is_block_editor() ) { + return; + } if ( ! post_type_supports( $post_type, 'thumbnail' ) ) { return; } @@ -193,6 +187,23 @@ class Display_Featured_Image_Genesis_Post_Meta { return $output; } + /** + * Check whether we are on a block editor/Gutenberg screen. + * + * @return bool + */ + private function is_block_editor() { + if ( ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) ) { + return true; + } + $screen = get_current_screen(); + if ( method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() ) { + return true; + } + + return false; + } + /** * Update the post meta. * diff --git a/includes/class-displayfeaturedimagegenesis.php b/includes/class-displayfeaturedimagegenesis.php index d5776dc..3611511 100644 --- a/includes/class-displayfeaturedimagegenesis.php +++ b/includes/class-displayfeaturedimagegenesis.php @@ -148,7 +148,7 @@ class Display_Featured_Image_Genesis { add_action( 'admin_init', array( $this->author, 'set_author_meta' ) ); // Post Meta - add_action( 'enqueue_block_editor_assets', array( $this->post_meta, 'maybe_add_metabox' ) ); + add_action( 'add_meta_boxes', array( $this->post_meta, 'add_metabox' ), 10, 2 ); add_filter( 'admin_post_thumbnail_html', array( $this->post_meta, 'meta_box' ), 10, 2 ); add_action( 'save_post', array( $this->post_meta, 'save_meta' ) );