| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets; |
| 4 |
|
| 5 |
use Elementor\Core\Common\Modules\Ajax\Module as Ajax; |
| 6 |
use Elementor\Core\Experiments\Manager as Experiments_Manager; |
| 7 |
use Elementor\Modules\GlobalClasses\Module as GlobalClassesModule; |
| 8 |
use Elementor\Modules\NestedElements\Module as NestedElementsModule; |
| 9 |
use Elementor\Modules\AtomicWidgets\Module as AtomicWidgetsModule; |
| 10 |
use Elementor\Modules\Variables\Module as VariablesModule; |
| 11 |
use Elementor\Plugin; |
| 12 |
|
| 13 |
class Opt_In { |
| 14 |
const EXPERIMENT_NAME = 'e_opt_in_v4'; |
| 15 |
|
| 16 |
const OPT_OUT_FEATURES = [ |
| 17 |
self::EXPERIMENT_NAME, |
| 18 |
AtomicWidgetsModule::EXPERIMENT_NAME, |
| 19 |
GlobalClassesModule::NAME, |
| 20 |
VariablesModule::EXPERIMENT_NAME, |
| 21 |
]; |
| 22 |
|
| 23 |
const OPT_IN_FEATURES = [ |
| 24 |
self::EXPERIMENT_NAME, |
| 25 |
'container', |
| 26 |
NestedElementsModule::EXPERIMENT_NAME, |
| 27 |
AtomicWidgetsModule::EXPERIMENT_NAME, |
| 28 |
GlobalClassesModule::NAME, |
| 29 |
VariablesModule::EXPERIMENT_NAME, |
| 30 |
]; |
| 31 |
|
| 32 |
public function init() { |
| 33 |
$this->register_feature(); |
| 34 |
|
| 35 |
add_action( 'elementor/ajax/register_actions', fn( Ajax $ajax ) => $this->add_ajax_actions( $ajax ) ); |
| 36 |
} |
| 37 |
|
| 38 |
private function register_feature() { |
| 39 |
Plugin::$instance->experiments->add_feature([ |
| 40 |
'name' => self::EXPERIMENT_NAME, |
| 41 |
'title' => esc_html__( 'Editor V4', 'elementor' ), |
| 42 |
'description' => esc_html__( 'Enable Editor V4.', 'elementor' ), |
| 43 |
'hidden' => true, |
| 44 |
'default' => Experiments_Manager::STATE_INACTIVE, |
| 45 |
'release_status' => Experiments_Manager::RELEASE_STATUS_ALPHA, |
| 46 |
]); |
| 47 |
} |
| 48 |
|
| 49 |
private function opt_out_v4() { |
| 50 |
foreach ( self::OPT_OUT_FEATURES as $feature ) { |
| 51 |
$feature_key = Plugin::$instance->experiments->get_feature_option_key( $feature ); |
| 52 |
update_option( $feature_key, Experiments_Manager::STATE_INACTIVE ); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
private function opt_in_v4() { |
| 57 |
foreach ( self::OPT_IN_FEATURES as $feature ) { |
| 58 |
$feature_key = Plugin::$instance->experiments->get_feature_option_key( $feature ); |
| 59 |
update_option( $feature_key, Experiments_Manager::STATE_ACTIVE ); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
public function ajax_opt_out_v4() { |
| 64 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 65 |
throw new \Exception( 'Permission denied' ); |
| 66 |
} |
| 67 |
|
| 68 |
$this->opt_out_v4(); |
| 69 |
} |
| 70 |
|
| 71 |
public function ajax_opt_in_v4() { |
| 72 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 73 |
throw new \Exception( 'Permission denied' ); |
| 74 |
} |
| 75 |
|
| 76 |
$this->opt_in_v4(); |
| 77 |
} |
| 78 |
|
| 79 |
private function add_ajax_actions( Ajax $ajax ) { |
| 80 |
$ajax->register_ajax_action( 'editor_v4_opt_in', fn() => $this->ajax_opt_in_v4() ); |
| 81 |
$ajax->register_ajax_action( 'editor_v4_opt_out', fn() => $this->ajax_opt_out_v4() ); |
| 82 |
} |
| 83 |
} |
| 84 |
|