| 1 |
<?php |
| 2 |
/** |
| 3 |
* Module: Layouts Blocks. |
| 4 |
* |
| 5 |
* @package Orderable/Classes |
| 6 |
*/ |
| 7 |
|
| 8 |
defined( 'ABSPATH' ) || exit; |
| 9 |
|
| 10 |
/** |
| 11 |
* Layouts blocks class. |
| 12 |
*/ |
| 13 |
class Orderable_Layouts_Blocks { |
| 14 |
/** |
| 15 |
* Init. |
| 16 |
*/ |
| 17 |
public static function run() { |
| 18 |
add_action( 'init', array( __CLASS__, 'register_blocks' ) ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Register blocks. |
| 23 |
*/ |
| 24 |
public static function register_blocks() { |
| 25 |
if ( ! function_exists( 'register_block_type' ) ) { |
| 26 |
return; |
| 27 |
} |
| 28 |
|
| 29 |
wp_register_script( |
| 30 |
'orderable-layout', |
| 31 |
ORDERABLE_URL . 'inc/modules/layouts/assets/admin/js/block-layout.js', |
| 32 |
array( |
| 33 |
'wp-blocks', |
| 34 |
'wp-i18n', |
| 35 |
'wp-element', |
| 36 |
'wp-components', |
| 37 |
'wp-editor', |
| 38 |
), |
| 39 |
ORDERABLE_VERSION |
| 40 |
); |
| 41 |
|
| 42 |
wp_localize_script( |
| 43 |
'orderable-layout', |
| 44 |
'orderable_vars', |
| 45 |
array( |
| 46 |
'admin_url' => get_admin_url(), |
| 47 |
) |
| 48 |
); |
| 49 |
|
| 50 |
register_block_type( |
| 51 |
'orderable/layout', |
| 52 |
array( |
| 53 |
'editor_script' => 'orderable-layout', |
| 54 |
'render_callback' => array( __CLASS__, 'layout_block_handler' ), |
| 55 |
'attributes' => array( |
| 56 |
'id' => array( |
| 57 |
'default' => '0', |
| 58 |
'type' => 'string', |
| 59 |
), |
| 60 |
'layoutIds' => array( |
| 61 |
'default' => new stdClass(), |
| 62 |
'type' => 'object', |
| 63 |
), |
| 64 |
), |
| 65 |
) |
| 66 |
); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Handle block: Layout. |
| 71 |
*/ |
| 72 |
public static function layout_block_handler( $args = array() ) { |
| 73 |
$layout_settings = Orderable_Layouts::get_layout_settings( $args['id'] ); |
| 74 |
|
| 75 |
return Orderable_Layouts::orderable_shortcode( $layout_settings ); |
| 76 |
} |
| 77 |
} |
| 78 |
|