Skip to content

Commit aecb268

Browse files
authored
Merge pull request #181 from BeAPI/fix/assets
fix (theme): partial assets loading in editor
2 parents ca4e34a + 4a4e1a4 commit aecb268

2 files changed

Lines changed: 48 additions & 13 deletions

File tree

‎inc/Services/Assets.php‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,21 @@ public function boot( Service_Container $container ): void {
5151
/**
5252
* Add hooks for the scripts and styles to hook on
5353
*/
54+
add_action( 'wp_enqueue_scripts', [ $this, 'add_theme_capabilities_script' ] );
55+
add_filter( 'wp_login_page_theme_css', [ $this, 'login_stylesheet_uri' ] );
56+
57+
/**
58+
* Following hooks are only needed in the frontend
59+
*/
60+
if ( is_admin() ) {
61+
return;
62+
}
63+
5464
add_action( 'wp', [ $this, 'register_assets' ] );
5565
add_action( 'init', [ $this, 'register_partial_assets' ] );
5666
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
5767
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles' ] );
58-
add_action( 'wp_enqueue_scripts', [ $this, 'add_theme_capabilities_script' ] );
5968
add_filter( 'stylesheet_uri', [ $this, 'stylesheet_uri' ] );
60-
add_filter( 'wp_login_page_theme_css', [ $this, 'login_stylesheet_uri' ] );
6169
add_filter( 'block_type_metadata', [ $this, 'add_block_assets_to_metadata' ], 1000, 1 );
6270
add_filter( 'render_block', [ $this, 'enqueue_pattern_assets' ], 1000, 2 );
6371
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_template_assets' ], 1000, 1 );
@@ -74,10 +82,6 @@ public function get_service_name(): string {
7482
* Register all the Theme assets
7583
*/
7684
public function register_assets(): void {
77-
if ( is_admin() ) {
78-
return;
79-
}
80-
8185
// Js
8286
$asset = $this->get_asset_file( 'app', 'js' );
8387
if ( $asset ) {

‎inc/Services/Editor.php‎

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,12 @@ private function style(): void {
211211
/**
212212
* Do not enqueue a nonexistent file on admin
213213
*/
214-
if ( ! $editor_asset ) {
215-
return;
214+
if ( $editor_asset ) {
215+
add_editor_style( $editor_asset['file'] );
216216
}
217217

218-
add_editor_style( $editor_asset['file'] );
219-
220218
/**
221-
* Load all partial assets
219+
* Load all partial css assets
222220
*/
223221
foreach ( $this->assets->partial_assets['css'] as $asset ) {
224222
add_editor_style( $asset['path_from_theme_root'] );
@@ -248,8 +246,41 @@ public function admin_editor_script(): void {
248246
/**
249247
* Do not enqueue a nonexistent file on admin
250248
*/
251-
if ( ! $editor_asset ) {
252-
return;
249+
if ( $editor_asset ) {
250+
$this->assets_tools->register_script(
251+
'theme-admin-editor-script',
252+
$editor_asset['file'],
253+
$editor_asset['dependencies'],
254+
$editor_asset['version'],
255+
[ 'in_footer' => true ]
256+
);
257+
258+
$this->assets_tools->add_inline_script(
259+
'theme-admin-editor-script',
260+
'const BFFEditorSettings = ' . wp_json_encode(
261+
apply_filters(
262+
'bff_editor_custom_settings',
263+
[
264+
'disableAllBlocksStyles' => [
265+
'core/separator',
266+
'core/quote',
267+
'core/pullquote',
268+
'core/table',
269+
'core/image',
270+
],
271+
'disabledBlocksStyles' => [
272+
// 'core/button' => [ 'outline' ]
273+
],
274+
'allowedBlocksVariations' => [
275+
'core/embed' => [ 'youtube', 'vimeo', 'dailymotion' ],
276+
],
277+
]
278+
)
279+
),
280+
'before'
281+
);
282+
283+
$this->assets_tools->enqueue_script( 'theme-admin-editor-script' );
253284
}
254285

255286
$this->assets_tools->register_script(

0 commit comments

Comments
 (0)