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

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