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

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