Skip to content

Commit

Permalink
Small cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauteri committed Dec 23, 2024
1 parent cc1829e commit e0e185c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 14 additions & 2 deletions includes/core/classes/blocks/class-rsvp-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class Rsvp_Template {
*/
use Singleton;

/**
* Constant representing the Block Name.
*
* @since 1.0.0
* @var string
*/
const BLOCK_NAME = 'gatherpress/rsvp-template';

/**
* Class constructor.
*
Expand Down Expand Up @@ -73,7 +81,7 @@ protected function setup_hooks(): void {
* @return string The filtered block content.
*/
public function ensure_block_styles_loaded( string $block_content, array $block ): string {
if ( 'gatherpress/rsvp-template' === $block['blockName'] ) {
if ( self::BLOCK_NAME === $block['blockName'] ) {
$block_instance = Block::get_instance();
$tag = new WP_HTML_Tag_Processor( $block_content );

Expand Down Expand Up @@ -130,7 +138,11 @@ public function render_block( array $attributes, string $content, WP_Block $bloc

if ( -1 === $response_id ) {
$blocks = wp_json_encode( $block->parsed_block );
$rsvp_response_template = '<div data-wp-interactive="gatherpress" data-wp-context=\'{ "postId": ' . intval( get_the_ID() ) . ' }\' data-wp-watch="callbacks.renderBlocks" data-blocks="' . esc_attr( $blocks ) . '"></div>';
$rsvp_response_template = sprintf(
'<div data-wp-interactive="gatherpress" data-wp-context=\'{ "postId": %d }\' data-wp-watch="callbacks.renderBlocks" data-blocks="%s"></div>',
intval( get_the_ID() ),
esc_attr( $blocks )
);
continue;
}

Expand Down
6 changes: 5 additions & 1 deletion includes/core/classes/blocks/class-rsvp.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ public function transform_block_content( string $block_content, array $block ):
// Render inner blocks for all statuses.
$inner_blocks_markup = '';
foreach ( $serialized_inner_blocks as $status => $serialized_inner_block ) {
$inner_blocks_markup .= '<div style="display:none;" data-rsvp-status="' . esc_attr( $status ) . '">' . do_blocks( $serialized_inner_block ) . '</div>';
$inner_blocks_markup .= sprintf(
'<div style="display:none;" data-rsvp-status="%s">%s</div>',
esc_attr( $status ),
do_blocks( $serialized_inner_block )
);
}

// Set dynamic attributes for interactivity.
Expand Down

0 comments on commit e0e185c

Please sign in to comment.