diff --git a/.plugin-data b/.plugin-data index 5f90b2a..af27360 100644 --- a/.plugin-data +++ b/.plugin-data @@ -1,4 +1,4 @@ { - "version": "1.0.3", + "version": "1.0.4", "slug": "blockparty-modal" } diff --git a/README.md b/README.md index 0b52457..9868201 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,27 @@ add_filter( 'blockparty_modal_trigger_allowed_blocks', function ( $blocks ) { - **Parameters:** `array` — List of block names (e.g. `'core/button'`). - **Default:** `array( 'core/button' )` +### Blocks allowed inside the modal + +The modal block uses InnerBlocks for its content. By default, a fixed set of blocks is allowed (paragraph, heading, list, image, button, etc.). To change which blocks can be inserted inside the modal, use the filter `blockparty_modal_inner_allowed_blocks` in your theme or plugin: + +```php +add_filter( 'blockparty_modal_inner_allowed_blocks', function ( array $blocks ) { + // Add more blocks + $blocks[] = 'core/cover'; + $blocks[] = 'core/group'; + return $blocks; +} ); + +// Or restrict to a subset +add_filter( 'blockparty_modal_inner_allowed_blocks', function () { + return [ 'core/paragraph', 'core/image', 'core/button' ]; +} ); +``` + +- **Filter name:** `blockparty_modal_inner_allowed_blocks` +- **Parameters:** `array` — List of block names (e.g. `'core/paragraph'`, `'core/button'`). Default list includes paragraph, heading, list, image, gallery, video, buttons, embed, shortcode, etc. + ## 🛠️ Development ### Project Structure @@ -249,6 +270,9 @@ This plugin is distributed under the GPL-2.0-or-later license. See the [LICENSE] See [readme.txt](readme.txt) for the full version history. Recent highlights: +- **1.0.4** + - Filter `blockparty_modal_inner_allowed_blocks` to control allowed blocks in the modal. + - **1.0.3** - Fix: prevent adding linkedModalId attribute to non allowed blocks. - Set min required PHP version to 8.1 diff --git a/blockparty-modal.php b/blockparty-modal.php index f7bd456..05873fe 100644 --- a/blockparty-modal.php +++ b/blockparty-modal.php @@ -2,7 +2,7 @@ /** * Plugin Name: Blockparty Modal * Description: Modal block for WordPress editor. - * Version: 1.0.3 + * Version: 1.0.4 * Requires at least: 6.8 * Requires PHP: 8.1 * Author: Be API Technical Team @@ -19,7 +19,7 @@ exit; // Exit if accessed directly. } -define( 'BLOCKPARTY_MODAL_VERSION', '1.0.3' ); +define( 'BLOCKPARTY_MODAL_VERSION', '1.0.4' ); define( 'BLOCKPARTY_MODAL_URL', plugin_dir_url( __FILE__ ) ); define( 'BLOCKPARTY_MODAL_DIR', plugin_dir_path( __FILE__ ) ); @@ -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/package.json b/package.json index e306a11..08e2eb4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blockparty-modal", - "version": "1.0.3", + "version": "1.0.4", "description": "Add a modal block to the WordPress editor.", "author": "Be API", "license": "GPL-2.0-or-later", diff --git a/readme.txt b/readme.txt index c885cca..4085afc 100644 --- a/readme.txt +++ b/readme.txt @@ -45,6 +45,9 @@ directory take precedence. For example, `/assets/screenshot-1.png` would win ove == Changelog == += 1.0.4 = +* Filter `blockparty_modal_inner_allowed_blocks` to control allowed blocks in the modal. + = 1.0.3 = * Fix: prevent adding linkedModalId attribute to non allowed blocks. * Set min required PHP version to 8.1 diff --git a/src/blockparty-modal/block.json b/src/blockparty-modal/block.json index 42e0aaa..8f1ddfc 100644 --- a/src/blockparty-modal/block.json +++ b/src/blockparty-modal/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "blockparty/modal", - "version": "1.0.3", + "version": "1.0.4", "title": "Modal", "category": "widgets", "description": "Insert a modal dialog that opens on trigger. Configure content and behaviour in the editor; the modal is displayed on the frontend when activated.", 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' && (