Skip to content
Merged
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 .plugin-data
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.0.3",
"version": "1.0.4",
"slug": "blockparty-modal"
}
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
44 changes: 42 additions & 2 deletions blockparty-modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__ ) );

Expand Down Expand Up @@ -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;
}

Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/blockparty-modal/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
55 changes: 32 additions & 23 deletions src/blockparty-modal/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 (
<>
Expand All @@ -193,7 +202,7 @@ export default function Edit( { clientId, attributes, setAttributes } ) {
/>
</div>
<div className="wp-block-blockparty-modal__content">
<InnerBlocks allowedBlocks={ ALLOWED_BLOCKS } />
<InnerBlocks allowedBlocks={ allowedBlocks } />
</div>
{ enableCloseButton && closedBy !== 'none' && (
<button
Expand Down
Loading