Skip to content

Commit

Permalink
feat: enqueue mb assets in gutenberg screens
Browse files Browse the repository at this point in the history
  • Loading branch information
tanftw committed Apr 17, 2024
1 parent 059f02d commit cf9b019
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion inc/meta-box.php
Expand Up @@ -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;
}

Expand Down Expand Up @@ -149,6 +149,12 @@ public function enqueue() {
do_action( 'rwmb_enqueue_scripts', $this );
}

private function is_gutenberg_screen() : bool {
global $pagenow;

return in_array( $pagenow, ['site-editor.php', 'widgets.php'] );
}

/**
* Add meta box for multiple post types
*/
Expand Down
9 changes: 7 additions & 2 deletions js/validation/validation.js
Expand Up @@ -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 );
Expand Down

0 comments on commit cf9b019

Please sign in to comment.