| 1 |
<?php |
| 2 |
/** |
| 3 |
* Widgetized area block. |
| 4 |
* |
| 5 |
* @package ghostkit |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Class GhostKit_Widgetized_Area_Block |
| 14 |
*/ |
| 15 |
class GhostKit_Widgetized_Area_Block { |
| 16 |
/** |
| 17 |
* GhostKit_Widgetized_Area_Block constructor. |
| 18 |
*/ |
| 19 |
public function __construct() { |
| 20 |
add_action( 'init', array( $this, 'init' ) ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Init. |
| 25 |
*/ |
| 26 |
public function init() { |
| 27 |
if ( function_exists( 'register_block_type' ) ) { |
| 28 |
register_block_type( 'ghostkit/widgetized-area', array( |
| 29 |
'render_callback' => array( $this, 'block_render' ), |
| 30 |
) ); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Register gutenberg block output |
| 36 |
* |
| 37 |
* @param array $attributes - block attributes. |
| 38 |
* |
| 39 |
* @return string |
| 40 |
*/ |
| 41 |
public function block_render( $attributes ) { |
| 42 |
ob_start(); |
| 43 |
|
| 44 |
$class = isset( $attributes['className'] ) ? $attributes['className'] : ''; |
| 45 |
$class .= ' ghostkit-widgetized-area'; |
| 46 |
|
| 47 |
if ( $attributes['id'] ) { |
| 48 |
echo '<div class="' . esc_attr( $class ) . '">'; |
| 49 |
dynamic_sidebar( $attributes['id'] ); |
| 50 |
echo '</div>'; |
| 51 |
} |
| 52 |
|
| 53 |
return ob_get_clean(); |
| 54 |
} |
| 55 |
} |
| 56 |
new GhostKit_Widgetized_Area_Block(); |
| 57 |
|