diff --git a/composer.json b/composer.json index 98a1e7d0..c333a62a 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/inc/Services/Editor.php b/inc/Services/Editor.php index 6f43f891..ab34f28b 100644 --- a/inc/Services/Editor.php +++ b/inc/Services/Editor.php @@ -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 ); } @@ -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 ); } }