PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.5.6.3
JetFormBuilder — Dynamic Blocks Form Builder v3.5.6.3
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 / jet-style / module.php
jetformbuilder / modules / jet-style Last commit date
assets 2 years ago css-compilers 2 years ago css-compiler-manager.php 2 years ago module.php 1 year ago
module.php
142 lines
1 <?php
2
3
4 namespace JFB_Modules\Jet_Style;
5
6 use Jet_Form_Builder\Classes\Arrayable\Array_Tools;
7 use JFB_Components\Module\Base_Module_After_Install_It;
8 use JFB_Components\Module\Base_Module_Dir_It;
9 use JFB_Components\Module\Base_Module_Dir_Trait;
10 use JFB_Components\Module\Base_Module_Handle_It;
11 use JFB_Components\Module\Base_Module_Handle_Trait;
12 use JFB_Components\Module\Base_Module_It;
13 use JFB_Components\Module\Base_Module_Url_It;
14 use JFB_Components\Module\Base_Module_Url_Trait;
15
16 // If this file is called directly, abort.
17 if ( ! defined( 'WPINC' ) ) {
18 die;
19 }
20
21 /**
22 * @since 3.1.0
23 *
24 * Class Module
25 * @package JFB_Modules\Jet_Style
26 */
27 class Module implements
28 Base_Module_It,
29 Base_Module_Handle_It,
30 Base_Module_Url_It,
31 Base_Module_After_Install_It,
32 Base_Module_Dir_It {
33
34 use Base_Module_Url_Trait;
35 use Base_Module_Handle_Trait;
36 use Base_Module_Dir_Trait;
37
38 const SUPPORT_NAME = 'jetStyle';
39
40 /**
41 * @var Css_Compiler_Manager
42 */
43 private $compiler;
44
45 public function rep_item_id() {
46 return 'jet-style';
47 }
48
49 public function condition(): bool {
50 // since WP 6.2
51 return class_exists( '\WP_HTML_Tag_Processor' );
52 }
53
54 public function on_install() {
55 $this->compiler = new Css_Compiler_Manager();
56
57 \WP_Block_Supports::get_instance()->register(
58 self::SUPPORT_NAME,
59 array(
60 'register_attribute' => array( $this, 'register_support' ),
61 'apply' => array( $this, 'apply_support' ),
62 )
63 );
64 }
65
66 public function on_uninstall() {
67 unset( $this->compiler );
68
69 \WP_Block_Supports::get_instance()->register( self::SUPPORT_NAME, array() );
70 }
71
72 public function init_hooks() {
73 add_action(
74 'jet-form-builder/editor-assets/before',
75 array( $this, 'register_scripts' ),
76 0
77 );
78 }
79
80 public function remove_hooks() {
81 remove_action(
82 'jet-form-builder/editor-assets/before',
83 array( $this, 'register_scripts' ),
84 0
85 );
86 }
87
88 public function register_scripts() {
89 $script_asset = require_once $this->get_dir( 'assets/build/editor.asset.php' );
90
91 if ( true === $script_asset ) {
92 return;
93 }
94
95 wp_enqueue_script(
96 $this->get_handle(),
97 $this->get_url( 'assets/build/editor.js' ),
98 $script_asset['dependencies'],
99 $script_asset['version'],
100 true
101 );
102 }
103
104 public function register_support( \WP_Block_Type $block_type ) {
105 // Setup attributes and styles within that if needed.
106 if ( ! $block_type->attributes ) {
107 $block_type->attributes = array();
108 }
109
110 if ( block_has_support( $block_type, array( self::SUPPORT_NAME ) ) &&
111 ! array_key_exists( 'style', $block_type->attributes )
112 ) {
113 $block_type->attributes['style'] = array(
114 'type' => 'object',
115 );
116 }
117 }
118
119 public function apply_support( \WP_Block_Type $block_type, array $block_attributes ): array {
120
121 if ( ! is_array( $block_type->supports ) ) {
122 return array();
123 }
124
125 $support_config = Array_Tools::get( $block_type->supports, array( self::SUPPORT_NAME ), false );
126 $root_styles = $block_attributes['style'] ?? array();
127
128 if (
129 ! is_array( $support_config ) ||
130 empty( $root_styles )
131 ) {
132 return array();
133 }
134
135 return $this->get_compiler()->compile( $root_styles, $support_config );
136 }
137
138 public function get_compiler(): Css_Compiler_Manager {
139 return $this->compiler;
140 }
141 }
142