Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enqueue mb assets in gutenberg screens #1578

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion inc/meta-box.php
Original file line number Diff line number Diff line change
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 {
$screen = get_current_screen();

return in_array( $screen->base, [ 'site-editor', 'widgets' ] );
}

/**
* Add meta box for multiple post types
*/
Expand Down
9 changes: 7 additions & 2 deletions js/validation/validation.js
Original file line number Diff line number Diff line change
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