| 1 |
<?php |
| 2 |
if ( !defined( 'ABSPATH' ) ) { exit; } |
| 3 |
|
| 4 |
$btnbId = wp_unique_id( 'btnButton-' ); |
| 5 |
|
| 6 |
// Extract attributes with defaults |
| 7 |
$btnbIcon = isset( $attributes['icon'] ) ? (array) $attributes['icon'] : []; |
| 8 |
$btnbAnimationType = isset( $attributes['animationType'] ) ? sanitize_text_field( $attributes['animationType'] ) : ''; |
| 9 |
$btnbUrl = isset( $attributes['url'] ) ? esc_url_raw( $attributes['url'] ) : ''; |
| 10 |
$btnbPopup = isset( $attributes['popup'] ) ? (array) $attributes['popup'] : [ 'type' => 'image', 'content' => '', 'caption' => '' ]; |
| 11 |
|
| 12 |
if( isset( $btnbIcon['class'] ) && !empty( $btnbIcon['class'] ) ){ |
| 13 |
wp_enqueue_style( 'font-awesome-7' ); |
| 14 |
} |
| 15 |
if( !empty( $btnbAnimationType ) ){ |
| 16 |
wp_enqueue_script( 'aos' ); |
| 17 |
wp_enqueue_style( 'aos' ); |
| 18 |
} |
| 19 |
|
| 20 |
$attributes['url'] = esc_url( $btnbUrl ); |
| 21 |
if ( 'content' === $btnbPopup['type'] ) { |
| 22 |
$btnbContentBlocks = parse_blocks( $btnbPopup['content'] ?? '' ); |
| 23 |
$btnbPopup['content'] = ''; |
| 24 |
foreach ( $btnbContentBlocks as $btnbContentBlock ) { |
| 25 |
$btnbPopup['content'] .= render_block( $btnbContentBlock ); |
| 26 |
} |
| 27 |
} // Convert the blocks to dom elements |
| 28 |
?> |
| 29 |
<div |
| 30 |
<?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_block_wrapper_attributes() is properly escaped ?> |
| 31 |
<?php echo get_block_wrapper_attributes(); ?> |
| 32 |
id='<?php echo esc_attr( $btnbId ); ?>' |
| 33 |
<?php |
| 34 |
$btnbAttributes = $attributes; |
| 35 |
if ( isset( $btnbAttributes['securityPassword'] ) ) { |
| 36 |
unset( $btnbAttributes['securityPassword'] ); |
| 37 |
} |
| 38 |
?> |
| 39 |
data-attributes='<?php echo esc_attr( wp_json_encode( $btnbAttributes ?? [] ) ); ?>' |
| 40 |
></div> |