PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / trunk
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster vtrunk
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / includes / block-editor / blocks / smart-coupon / index.php

index.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster trunk, at includes/block-editor/blocks/smart-coupon/index.php

101 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Sellkit\Blocks\Render;
3
4 use Sellkit\Blocks\Sellkit_Blocks;
5
6 /**
7 * Smart Coupon block.
8 *
9 * @since 2.3.0
10 */
11 class Smart_Coupon {
12 /**
13 * Check block activation.
14 *
15 * @since 2.3.0
16 * @return boolean
17 */
18 public function is_active() {
19 return true;
20 }
21
22 /**
23 * Register block from meta.
24 *
25 * @since 2.3.0
26 */
27 public function register_block_meta() {
28 register_block_type_from_metadata(
29 __DIR__,
30 [
31 'render_callback' => [ $this, 'render' ],
32 ]
33 );
34 }
35
36 /**
37 * Check block has inner blocks.
38 *
39 * @since 2.3.0
40 * @return boolean
41 */
42 public function has_inner_blocks() {
43 return true;
44 }
45
46 /**
47 * Check block has inner blocks.
48 *
49 * @since 2.3.0
50 * @return boolean
51 */
52 public function get_inner_block() {
53 return [
54 'smart-coupon-code' => 'block-editor/blocks/smart-coupon/inner-blocks/smart-coupon-code/class',
55 'smart-coupon-expiration' => 'block-editor/blocks/smart-coupon/inner-blocks/smart-coupon-expiration/class',
56 ];
57 }
58
59
60 /**
61 * Render block in front-end.
62 *
63 * @param array $attributes Block attributes.
64 * @param string $content Block content.
65 * @param \WP_Block $block Block object.
66 * @since 2.3.0
67 * @return string
68 */
69 public function render( $attributes, $content, $block ) {
70 $block_html = '';
71 $wrapper_attributes = get_block_wrapper_attributes();
72
73 foreach ( $block->inner_blocks as $inner_block ) {
74 $block_name = str_replace( 'sellkit-inner-blocks/', '', $inner_block->parsed_block['blockName'] );
75 $block_name = str_replace( '-', ' ', $block_name );
76 $block_name = ucwords( $block_name );
77 $block_name = str_replace(' ', '_', $block_name );
78 $block_content = $inner_block->render();
79 $class_name = 'Sellkit\Blocks\Inner_Block\\' . ucwords( $block_name );
80
81 if ( ! class_exists( $class_name ) ) {
82 $block_html .= $inner_block->render();
83 continue;
84 }
85 $new_class = new $class_name();
86
87 if ( method_exists( $new_class, $block_name ) ) {
88 $block_html .= $new_class->$block_name( $block_content );
89 }
90 }
91
92 $block_html = sprintf(
93 '<div %1$s>%2$s</div>',
94 wp_kses_data( $wrapper_attributes ),
95 wp_kses_post( $block_html )
96 );
97
98 return $block_html;
99 }
100 }
101