diff --git a/README.md b/README.md index accf8cee..a0d3935f 100644 --- a/README.md +++ b/README.md @@ -109,3 +109,25 @@ You can launch a bundle report with the following command : ```bash yarn bundle-report ``` + +## WordPress Editor (Gutenberg) + +### Customize blocks + +The `bff_editor_custom_settings` filter allow you to customize blocks styles and variations. For example: + +```php +add_filter( 'bff_editor_custom_settings', 'customize_editor_settings', 10, 1 ); +function customize_editor_settings( $settings ) { + // Disable all block styles for Separator block + $settings[ 'disableAllBlocksStyles' ] = [ 'core/separator' ]; + + // Disable specific block style for Button block + $settings[ 'disabledBlocksStyles' ] = [ 'core/button' => [ 'outline' ] ]; + + // Allow only YouTube variation for Embed block + $settings[ 'allowedBlocksVariations' ] = [ 'core/embed' => [ 'youtube' ] ]; + + return $settings; +} +``` \ No newline at end of file diff --git a/inc/Services/Editor.php b/inc/Services/Editor.php index 46eb68c1..d5cc8955 100644 --- a/inc/Services/Editor.php +++ b/inc/Services/Editor.php @@ -203,30 +203,24 @@ public function admin_editor_script(): void { $this->assets_tools->add_inline_script( 'theme-admin-editor-script', 'const BFFEditorSettings = ' . wp_json_encode( - [ - 'disableAllBlocksStyles' => apply_filters( - 'bff_editor_disable_all_blocks_styles', - [ + apply_filters( + 'bff_editor_custom_settings', + [ + 'disableAllBlocksStyles' => [ 'core/separator', 'core/quote', 'core/pullquote', 'core/table', 'core/image', - ] - ), - 'disabledBlocksStyles' => apply_filters( - 'bff_editor_disabled_blocks_styles', - [ + ], + 'disabledBlocksStyles' => [ // 'core/button' => [ 'outline' ] - ] - ), - 'allowedBlocksVariations' => apply_filters( - 'bff_editor_allowed_blocks_variations', - [ + ], + 'allowedBlocksVariations' => [ 'core/embed' => [ 'youtube', 'vimeo', 'dailymotion' ], - ] - ), - ] + ], + ] + ) ), 'before' ); diff --git a/src/js/editor.js b/src/js/editor.js index c26e98c5..fbed2e49 100644 --- a/src/js/editor.js +++ b/src/js/editor.js @@ -1,4 +1,6 @@ -/*global BFFEditorSettings*/ +/* global BFFEditorSettings */ + +/* Customize BFFEditorSettings in inc/Services/Editor.php or with `bff_editor_custom_settings` filter (see readme). */ import lazySizes from 'lazysizes' import 'lazysizes/plugins/native-loading/ls.native-loading'