Skip to content

Commit a8818d6

Browse files
authored
Merge pull request #11 from BeAPI/ver/1.0.4
Release 1.0.4
2 parents fae91e6 + a06167c commit a8818d6

7 files changed

Lines changed: 104 additions & 28 deletions

File tree

.plugin-data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"version": "1.0.3",
2+
"version": "1.0.4",
33
"slug": "blockparty-modal"
44
}

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,27 @@ add_filter( 'blockparty_modal_trigger_allowed_blocks', function ( $blocks ) {
9191
- **Parameters:** `array` — List of block names (e.g. `'core/button'`).
9292
- **Default:** `array( 'core/button' )`
9393

94+
### Blocks allowed inside the modal
95+
96+
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:
97+
98+
```php
99+
add_filter( 'blockparty_modal_inner_allowed_blocks', function ( array $blocks ) {
100+
// Add more blocks
101+
$blocks[] = 'core/cover';
102+
$blocks[] = 'core/group';
103+
return $blocks;
104+
} );
105+
106+
// Or restrict to a subset
107+
add_filter( 'blockparty_modal_inner_allowed_blocks', function () {
108+
return [ 'core/paragraph', 'core/image', 'core/button' ];
109+
} );
110+
```
111+
112+
- **Filter name:** `blockparty_modal_inner_allowed_blocks`
113+
- **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.
114+
94115
## 🛠️ Development
95116

96117
### Project Structure
@@ -249,6 +270,9 @@ This plugin is distributed under the GPL-2.0-or-later license. See the [LICENSE]
249270

250271
See [readme.txt](readme.txt) for the full version history. Recent highlights:
251272

273+
- **1.0.4**
274+
- Filter `blockparty_modal_inner_allowed_blocks` to control allowed blocks in the modal.
275+
252276
- **1.0.3**
253277
- Fix: prevent adding linkedModalId attribute to non allowed blocks.
254278
- Set min required PHP version to 8.1

blockparty-modal.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Plugin Name: Blockparty Modal
44
* Description: Modal block for WordPress editor.
5-
* Version: 1.0.3
5+
* Version: 1.0.4
66
* Requires at least: 6.8
77
* Requires PHP: 8.1
88
* Author: Be API Technical Team
@@ -19,7 +19,7 @@
1919
exit; // Exit if accessed directly.
2020
}
2121

22-
define( 'BLOCKPARTY_MODAL_VERSION', '1.0.3' );
22+
define( 'BLOCKPARTY_MODAL_VERSION', '1.0.4' );
2323
define( 'BLOCKPARTY_MODAL_URL', plugin_dir_url( __FILE__ ) );
2424
define( 'BLOCKPARTY_MODAL_DIR', plugin_dir_path( __FILE__ ) );
2525

@@ -63,6 +63,16 @@ function block_editor_settings_modal_trigger_blocks( array $settings, \WP_Block_
6363
$settings['blockpartyModalTriggerAllowedBlocks'] = array_values(
6464
array_filter( is_array( $raw ) ? $raw : [], 'is_string' )
6565
);
66+
67+
/** @psalm-suppress MixedAssignment */
68+
$inner_raw = apply_filters(
69+
'blockparty_modal_inner_allowed_blocks',
70+
get_default_modal_inner_allowed_blocks()
71+
);
72+
$settings['blockpartyModalInnerAllowedBlocks'] = array_values(
73+
array_filter( is_array( $inner_raw ) ? $inner_raw : [], 'is_string' )
74+
);
75+
6676
return $settings;
6777
}
6878

@@ -77,6 +87,36 @@ function get_default_modal_trigger_allowed_blocks(): array {
7787
return [ 'core/button' ];
7888
}
7989

90+
/**
91+
* Default list of block names allowed inside the modal block (InnerBlocks).
92+
*
93+
* @return string[] Block names (e.g. 'core/paragraph').
94+
*/
95+
function get_default_modal_inner_allowed_blocks(): array {
96+
return [
97+
'core/paragraph',
98+
'core/heading',
99+
'core/list',
100+
'core/list-item',
101+
'core/file',
102+
'core/quote',
103+
'core/math',
104+
'core/details',
105+
'core/pullquote',
106+
'core/table',
107+
'core/embed',
108+
'core/shortcode',
109+
'core/html',
110+
'core/separator',
111+
'core/image',
112+
'core/gallery',
113+
'core/video',
114+
'core/buttons',
115+
'core/button',
116+
'core/spacer',
117+
];
118+
}
119+
80120
/**
81121
* Wraps block output with a trigger wrapper when linkedModalId is set,
82122
* so the view script can open the modal on click.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blockparty-modal",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Add a modal block to the WordPress editor.",
55
"author": "Be API",
66
"license": "GPL-2.0-or-later",

readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ directory take precedence. For example, `/assets/screenshot-1.png` would win ove
4545

4646
== Changelog ==
4747

48+
= 1.0.4 =
49+
* Filter `blockparty_modal_inner_allowed_blocks` to control allowed blocks in the modal.
50+
4851
= 1.0.3 =
4952
* Fix: prevent adding linkedModalId attribute to non allowed blocks.
5053
* Set min required PHP version to 8.1

src/blockparty-modal/block.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://schemas.wp.org/trunk/block.json",
33
"apiVersion": 3,
44
"name": "blockparty/modal",
5-
"version": "1.0.3",
5+
"version": "1.0.4",
66
"title": "Modal",
77
"category": "widgets",
88
"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.",

src/blockparty-modal/edit.js

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,30 @@ import { useState, useRef, useEffect } from '@wordpress/element';
4646

4747
import { generateStableModalId, MODAL_BLOCK_NAME } from './utils';
4848

49+
/** Default block names allowed inside the modal (filterable via blockparty_modal_inner_allowed_blocks). */
50+
const DEFAULT_INNER_ALLOWED_BLOCKS = [
51+
'core/paragraph',
52+
'core/heading',
53+
'core/list',
54+
'core/list-item',
55+
'core/file',
56+
'core/quote',
57+
'core/math',
58+
'core/details',
59+
'core/pullquote',
60+
'core/table',
61+
'core/embed',
62+
'core/shortcode',
63+
'core/html',
64+
'core/separator',
65+
'core/image',
66+
'core/gallery',
67+
'core/video',
68+
'core/buttons',
69+
'core/button',
70+
'core/spacer',
71+
];
72+
4973
/**
5074
* The edit function describes the structure of your block in the context of the
5175
* editor. This represents what the editor will render when the block is used.
@@ -147,28 +171,13 @@ export default function Edit( { clientId, attributes, setAttributes } ) {
147171
};
148172
}, [ isPreview ] );
149173

150-
const ALLOWED_BLOCKS = [
151-
'core/paragraph',
152-
'core/heading',
153-
'core/list',
154-
'core/list-item',
155-
'core/file',
156-
'core/quote',
157-
'core/math',
158-
'core/details',
159-
'core/pullquote',
160-
'core/table',
161-
'core/embed',
162-
'core/shortcode',
163-
'core/html',
164-
'core/separator',
165-
'core/image',
166-
'core/gallery',
167-
'core/video',
168-
'core/buttons',
169-
'core/button',
170-
'core/spacer',
171-
];
174+
const allowedBlocks = useSelect( ( storeSelect ) => {
175+
const settings = storeSelect( 'core/block-editor' ).getSettings();
176+
const list = settings?.blockpartyModalInnerAllowedBlocks;
177+
return Array.isArray( list ) && list.length > 0
178+
? list
179+
: DEFAULT_INNER_ALLOWED_BLOCKS;
180+
}, [] );
172181

173182
return (
174183
<>
@@ -193,7 +202,7 @@ export default function Edit( { clientId, attributes, setAttributes } ) {
193202
/>
194203
</div>
195204
<div className="wp-block-blockparty-modal__content">
196-
<InnerBlocks allowedBlocks={ ALLOWED_BLOCKS } />
205+
<InnerBlocks allowedBlocks={ allowedBlocks } />
197206
</div>
198207
{ enableCloseButton && closedBy !== 'none' && (
199208
<button

0 commit comments

Comments
 (0)