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 / module.php

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

106 lines 3.1 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\Core\Base\Module as BaseModule;
6 use Elementor\Core\Experiments\Manager as ExperimentsManager;
7 use Elementor\Modules\AtomicWidgets\Module as AtomicWidgetsModule;
8 use Elementor\Modules\Variables\Classes\Variable_Types_Registry;
9 use Elementor\Modules\Variables\PropTypes\Color_Variable_Prop_Type;
10 use Elementor\Modules\Variables\PropTypes\Font_Variable_Prop_Type;
11 use Elementor\Modules\Variables\PropTypes\Size_Variable_Prop_Type;
12 use Elementor\Plugin;
13 use Elementor\Utils;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 class Module extends BaseModule {
20 const MODULE_NAME = 'e-variables';
21 const EXPERIMENT_NAME = 'e_variables';
22 const EXPERIMENT_MANAGER_NAME = 'e_variables_manager';
23
24 private Variable_Types_Registry $variable_types_registry;
25
26 public function get_name() {
27 return self::MODULE_NAME;
28 }
29
30 public static function get_experimental_data(): array {
31 return [
32 'name' => self::EXPERIMENT_NAME,
33 'title' => esc_html__( 'Variables', 'elementor' ),
34 'description' => esc_html__( 'Enable variables. (For this feature to work - Atomic Widgets must be active)', 'elementor' ),
35 'hidden' => true,
36 'default' => ExperimentsManager::STATE_ACTIVE,
37 'release_status' => ExperimentsManager::RELEASE_STATUS_ALPHA,
38 ];
39 }
40
41 private function hooks() {
42 return new Hooks();
43 }
44
45 public function __construct() {
46 parent::__construct();
47
48 if ( ! $this->is_experiment_active() ) {
49 return;
50 }
51 $this->register_features();
52
53 $this->hooks()->register();
54
55 add_action( 'init', [ $this, 'init_variable_types_registry' ] );
56 add_action( 'elementor/editor/before_enqueue_scripts', fn () => $this->enqueue_editor_scripts() );
57 }
58
59 private function register_features() {
60 Plugin::$instance->experiments->add_feature([
61 'name' => self::EXPERIMENT_MANAGER_NAME,
62 'title' => esc_html__( 'Variables Manager', 'elementor' ),
63 'description' => esc_html__( 'Enable variables manager. (For this feature to work - Variables must be active)', 'elementor' ),
64 'hidden' => true,
65 'default' => ExperimentsManager::STATE_ACTIVE,
66 'release_status' => ExperimentsManager::RELEASE_STATUS_ALPHA,
67 ]);
68 }
69
70 private function is_experiment_active(): bool {
71 return Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_NAME )
72 && Plugin::$instance->experiments->is_feature_active( AtomicWidgetsModule::EXPERIMENT_NAME );
73 }
74
75 public function init_variable_types_registry(): void {
76 $this->variable_types_registry = new Variable_Types_Registry();
77
78 do_action( 'elementor/variables/register', $this->variable_types_registry );
79 }
80
81
82 public function get_variable_types_registry(): Variable_Types_Registry {
83 return $this->variable_types_registry;
84 }
85
86 private function get_quota_config(): array {
87 return [
88 Color_Variable_Prop_Type::get_key() => 100000,
89 Font_Variable_Prop_Type::get_key() => 100000,
90 Size_Variable_Prop_Type::get_key() => 0,
91 ];
92 }
93
94 public function enqueue_editor_scripts() {
95 if ( Utils::has_pro() ) {
96 return;
97 }
98
99 wp_add_inline_script(
100 'elementor-common',
101 'window.ElementorVariablesQuotaConfig = ' . wp_json_encode( $this->get_quota_config() ) . ';',
102 'before'
103 );
104 }
105 }
106