PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.3
Elementor Website Builder – more than just a page builder v3.35.3
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / variables / hooks.php

hooks.php in Elementor Website Builder – more than just a page builder 3.35.3, at modules/variables/hooks.php

134 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\Variables;
4
5 use Elementor\Modules\Variables\Adapters\Prop_Type_Adapter;
6 use Elementor\Modules\Variables\Classes\Variable_Types_Registry;
7 use Elementor\Modules\Variables\PropTypes\Color_Variable_Prop_Type;
8 use Elementor\Modules\Variables\PropTypes\Font_Variable_Prop_Type;
9 use Elementor\Modules\Variables\PropTypes\Size_Variable_Prop_Type;
10 use Elementor\Modules\Variables\Services\Batch_Operations\Batch_Processor;
11 use Elementor\Modules\Variables\Services\Variables_Service;
12 use Elementor\Modules\Variables\Storage\Variables_Repository;
13 use Elementor\Plugin;
14 use Elementor\Core\Files\CSS\Post as Post_CSS;
15 use Elementor\Modules\Variables\Classes\CSS_Renderer as Variables_CSS_Renderer;
16 use Elementor\Modules\Variables\Classes\Fonts;
17 use Elementor\Modules\Variables\Classes\Rest_Api as Variables_API;
18 use Elementor\Modules\Variables\Classes\Style_Schema;
19 use Elementor\Modules\Variables\Classes\Size_Style_Schema;
20 use Elementor\Modules\Variables\Classes\Style_Transformers;
21 use Elementor\Modules\Variables\Classes\Variables;
22
23 if ( ! defined( 'ABSPATH' ) ) {
24 exit; // Exit if accessed directly.
25 }
26
27 class Hooks {
28 const PACKAGES = [
29 'editor-variables',
30 ];
31
32 public function register() {
33 $this->register_styles_transformers()
34 ->register_css_renderer()
35 ->register_packages()
36 ->register_fonts()
37 ->register_api_endpoints()
38 ->filter_for_style_schema()
39 ->register_variable_types();
40
41 return $this;
42 }
43
44 private function register_variable_types() {
45 add_action( 'elementor/variables/register', function ( Variable_Types_Registry $registry ) {
46 $registry->register( Color_Variable_Prop_Type::get_key(), new Color_Variable_Prop_Type() );
47 $registry->register( Font_Variable_Prop_Type::get_key(), new Font_Variable_Prop_Type() );
48 $registry->register( Prop_Type_Adapter::GLOBAL_CUSTOM_SIZE_VARIABLE_KEY, new Size_Variable_Prop_Type() );
49 $registry->register( Size_Variable_Prop_Type::get_key(), new Size_Variable_Prop_Type() );
50 } );
51
52 return $this;
53 }
54
55 private function register_packages() {
56 add_filter( 'elementor/editor/v2/packages', function ( $packages ) {
57 return array_merge( $packages, self::PACKAGES );
58 } );
59
60 return $this;
61 }
62
63 private function register_styles_transformers() {
64 add_action( 'elementor/atomic-widgets/styles/transformers/register', function ( $registry ) {
65 Variables::init( $this->variables_service() );
66 ( new Style_Transformers() )->append_to( $registry );
67 } );
68
69 return $this;
70 }
71
72 private function filter_for_style_schema() {
73 add_filter( 'elementor/atomic-widgets/styles/schema', function ( array $schema ) {
74 return ( new Style_Schema() )->augment( $schema );
75 } );
76
77 add_filter( 'elementor/atomic-widgets/styles/schema', function ( array $schema ) {
78 return ( new Size_Style_Schema() )->augment( $schema );
79 } );
80
81 return $this;
82 }
83
84 private function css_renderer() {
85 return new Variables_CSS_Renderer( $this->variables_service() );
86 }
87
88 private function register_css_renderer() {
89 add_action( 'elementor/css-file/post/parse', function ( Post_CSS $post_css ) {
90 if ( ! Plugin::$instance->kits_manager->is_kit( $post_css->get_post_id() ) ) {
91 return;
92 }
93
94 $post_css->get_stylesheet()->add_raw_css(
95 $this->css_renderer()->raw_css()
96 );
97 } );
98
99 return $this;
100 }
101
102 private function fonts() {
103 return new Fonts( $this->variables_service() );
104 }
105
106 private function register_fonts() {
107 add_action( 'elementor/css-file/post/parse', function ( $post_css ) {
108 $this->fonts()->append_to( $post_css );
109 } );
110
111 return $this;
112 }
113
114 private function rest_api() {
115 return new Variables_API( $this->variables_service() );
116 }
117
118 private function register_api_endpoints() {
119 add_action( 'rest_api_init', function () {
120 $this->rest_api()->register_routes();
121 } );
122
123 return $this;
124 }
125
126 private function variables_service() {
127 $repository = new Variables_Repository(
128 Plugin::$instance->kits_manager->get_active_kit()
129 );
130
131 return new Variables_Service( $repository, new Batch_Processor() );
132 }
133 }
134