feat: prima versione del plugin, blocco e shortcode con iframe stampato lato server

This commit is contained in:
Lorenzo Iovino 2026-09-04 15:32:47 +02:00
commit 5c73bbc2b8
20 changed files with 1562 additions and 0 deletions

52
includes/block.php Normal file
View file

@ -0,0 +1,52 @@
<?php
/**
* The editor block. Dynamic: the markup is produced by PHP at render time, so
* the events are always the ones of today and never a copy frozen in the post
* content.
*
* @package PiazzaInFesta
*/
defined( 'ABSPATH' ) || exit;
/**
* Registers the block from its block.json.
*
* @return void
*/
function pinfesta_register_block() {
$type = register_block_type(
PINFESTA_DIR . 'blocks/eventi',
array( 'render_callback' => 'pinfesta_render_block' )
);
// The editor strings live in JavaScript, so they need their own JSON
// catalogue. The handle is read back from the registered block instead of
// being guessed: WordPress builds it from block.json and it can change.
if ( $type && ! empty( $type->editor_script_handles ) ) {
foreach ( $type->editor_script_handles as $handle ) {
wp_set_script_translations( $handle, 'piazza-in-festa', PINFESTA_DIR . 'languages' );
}
}
}
add_action( 'init', 'pinfesta_register_block' );
/**
* Renders the block on the front end and in the editor preview.
*
* @param array $attributes Block attributes.
* @return string HTML.
*/
function pinfesta_render_block( $attributes ) {
$args = wp_parse_args( (array) $attributes, pinfesta_defaults() );
$html = pinfesta_render_iframe( $args );
if ( '' === $html ) {
return '';
}
$wrapper = get_block_wrapper_attributes();
return '<div' . ( '' === $wrapper ? '' : ' ' . $wrapper ) . '>' . $html . '</div>';
}