PluginProbe
Elementor Website Builder – more than just a page builder / 3.34.1
Elementor Website Builder – more than just a page builder v3.34.1
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.34.1, at modules/variables/hooks.php

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