From 7669f748d3dd4e5616564fa224a23f60b2ed16fe Mon Sep 17 00:00:00 2001 From: mricoul Date: Thu, 12 Mar 2026 09:25:43 +0100 Subject: [PATCH 1/3] feat(modal): make inner allowed blocks filterable Introduces the `blockparty_modal_inner_allowed_blocks` PHP filter to allow customization of the blocks permitted inside the modal content area. The block editor now retrieves these settings dynamically instead of using a hardcoded list. --- blockparty-modal.php | 40 ++++++++++++++++++++++++++ src/blockparty-modal/edit.js | 55 +++++++++++++++++++++--------------- 2 files changed, 72 insertions(+), 23 deletions(-) diff --git a/blockparty-modal.php b/blockparty-modal.php index f7bd456..b9b88ca 100644 --- a/blockparty-modal.php +++ b/blockparty-modal.php @@ -63,6 +63,16 @@ function block_editor_settings_modal_trigger_blocks( array $settings, \WP_Block_ $settings['blockpartyModalTriggerAllowedBlocks'] = array_values( array_filter( is_array( $raw ) ? $raw : [], 'is_string' ) ); + + /** @psalm-suppress MixedAssignment */ + $inner_raw = apply_filters( + 'blockparty_modal_inner_allowed_blocks', + get_default_modal_inner_allowed_blocks() + ); + $settings['blockpartyModalInnerAllowedBlocks'] = array_values( + array_filter( is_array( $inner_raw ) ? $inner_raw : [], 'is_string' ) + ); + return $settings; } @@ -77,6 +87,36 @@ function get_default_modal_trigger_allowed_blocks(): array { return [ 'core/button' ]; } +/** + * Default list of block names allowed inside the modal block (InnerBlocks). + * + * @return string[] Block names (e.g. 'core/paragraph'). + */ +function get_default_modal_inner_allowed_blocks(): array { + return [ + 'core/paragraph', + 'core/heading', + 'core/list', + 'core/list-item', + 'core/file', + 'core/quote', + 'core/math', + 'core/details', + 'core/pullquote', + 'core/table', + 'core/embed', + 'core/shortcode', + 'core/html', + 'core/separator', + 'core/image', + 'core/gallery', + 'core/video', + 'core/buttons', + 'core/button', + 'core/spacer', + ]; +} + /** * Wraps block output with a trigger wrapper when linkedModalId is set, * so the view script can open the modal on click. diff --git a/src/blockparty-modal/edit.js b/src/blockparty-modal/edit.js index 6063aae..90c72e5 100644 --- a/src/blockparty-modal/edit.js +++ b/src/blockparty-modal/edit.js @@ -46,6 +46,30 @@ import { useState, useRef, useEffect } from '@wordpress/element'; import { generateStableModalId, MODAL_BLOCK_NAME } from './utils'; +/** Default block names allowed inside the modal (filterable via blockparty_modal_inner_allowed_blocks). */ +const DEFAULT_INNER_ALLOWED_BLOCKS = [ + 'core/paragraph', + 'core/heading', + 'core/list', + 'core/list-item', + 'core/file', + 'core/quote', + 'core/math', + 'core/details', + 'core/pullquote', + 'core/table', + 'core/embed', + 'core/shortcode', + 'core/html', + 'core/separator', + 'core/image', + 'core/gallery', + 'core/video', + 'core/buttons', + 'core/button', + 'core/spacer', +]; + /** * The edit function describes the structure of your block in the context of the * editor. This represents what the editor will render when the block is used. @@ -147,28 +171,13 @@ export default function Edit( { clientId, attributes, setAttributes } ) { }; }, [ isPreview ] ); - const ALLOWED_BLOCKS = [ - 'core/paragraph', - 'core/heading', - 'core/list', - 'core/list-item', - 'core/file', - 'core/quote', - 'core/math', - 'core/details', - 'core/pullquote', - 'core/table', - 'core/embed', - 'core/shortcode', - 'core/html', - 'core/separator', - 'core/image', - 'core/gallery', - 'core/video', - 'core/buttons', - 'core/button', - 'core/spacer', - ]; + const allowedBlocks = useSelect( ( storeSelect ) => { + const settings = storeSelect( 'core/block-editor' ).getSettings(); + const list = settings?.blockpartyModalInnerAllowedBlocks; + return Array.isArray( list ) && list.length > 0 + ? list + : DEFAULT_INNER_ALLOWED_BLOCKS; + }, [] ); return ( <> @@ -193,7 +202,7 @@ export default function Edit( { clientId, attributes, setAttributes } ) { />
- +
{ enableCloseButton && closedBy !== 'none' && (