PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / trunk
JetFormBuilder — Dynamic Blocks Form Builder vtrunk
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 1 month ago css-compilers 2 years ago css-compiler-manager.php 2 years ago module.php 2 months ago style-manager.php 2 months ago
module.php
145 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
56 Style_Manager::instance();
57
58 $this->compiler = new Css_Compiler_Manager();
59
60 \WP_Block_Supports::get_instance()->register(
61 self::SUPPORT_NAME,
62 array(
63 'register_attribute' => array( $this, 'register_support' ),
64 'apply' => array( $this, 'apply_support' ),
65 )
66 );
67 }
68
69 public function on_uninstall() {
70 unset( $this->compiler );
71
72 \WP_Block_Supports::get_instance()->register( self::SUPPORT_NAME, array() );
73 }
74
75 public function init_hooks() {
76 add_action(
77 'jet-form-builder/editor-assets/before',
78 array( $this, 'register_scripts' ),
79 0
80 );
81 }
82
83 public function remove_hooks() {
84 remove_action(
85 'jet-form-builder/editor-assets/before',
86 array( $this, 'register_scripts' ),
87 0
88 );
89 }
90
91 public function register_scripts() {
92 $script_asset = require_once $this->get_dir( 'assets/build/editor.asset.php' );
93
94 if ( true === $script_asset ) {
95 return;
96 }
97
98 wp_enqueue_script(
99 $this->get_handle(),
100 $this->get_url( 'assets/build/editor.js' ),
101 $script_asset['dependencies'],
102 $script_asset['version'],
103 true
104 );
105 }
106
107 public function register_support( \WP_Block_Type $block_type ) {
108 // Setup attributes and styles within that if needed.
109 if ( ! $block_type->attributes ) {
110 $block_type->attributes = array();
111 }
112
113 if ( block_has_support( $block_type, array( self::SUPPORT_NAME ) ) &&
114 ! array_key_exists( 'style', $block_type->attributes )
115 ) {
116 $block_type->attributes['style'] = array(
117 'type' => 'object',
118 );
119 }
120 }
121
122 public function apply_support( \WP_Block_Type $block_type, array $block_attributes ): array {
123
124 if ( ! is_array( $block_type->supports ) ) {
125 return array();
126 }
127
128 $support_config = Array_Tools::get( $block_type->supports, array( self::SUPPORT_NAME ), false );
129 $root_styles = $block_attributes['style'] ?? array();
130
131 if (
132 ! is_array( $support_config ) ||
133 empty( $root_styles )
134 ) {
135 return array();
136 }
137
138 return $this->get_compiler()->compile( $root_styles, $support_config );
139 }
140
141 public function get_compiler(): Css_Compiler_Manager {
142 return $this->compiler;
143 }
144 }
145