Skip to content

Commit b686ebc

Browse files
committed
🧑‍💻 Add the wp-block- classname without acf namespace to the block list container
1 parent 59eba36 commit b686ebc

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@verbatim
2+
wp.hooks.addFilter(
3+
'blocks.getBlockDefaultClassName',
4+
'acf-composer/block-slug-classname',
5+
(className, blockName) => {
6+
if (! blockName.startsWith('acf/')) {
7+
return className;
8+
}
9+
10+
const list = (className || '').split(/\\s+/);
11+
12+
const classes = list.reduce((acc, current) => {
13+
acc.push(current);
14+
15+
if (current.startsWith('wp-block-acf-')) {
16+
acc.push(
17+
current.replace('wp-block-acf-', 'wp-block-')
18+
);
19+
}
20+
21+
return acc;
22+
}, []);
23+
24+
return classes.join(' ');
25+
}
26+
);
27+
@endverbatim

src/AcfComposer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ protected function handleBlocks(): void
207207
}
208208
});
209209

210+
add_action('enqueue_block_editor_assets', function () {
211+
wp_add_inline_script('wp-blocks', view('acf-composer::block-editor-filters')->render());
212+
});
213+
210214
add_action('acf_block_render_template', function ($block, $content, $is_preview, $post_id, $wp_block, $context) {
211215
if (! class_exists($composer = $block['render_template'] ?? '')) {
212216
return;

src/Block.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ public function getClasses(): string
474474
return str_replace(
475475
acf_slugify($this->namespace),
476476
$this->slug,
477-
$supports['class'] ?? "wp-block-{$this->slug}"
477+
$supports['class'] ?? ''
478478
);
479479
}
480480

0 commit comments

Comments
 (0)