| 1 |
<?php |
| 2 |
/** |
| 3 |
* Standalone (theme_id 990) single-property section shortcodes (generic adapter). |
| 4 |
* |
| 5 |
* One adapter that loops the section manifest and registers a |
| 6 |
* [mlsimport_property_<slug>] shortcode for every entry. Each shortcode resolves |
| 7 |
* the property (optional id att; otherwise the loop post) and hands off to the |
| 8 |
* one dispatcher — so the shortcode, block and Elementor widget all emit the |
| 9 |
* same markup. Adding a section needs no change here. See docs/adr/0005. |
| 10 |
* |
| 11 |
* @package Mlsimport |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
require_once __DIR__ . '/property-section-registry.php'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Registers a shortcode per registered property section. |
| 22 |
*/ |
| 23 |
class Mlsimport_Property_Section_Shortcodes { |
| 24 |
|
| 25 |
/** |
| 26 |
* Register one shortcode for every manifest entry. |
| 27 |
* |
| 28 |
* @return void |
| 29 |
*/ |
| 30 |
public static function register(): void { |
| 31 |
mlsimport_register_builtin_property_sections(); |
| 32 |
|
| 33 |
foreach ( array_keys( mlsimport_get_property_sections() ) as $slug ) { |
| 34 |
add_shortcode( |
| 35 |
'mlsimport_property_' . $slug, |
| 36 |
static function ( $atts ) use ( $slug ) { |
| 37 |
return self::render( $slug, $atts ); |
| 38 |
} |
| 39 |
); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Map shortcode atts to a section render. |
| 45 |
* |
| 46 |
* @param string $slug Section slug. |
| 47 |
* @param array|string $atts Shortcode attributes. |
| 48 |
* @return string |
| 49 |
*/ |
| 50 |
public static function render( string $slug, $atts ): string { |
| 51 |
$atts = shortcode_atts( array( 'id' => 0 ), (array) $atts, 'mlsimport_property_' . $slug ); |
| 52 |
return mlsimport_render_property_section( $slug, (int) $atts['id'] ); |
| 53 |
} |
| 54 |
} |
| 55 |
|