| 1 |
<?php |
| 2 |
/** |
| 3 |
* Standalone (theme_id 990) page-block shortcodes (generic adapter). |
| 4 |
* |
| 5 |
* One adapter that loops the page-block manifest and registers a |
| 6 |
* [mlsimport_<slug>] shortcode for every entry. Each shortcode maps its atts |
| 7 |
* (defaulted from the block's arg schema) and hands off to the one dispatcher — so |
| 8 |
* shortcode, Gutenberg block and Elementor widget all emit identical markup. |
| 9 |
* Adding a block needs no change here. See docs/adr/0007. |
| 10 |
* |
| 11 |
* @package Mlsimport |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
require_once __DIR__ . '/page-block-registry.php'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Registers a shortcode per registered page block. |
| 22 |
*/ |
| 23 |
class Mlsimport_Page_Block_Shortcodes { |
| 24 |
|
| 25 |
/** |
| 26 |
* Register one shortcode for every manifest entry. |
| 27 |
* |
| 28 |
* @return void |
| 29 |
*/ |
| 30 |
public static function register(): void { |
| 31 |
// One [mlsimport_<slug>] shortcode per manifest entry. |
| 32 |
foreach ( mlsimport_get_page_blocks() as $slug => $def ) { |
| 33 |
add_shortcode( |
| 34 |
'mlsimport_' . $slug, |
| 35 |
static function ( $atts ) use ( $slug ) { |
| 36 |
return self::render( $slug, $atts ); |
| 37 |
} |
| 38 |
); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Map shortcode atts (defaulted from the schema) to a page-block render. |
| 44 |
* |
| 45 |
* @param string $slug Block slug. |
| 46 |
* @param array|string $atts Shortcode attributes. |
| 47 |
* @return string |
| 48 |
*/ |
| 49 |
public static function render( string $slug, $atts ): string { |
| 50 |
$atts = shortcode_atts( mlsimport_page_block_defaults( $slug ), (array) $atts, 'mlsimport_' . $slug ); |
| 51 |
return mlsimport_render_page_block( $slug, $atts ); |
| 52 |
} |
| 53 |
} |
| 54 |
|