PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
4.3.0-beta3 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 All 452 releases
elementor / modules / atomic-widgets / opt-in / opt-in.php

opt-in.php in Elementor Website Builder – more than just a page builder 4.3.0-beta3, at modules/atomic-widgets/opt-in/opt-in.php

101 lines 2.8 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\AtomicWidgets\OptIn;
4
5 use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
6 use Elementor\Core\Experiments\Manager as Experiments_Manager;
7 use Elementor\Modules\AtomicWidgets\Module as AtomicWidgetsModule;
8 use Elementor\Plugin;
9
10 class Opt_In {
11 const EXPERIMENT_NAME = 'e_opt_in_v4';
12
13 const OPT_IN_CLICKED_OPTION = 'elementor_v4_opt_in_clicked';
14
15 const OPT_IN_FEATURES = [
16 self::EXPERIMENT_NAME,
17 'container',
18 AtomicWidgetsModule::EXPERIMENT_NAME,
19 ];
20
21 const OPT_OUT_FEATURES = [
22 self::EXPERIMENT_NAME,
23 AtomicWidgetsModule::EXPERIMENT_NAME,
24 ];
25
26
27 public function init() {
28 $this->register_feature();
29
30 add_action( 'elementor/ajax/register_actions', fn( Ajax $ajax ) => $this->add_ajax_actions( $ajax ) );
31 add_action( 'rest_api_init', fn() => $this->register_routes() );
32 }
33
34 private function register_feature() {
35 Plugin::$instance->experiments->add_feature([
36 'name' => self::EXPERIMENT_NAME,
37 'title' => esc_html__( 'Editor V4', 'elementor' ),
38 'description' => esc_html__( 'Enable Editor V4.', 'elementor' ),
39 'hidden' => true,
40 'default' => Experiments_Manager::STATE_INACTIVE,
41 'release_status' => Experiments_Manager::RELEASE_STATUS_ALPHA,
42 'new_site' => [
43 'default_active' => true,
44 'minimum_installation_version' => '4.0.0',
45 ],
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 update_option( self::OPT_IN_CLICKED_OPTION, true );
63 }
64
65 public function ajax_opt_out_v4() {
66 if ( ! current_user_can( 'manage_options' ) ) {
67 throw new \Exception( 'Permission denied' );
68 }
69
70 $this->opt_out_v4();
71 }
72
73 public function ajax_opt_in_v4() {
74 if ( ! current_user_can( 'manage_options' ) ) {
75 throw new \Exception( 'Permission denied' );
76 }
77
78 $this->opt_in_v4();
79 }
80
81 private function add_ajax_actions( Ajax $ajax ) {
82 $ajax->register_ajax_action( 'editor_v4_opt_in', fn() => $this->ajax_opt_in_v4() );
83 $ajax->register_ajax_action( 'editor_v4_opt_out', fn() => $this->ajax_opt_out_v4() );
84 }
85
86 private function handle_rest_opt_in_v4() {
87 $this->ajax_opt_in_v4();
88 return new \WP_REST_Response( [
89 'success' => true,
90 ], 200 );
91 }
92
93 private function register_routes() {
94 register_rest_route( 'elementor/v1', '/operations/opt-in-v4', [
95 'methods' => 'POST',
96 'callback' => fn() => $this->handle_rest_opt_in_v4(),
97 'permission_callback' => fn() => current_user_can( 'manage_options' ),
98 ] );
99 }
100 }
101