| 1 |
<?php |
| 2 |
/** |
| 3 |
* Server-side rendering of the `gutenify/social` block. |
| 4 |
* |
| 5 |
* @package Gutenify |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Map Block render |
| 10 |
* |
| 11 |
* @param array $attributes Map Attributes. |
| 12 |
* @return string |
| 13 |
*/ |
| 14 |
function gutenify_render_count_down_block( $attributes ) { |
| 15 |
$client_id = ! empty( $attributes['blockClientId'] ) ? $attributes['blockClientId'] : ''; |
| 16 |
$align = ! empty( $attributes['align'] ) ? $attributes['align'] : 'full'; |
| 17 |
$class = ! empty( $attributes['className'] ) ? $attributes['className'] : ''; |
| 18 |
$class = 'wp-block-gutenify-map align' . $align . ' ' . $class; |
| 19 |
$location = ! empty( $attributes['location'] ) ? $attributes['location'] : ''; |
| 20 |
$language = ! empty( $attributes['language'] ) ? $attributes['language'] : 'en'; |
| 21 |
$zoom = ! empty( $attributes['zoom'] ) ? $attributes['zoom'] : 12; |
| 22 |
$height = ! empty( $attributes['height'] ) ? $attributes['height'] : 400; |
| 23 |
|
| 24 |
return '<div class="' . $class . '"><div id="gutenify-section-' . $client_id . '"><iframe title="Google Map" frameBorder="0" src="https://www.google.com/maps?q=' . $location . '&output=embed&hl=' . $language . '&z=' . $zoom . '" style="width:100%;min-height:' . $height . 'px"></iframe></div></div>'; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Registers the block on server. |
| 29 |
*/ |
| 30 |
function gutenify_register_count_down_block() { |
| 31 |
// Return early if this function does not exist. |
| 32 |
if ( ! function_exists( 'register_block_type' ) ) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
// Load attributes from block.json. |
| 37 |
ob_start(); |
| 38 |
include GUTENIFY_PLUGIN_DIR . 'src/blocks/count-down/block.json'; |
| 39 |
$metadata = json_decode( ob_get_clean(), true ); |
| 40 |
|
| 41 |
register_block_type( |
| 42 |
'gutenify/count-down', |
| 43 |
array( |
| 44 |
'editor_script' => 'gutenify-editor', |
| 45 |
'editor_style' => 'gutenify-editor', |
| 46 |
'style' => 'gutenify-frontend', |
| 47 |
'attributes' => $metadata['attributes'], |
| 48 |
'render_callback' => 'gutenify_render_count_down_block', |
| 49 |
) |
| 50 |
); |
| 51 |
} |
| 52 |
add_action( 'init', 'gutenify_register_count_down_block' ); |
| 53 |
|