Commit 9c84f121 authored by Andrei Mondoc's avatar Andrei Mondoc
Browse files

ensure civi resources are enqueued in gutenberg editor

parent 398a0dd4
......@@ -61,6 +61,9 @@ class CiviCRM_Gutenberg_Blocks {
// convert serialised civicrm content blocks to shortcode
add_action( 'wp', [ $this, 'prerender' ], 5 );
// add civicrm core resources
add_action( 'admin_head', [ $this, 'maybe_add_core_resources' ], 20 );
}
......@@ -129,7 +132,7 @@ class CiviCRM_Gutenberg_Blocks {
'extra_attributes' => [
'type' => 'array',
'default' => [],
],
],
],
'editor_script' => 'civicrm-gutenberg-blocks', // The script name we gave in the wp_register_script() call.
'render_callback' => [ $this, 'block_render' ],
......@@ -510,6 +513,41 @@ class CiviCRM_Gutenberg_Blocks {
/**
* Adds CiviCRM core resources
* in the Gutenberg editor if they are missing.
*
* @uses 'admin_head' action
*
* @since 0.1
*
* @return void
*/
public function maybe_add_core_resources() {
$screen = get_current_screen();
if ( empty( $screen ) ) return;
if ( ! $screen->is_block_editor() ) return;
$actions = [
'load-post.php',
'load-post-new.php',
'load-page.php',
'load-page-new.php',
];
foreach ( $actions as $action ) {
if ( ! has_action( $action, [ civi_wp()->modal, 'add_core_resources' ] ) ) {
add_action( $action, [ civi_wp()->modal, 'add_core_resources' ] );
}
}
}
} // Class ends.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment