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