Skip to content

Commit c545f32

Browse files
committed
Editor settings in PHP : merge filters to one filter and add documentation
1 parent 9d2f540 commit c545f32

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,25 @@ You can launch a bundle report with the following command :
109109
```bash
110110
yarn bundle-report
111111
```
112+
113+
## WordPress Editor (Gutenberg)
114+
115+
### Customize blocks
116+
117+
The `bff_editor_custom_settings` filter allow you to customize blocks styles and variations. For example:
118+
119+
```php
120+
add_filter( 'bff_editor_custom_settings', 'customize_editor_settings', 10, 1 );
121+
function customize_editor_settings( $settings ) {
122+
// Disable all block styles for Separator block
123+
$settings[ 'disableAllBlocksStyles' ] = [ 'core/separator' ];
124+
125+
// Disable specific block style for Button block
126+
$settings[ 'disabledBlocksStyles' ] = [ 'core/button' => [ 'outline' ] ];
127+
128+
// Allow only YouTube variation for Embed block
129+
$settings[ 'allowedBlocksVariations' ] = [ 'core/embed' => [ 'youtube' ] ];
130+
131+
return $settings;
132+
}
133+
```

inc/Services/Editor.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,30 +203,24 @@ public function admin_editor_script(): void {
203203
$this->assets_tools->add_inline_script(
204204
'theme-admin-editor-script',
205205
'const BFFEditorSettings = ' . wp_json_encode(
206-
[
207-
'disableAllBlocksStyles' => apply_filters(
208-
'bff_editor_disable_all_blocks_styles',
209-
[
206+
apply_filters(
207+
'bff_editor_custom_settings',
208+
[
209+
'disableAllBlocksStyles' => [
210210
'core/separator',
211211
'core/quote',
212212
'core/pullquote',
213213
'core/table',
214214
'core/image',
215-
]
216-
),
217-
'disabledBlocksStyles' => apply_filters(
218-
'bff_editor_disabled_blocks_styles',
219-
[
215+
],
216+
'disabledBlocksStyles' => [
220217
// 'core/button' => [ 'outline' ]
221-
]
222-
),
223-
'allowedBlocksVariations' => apply_filters(
224-
'bff_editor_allowed_blocks_variations',
225-
[
218+
],
219+
'allowedBlocksVariations' => [
226220
'core/embed' => [ 'youtube', 'vimeo', 'dailymotion' ],
227-
]
228-
),
229-
]
221+
],
222+
]
223+
)
230224
),
231225
'before'
232226
);

src/js/editor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/*global BFFEditorSettings*/
1+
/* global BFFEditorSettings */
2+
3+
/* Customize BFFEditorSettings in inc/Services/Editor.php or with `bff_editor_custom_settings` filter (see readme). */
24

35
import lazySizes from 'lazysizes'
46
import 'lazysizes/plugins/native-loading/ls.native-loading'

0 commit comments

Comments
 (0)