| 1 |
<?php |
| 2 |
/** |
| 3 |
* PHP render for Dropdown Block. |
| 4 |
* |
| 5 |
* @package SureDonation |
| 6 |
* @since 1.1.1 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace SureDonation\Inc\Blocks\Dropdown; |
| 10 |
|
| 11 |
use SureDonation\Inc\Blocks\Base; |
| 12 |
use SureDonation\Inc\Fields\Dropdown_Markup; |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; // Exit if accessed directly. |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Dropdown Block. |
| 20 |
* |
| 21 |
* @since 1.1.1 |
| 22 |
*/ |
| 23 |
class Block extends Base { |
| 24 |
/** |
| 25 |
* Render the block. |
| 26 |
* |
| 27 |
* @param array<string, mixed> $attributes Block attributes. |
| 28 |
* @param string $content Block content. |
| 29 |
* @return string |
| 30 |
* @since 1.1.1 |
| 31 |
*/ |
| 32 |
public function render( $attributes, $content = '' ) { |
| 33 |
unset( $content ); // Unused parameter. |
| 34 |
|
| 35 |
if ( empty( $attributes ) ) { |
| 36 |
return ''; |
| 37 |
} |
| 38 |
|
| 39 |
// Load tom-select and the dropdown initializer only when a dropdown is on |
| 40 |
// the page. suredonation-dropdown declares tom-select as a dependency, so |
| 41 |
// enqueuing it pulls the library in too, in the right order. |
| 42 |
wp_enqueue_style( 'suredonation-tom-select' ); |
| 43 |
wp_enqueue_script( 'suredonation-dropdown' ); |
| 44 |
|
| 45 |
$markup_class = new Dropdown_Markup( $attributes ); |
| 46 |
ob_start(); |
| 47 |
echo wp_kses( $markup_class->markup(), self::get_allowed_form_html() ); |
| 48 |
$output = ob_get_clean(); |
| 49 |
return false !== $output ? $output : ''; |
| 50 |
} |
| 51 |
} |
| 52 |
|