diff --git a/inc/meta-box.php b/inc/meta-box.php index 4aedbf57..bb241143 100644 --- a/inc/meta-box.php +++ b/inc/meta-box.php @@ -110,7 +110,7 @@ protected function object_hooks() { } public function enqueue() { - if ( is_admin() && ! $this->is_edit_screen() ) { + if ( is_admin() && ! $this->is_edit_screen() && ! $this->is_gutenberg_screen() ) { return; } @@ -149,6 +149,12 @@ public function enqueue() { do_action( 'rwmb_enqueue_scripts', $this ); } + private function is_gutenberg_screen() : bool { + $screen = get_current_screen(); + + return in_array( $screen->base, [ 'site-editor', 'widgets' ] ); + } + /** * Add meta box for multiple post types */ diff --git a/js/validation/validation.js b/js/validation/validation.js index 6aaee97b..59dc365d 100644 --- a/js/validation/validation.js +++ b/js/validation/validation.js @@ -216,8 +216,13 @@ class GutenbergValidation extends Validation { init() { var that = this, - editor = wp.data.dispatch( 'core/editor' ), - savePost = editor.savePost; // Reference original method. + editor = wp.data.dispatch( 'core/editor' ); + + if ( ! editor ) { + return false; + } + + const savePost = editor.savePost; // Reference original method. if ( that.settings ) { that.$form.validate( that.settings );