Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"phpcompatibility/phpcompatibility-wp": "^2.1",
"phpro/grumphp-shim": "^2.6",
"roave/security-advisories": "dev-latest",
"wp-coding-standards/wpcs": "3.3.0",
"wp-coding-standards/wpcs": "3.4.1",
"wp-plugin/advanced-custom-fields": "6.8.4"
},
"scripts": {
Expand Down
59 changes: 27 additions & 32 deletions inc/Services/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function boot( Service_Container $container ): void {
*/
add_action( 'enqueue_block_assets', [ $this, 'admin_editor_script' ] );
/**
* White list of gutenberg blocks
* Black list of Gutenberg blocks
*/
add_filter( 'allowed_block_types_all', [ $this, 'gutenberg_blocks_allowed' ], 10, 2 );
}
Expand Down Expand Up @@ -207,44 +207,39 @@ private function register_custom_block_styles() {
}

/**
* Allow some core Gutenberg blocks
* Disallow some Gutenberg blocks (blacklist).
*
* @param bool|array $allowed_blocks
* @param \WP_Block_Editor_Context $block_editor_context
* @param bool|array $allowed_blocks The allowed blocks.
* @param \WP_Block_Editor_Context $block_editor_context The block editor context.
*
* @return array
* @return array The allowed blocks.
*/
public function gutenberg_blocks_allowed( $allowed_blocks, \WP_Block_Editor_Context $block_editor_context ): array {
// If boolean, get explicit list of allowed blocks.
if ( is_bool( $allowed_blocks ) ) {
$allowed_blocks = $allowed_blocks ? array_keys( \WP_Block_Type_Registry::get_instance()->get_all_registered() ) : [];
}

$allowed = [
//base
'core/block',
'core/heading',
'core/paragraph',
'core/image',
'core/list',
'core/list-item',
'core/quote',
'core/pullquote',
'core/table',
'core/buttons',
'core/button',
'core/group',
'core/columns',
'core/column',
'core/media-text',
'core/spacer',
'core/separator',
'core/cover',
'core/gallery',
'core/video',
'core/file',
// List of disallowed blocks.
$disallowed_blocks = [
'core/html',
'core/freeform',
'core/code',
'core/preformatted',
'core/verse',
'core/footnotes',
'core/more',
'core/loginout',
'core/embed',
// custom
'beapi/manual-block',
'beapi/dynamic-block',
];

return ( is_array( $allowed_blocks ) ) ? array_merge( $allowed, $allowed_blocks ) : $allowed;
// Remove disallowed blocks from allowed blocks.
foreach ( $disallowed_blocks as $block ) {
if ( in_array( $block, $allowed_blocks, true ) ) {
unset( $allowed_blocks[ array_search( $block, $allowed_blocks, true ) ] );
}
}

return array_values( $allowed_blocks );
}
}
Loading