Skip to content

Commit 01202d6

Browse files
authored
Merge pull request #36 from BeAPI/release/1.0.9
Releases version 1.0.9
2 parents e3919eb + 4f9c1df commit 01202d6

13 files changed

Lines changed: 172 additions & 2275 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ node_modules/
2929

3030
# dotenv environment variables file
3131
.env
32+
33+
# Composer
34+
composer.lock

.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.8",
2+
"version": "1.0.9",
33
"slug": "blockparty-modal"
44
}

.wordpress-org/blueprints/blueprint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"pluginData": {
1212
"resource": "git:directory",
1313
"url": "https://github.com/BeAPI/blockparty-modal",
14-
"ref": "1.0.8",
14+
"ref": "1.0.9",
1515
"refType": "tag"
1616
},
1717
"options": {

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.0.9]
9+
10+
* Fix `blockparty_modal_inner_allowed_blocks` and `blockparty_modal_trigger_allowed_blocks` filters not being applied in the block editor on recent WordPress versions.
11+
* Pass allowed block lists to the editor script via `wp_localize_script` so they are available despite the block editor settings allowlist.
12+
813
## [1.0.8]
914

1015
* Add GitHub Actions check and `tests/bin/check-release-version.sh` to validate that release version bumps are consistent across all versioned files.

blockparty-modal.php

Lines changed: 59 additions & 26 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.8
5+
* Version: 1.0.9
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.8' );
22+
define( 'BLOCKPARTY_MODAL_VERSION', '1.0.9' );
2323
define( 'BLOCKPARTY_MODAL_URL', plugin_dir_url( __FILE__ ) );
2424
define( 'BLOCKPARTY_MODAL_DIR', plugin_dir_path( __FILE__ ) );
2525

@@ -47,31 +47,72 @@ function init(): void {
4747
add_action( 'init', __NAMESPACE__ . '\\init', 10, 0 );
4848

4949
/**
50-
* Passes the list of blocks allowed as modal triggers to the block editor settings
51-
* so the "Attached modal" panel is only shown for those blocks.
50+
* Returns the filtered list of blocks allowed inside the modal block.
5251
*
53-
* @param array<array-key, mixed> $settings Block editor settings.
54-
* @param \WP_Block_Editor_Context $_context Block editor context (unused).
55-
* @return array<array-key, mixed> Modified settings.
52+
* @return string[] Block names.
5653
*/
57-
function block_editor_settings_modal_trigger_blocks( array $settings, \WP_Block_Editor_Context $_context ): array { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- Required by block_editor_settings_all filter signature.
54+
function get_modal_inner_allowed_blocks(): array {
5855
/** @psalm-suppress MixedAssignment */
5956
$raw = apply_filters(
60-
'blockparty_modal_trigger_allowed_blocks',
61-
get_default_modal_trigger_allowed_blocks()
57+
'blockparty_modal_inner_allowed_blocks',
58+
get_default_modal_inner_allowed_blocks()
6259
);
63-
$settings['blockpartyModalTriggerAllowedBlocks'] = array_values(
60+
61+
return array_values(
6462
array_filter( is_array( $raw ) ? $raw : [], 'is_string' )
6563
);
64+
}
6665

66+
/**
67+
* Returns the filtered list of blocks allowed as modal triggers.
68+
*
69+
* @return string[] Block names.
70+
*/
71+
function get_modal_trigger_allowed_blocks(): array {
6772
/** @psalm-suppress MixedAssignment */
68-
$inner_raw = apply_filters(
69-
'blockparty_modal_inner_allowed_blocks',
70-
get_default_modal_inner_allowed_blocks()
73+
$raw = apply_filters(
74+
'blockparty_modal_trigger_allowed_blocks',
75+
get_default_modal_trigger_allowed_blocks()
7176
);
72-
$settings['blockpartyModalInnerAllowedBlocks'] = array_values(
73-
array_filter( is_array( $inner_raw ) ? $inner_raw : [], 'is_string' )
77+
78+
return array_values(
79+
array_filter( is_array( $raw ) ? $raw : [], 'is_string' )
7480
);
81+
}
82+
83+
/**
84+
* Passes allowed-block lists to the block editor script.
85+
*
86+
* Custom keys added via block_editor_settings_all are stripped by the editor
87+
* allowlist in recent WordPress versions, so the lists are localized here.
88+
*/
89+
function enqueue_block_editor_data(): void {
90+
if ( ! wp_script_is( 'blockparty-modal-editor-script', 'registered' ) ) {
91+
return;
92+
}
93+
94+
wp_localize_script(
95+
'blockparty-modal-editor-script',
96+
'blockpartyModalEditorSettings',
97+
[
98+
'innerAllowedBlocks' => get_modal_inner_allowed_blocks(),
99+
'triggerAllowedBlocks' => get_modal_trigger_allowed_blocks(),
100+
]
101+
);
102+
}
103+
104+
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\enqueue_block_editor_data', 20 );
105+
106+
/**
107+
* Passes allowed-block lists to block editor settings (legacy path).
108+
*
109+
* @param array<array-key, mixed> $settings Block editor settings.
110+
* @param \WP_Block_Editor_Context $_context Block editor context (unused).
111+
* @return array<array-key, mixed> Modified settings.
112+
*/
113+
function block_editor_settings_modal_trigger_blocks( array $settings, \WP_Block_Editor_Context $_context ): array { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- Required by block_editor_settings_all filter signature.
114+
$settings['blockpartyModalTriggerAllowedBlocks'] = get_modal_trigger_allowed_blocks();
115+
$settings['blockpartyModalInnerAllowedBlocks'] = get_modal_inner_allowed_blocks();
75116

76117
return $settings;
77118
}
@@ -136,16 +177,8 @@ function render_block_add_modal_trigger( $block_content, array $block ) {
136177
return $block_content;
137178
}
138179

139-
$block_name = (string) ( $block['blockName'] ?? '' );
140-
/** @psalm-suppress MixedAssignment */
141-
$raw_blocks = apply_filters(
142-
'blockparty_modal_trigger_allowed_blocks',
143-
get_default_modal_trigger_allowed_blocks()
144-
);
145-
$allowed_blocks = array_filter(
146-
is_array( $raw_blocks ) ? $raw_blocks : array(),
147-
'is_string'
148-
);
180+
$block_name = (string) ( $block['blockName'] ?? '' );
181+
$allowed_blocks = get_modal_trigger_allowed_blocks();
149182

150183
if ( '' === $block_name || ! in_array( $block_name, $allowed_blocks, true ) ) {
151184
return $block_content;

0 commit comments

Comments
 (0)