PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.1
JetFormBuilder — Dynamic Blocks Form Builder v3.1.1
3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / block-sanitizer / module.php
jetformbuilder / modules / block-sanitizer Last commit date
base-block-sanitizer.php 3 years ago module.php 3 years ago
module.php
108 lines
1 <?php
2
3
4 namespace JFB_Modules\Block_Sanitizer;
5
6 use JFB_Components\Module\Base_Module_It;
7 use Jet_Form_Builder\Blocks\Block_Helper;
8
9 // If this file is called directly, abort.
10 if ( ! defined( 'WPINC' ) ) {
11 die;
12 }
13
14 /**
15 * The creation of this class is determined by the block rendering logic.
16 * Because it happens from the depths to the surface.
17 *
18 * The task was to throw the prepared value in the attribute into the child blocks.
19 * But the `render_callback` of the main block is run after the children,
20 * so changing the attributes for further transmission to the context makes no sense.
21 *
22 * The solution is to change the attributes on the `render_block_data' hook,
23 * because it is run in the correct order of block rendering - from top to bottom.
24 *
25 * @since 3.1.0
26 *
27 * Class Module
28 * @package Jet_Form_Builder\Blocks\Block_Sanitizer
29 */
30 final class Module implements Base_Module_It {
31
32 /**
33 * @var Base_Block_Sanitizer[]
34 */
35 private $sanitizers = array();
36
37 public function condition(): bool {
38 return true;
39 }
40
41 public function rep_item_id() {
42 return 'block-sanitizer';
43 }
44
45 public function init_hooks() {
46 add_filter(
47 'render_block_data',
48 array( $this, 'apply_blocks_data' ),
49 10,
50 2
51 );
52 }
53
54 public function remove_hooks() {
55 remove_filter(
56 'render_block_data',
57 array( $this, 'apply_blocks_data' )
58 );
59 }
60
61 public function apply_blocks_data( array $block_data, array $initial_block ): array {
62 $name = $initial_block['blockName'] ?? '';
63
64 // is has 'jet-forms/' namespace in 'blockName' property
65 if ( ! is_string( $name ) || ! Block_Helper::is_field( $name ) ) {
66 return $block_data;
67 }
68
69 $block_type = \WP_Block_Type_Registry::get_instance()->get_registered( $name );
70
71 if ( ! ( $block_type instanceof \WP_Block_Type ) ) {
72 return $block_data;
73 }
74
75 $name = Block_Helper::delete_namespace( $name );
76
77 foreach ( $this->sanitizers as $item ) {
78 if ( ! in_array( $name, $item->for_blocks(), true ) ) {
79 continue;
80 }
81
82 $block_data = $item->apply_data( $block_data );
83 }
84
85 return $block_data;
86 }
87
88 public function register( Base_Block_Sanitizer $item ): Module {
89 $this->sanitizers[] = $item;
90
91 return $this;
92 }
93
94 public function unregister( Base_Block_Sanitizer $item ): Module {
95 foreach ( $this->sanitizers as $index => $sanitizer ) {
96 if ( get_class( $sanitizer ) !== get_class( $item ) ) {
97 continue;
98 }
99 unset( $this->sanitizers[ $index ] );
100 }
101
102 $this->sanitizers = array_values( $this->sanitizers );
103
104 return $this;
105 }
106
107 }
108