Skip to content

Commit

Permalink
Editor settings in PHP : merge filters to one filter and add document…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
MarieComet committed May 7, 2024
1 parent 9d2f540 commit c545f32
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
22 changes: 22 additions & 0 deletions README.md
Expand Up @@ -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;
}
```
28 changes: 11 additions & 17 deletions inc/Services/Editor.php
Expand Up @@ -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'
);
Expand Down
4 changes: 3 additions & 1 deletion 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'
Expand Down

0 comments on commit c545f32

Please sign in to comment.