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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ node_modules/

# dotenv environment variables file
.env

# Composer
composer.lock
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.8",
"version": "1.0.9",
"slug": "blockparty-modal"
}
2 changes: 1 addition & 1 deletion .wordpress-org/blueprints/blueprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"pluginData": {
"resource": "git:directory",
"url": "https://github.com/BeAPI/blockparty-modal",
"ref": "1.0.8",
"ref": "1.0.9",
"refType": "tag"
},
"options": {
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.9]

* Fix `blockparty_modal_inner_allowed_blocks` and `blockparty_modal_trigger_allowed_blocks` filters not being applied in the block editor on recent WordPress versions.
* Pass allowed block lists to the editor script via `wp_localize_script` so they are available despite the block editor settings allowlist.

## [1.0.8]

* Add GitHub Actions check and `tests/bin/check-release-version.sh` to validate that release version bumps are consistent across all versioned files.
Expand Down
85 changes: 59 additions & 26 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.8
* Version: 1.0.9
* 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.8' );
define( 'BLOCKPARTY_MODAL_VERSION', '1.0.9' );
define( 'BLOCKPARTY_MODAL_URL', plugin_dir_url( __FILE__ ) );
define( 'BLOCKPARTY_MODAL_DIR', plugin_dir_path( __FILE__ ) );

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

/**
* Passes the list of blocks allowed as modal triggers to the block editor settings
* so the "Attached modal" panel is only shown for those blocks.
* Returns the filtered list of blocks allowed inside the modal block.
*
* @param array<array-key, mixed> $settings Block editor settings.
* @param \WP_Block_Editor_Context $_context Block editor context (unused).
* @return array<array-key, mixed> Modified settings.
* @return string[] Block names.
*/
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.
function get_modal_inner_allowed_blocks(): array {
/** @psalm-suppress MixedAssignment */
$raw = apply_filters(
'blockparty_modal_trigger_allowed_blocks',
get_default_modal_trigger_allowed_blocks()
'blockparty_modal_inner_allowed_blocks',
get_default_modal_inner_allowed_blocks()
);
$settings['blockpartyModalTriggerAllowedBlocks'] = array_values(

return array_values(
array_filter( is_array( $raw ) ? $raw : [], 'is_string' )
);
}

/**
* Returns the filtered list of blocks allowed as modal triggers.
*
* @return string[] Block names.
*/
function get_modal_trigger_allowed_blocks(): array {
/** @psalm-suppress MixedAssignment */
$inner_raw = apply_filters(
'blockparty_modal_inner_allowed_blocks',
get_default_modal_inner_allowed_blocks()
$raw = apply_filters(
'blockparty_modal_trigger_allowed_blocks',
get_default_modal_trigger_allowed_blocks()
);
$settings['blockpartyModalInnerAllowedBlocks'] = array_values(
array_filter( is_array( $inner_raw ) ? $inner_raw : [], 'is_string' )

return array_values(
array_filter( is_array( $raw ) ? $raw : [], 'is_string' )
);
}

/**
* Passes allowed-block lists to the block editor script.
*
* Custom keys added via block_editor_settings_all are stripped by the editor
* allowlist in recent WordPress versions, so the lists are localized here.
*/
function enqueue_block_editor_data(): void {
if ( ! wp_script_is( 'blockparty-modal-editor-script', 'registered' ) ) {
return;
}

wp_localize_script(
'blockparty-modal-editor-script',
'blockpartyModalEditorSettings',
[
'innerAllowedBlocks' => get_modal_inner_allowed_blocks(),
'triggerAllowedBlocks' => get_modal_trigger_allowed_blocks(),
]
);
}

add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\enqueue_block_editor_data', 20 );

/**
* Passes allowed-block lists to block editor settings (legacy path).
*
* @param array<array-key, mixed> $settings Block editor settings.
* @param \WP_Block_Editor_Context $_context Block editor context (unused).
* @return array<array-key, mixed> Modified settings.
*/
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.
$settings['blockpartyModalTriggerAllowedBlocks'] = get_modal_trigger_allowed_blocks();
$settings['blockpartyModalInnerAllowedBlocks'] = get_modal_inner_allowed_blocks();

return $settings;
}
Expand Down Expand Up @@ -136,16 +177,8 @@ function render_block_add_modal_trigger( $block_content, array $block ) {
return $block_content;
}

$block_name = (string) ( $block['blockName'] ?? '' );
/** @psalm-suppress MixedAssignment */
$raw_blocks = apply_filters(
'blockparty_modal_trigger_allowed_blocks',
get_default_modal_trigger_allowed_blocks()
);
$allowed_blocks = array_filter(
is_array( $raw_blocks ) ? $raw_blocks : array(),
'is_string'
);
$block_name = (string) ( $block['blockName'] ?? '' );
$allowed_blocks = get_modal_trigger_allowed_blocks();

if ( '' === $block_name || ! in_array( $block_name, $allowed_blocks, true ) ) {
return $block_content;
Expand Down
Loading
Loading