PluginProbe
Elementor Website Builder – more than just a page builder / 3.24.8
Elementor Website Builder – more than just a page builder v3.24.8
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
← All changes | modules/checklist/module.php +38 -132 4.3.0-beta33.24.8 View file →
@@ -2,18 +2,13 @@
2 2
3 3 namespace Elementor\Modules\Checklist;
4 4
5 5 use Elementor\Core\Base\Module as BaseModule;
6 -use Elementor\Core\Experiments\Manager as Experiments_Manager;
7 -use Elementor\Modules\ElementorCounter\Module as Elementor_Counter;
6 +use Elementor\Core\Experiments\Manager;
8 7 use Elementor\Core\Isolation\Wordpress_Adapter;
9 8 use Elementor\Core\Isolation\Wordpress_Adapter_Interface;
10 -use Elementor\Core\Isolation\Elementor_Adapter;
11 -use Elementor\Core\Isolation\Elementor_Adapter_Interface;
12 -use Elementor\Core\Isolation\Elementor_Counter_Adapter_Interface;
13 9 use Elementor\Plugin;
14 10 use Elementor\Utils;
15 -use Elementor\Modules\Checklist\Data\Controller;
16 11
17 12 if ( ! defined( 'ABSPATH' ) ) {
18 13 exit; // Exit if accessed directly.
19 14 }
@@ -18,52 +13,33 @@
18 13 exit; // Exit if accessed directly.
19 14 }
20 15
21 16 class Module extends BaseModule implements Checklist_Module_Interface {
22 - const EXPERIMENT_NAME = 'launchpad-checklist';
17 + const EXPERIMENT_ID = 'launchpad-checklist';
23 18 const DB_OPTION_KEY = 'elementor_checklist';
24 - const VISIBILITY_SWITCH_ID = 'show_launchpad_checklist';
25 - const FIRST_CLOSED_CHECKLIST_IN_EDITOR = 'first_closed_checklist_in_editor';
26 - const LAST_OPENED_TIMESTAMP = 'last_opened_timestamp';
27 - const SHOULD_OPEN_IN_EDITOR = 'should_open_in_editor';
28 - const IS_POPUP_MINIMIZED_KEY = 'is_popup_minimized';
29 19
20 + private $user_progress = null;
30 21 private Steps_Manager $steps_manager;
31 22 private Wordpress_Adapter_Interface $wordpress_adapter;
32 - private Elementor_Adapter_Interface $elementor_adapter;
33 - private Elementor_Counter_Adapter_Interface $counter_adapter;
34 - private $user_progress = null;
35 23
36 24 /**
37 25 * @param ?Wordpress_Adapter_Interface $wordpress_adapter
38 - * @param ?Elementor_Adapter_Interface $elementor_adapter
39 26 *
40 27 * @return void
41 28 */
42 - public function __construct(
43 - ?Wordpress_Adapter_Interface $wordpress_adapter = null,
44 - ?Elementor_Adapter_Interface $elementor_adapter = null
45 - ) {
29 + public function __construct( ?Wordpress_Adapter_Interface $wordpress_adapter = null ) {
46 30 $this->wordpress_adapter = $wordpress_adapter ?? new Wordpress_Adapter();
47 - $this->elementor_adapter = $elementor_adapter ?? new Elementor_Adapter();
31 + parent::__construct();
48 32
49 - parent::__construct();
33 + $this->register_experiment();
50 34
51 - if ( ! Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_NAME ) ) {
35 + if ( ! $this->is_experiment_active() ) {
52 36 return;
53 37 }
54 38
55 39 $this->init_user_progress();
56 -
57 - Plugin::$instance->data_manager_v2->register_controller( new Controller() );
58 40 $this->user_progress = $this->user_progress ?? $this->get_user_progress_from_db();
59 - $this->handle_checklist_visibility_with_kit();
60 41 $this->steps_manager = new Steps_Manager( $this );
61 -
62 - if ( ! current_user_can( 'manage_options' ) ) {
63 - return;
64 - }
65 -
66 42 $this->enqueue_editor_scripts();
67 43 }
68 44
69 45 /**
@@ -70,21 +46,19 @@
70 46 * Get the module name.
71 47 *
72 48 * @return string
73 49 */
74 - public function get_name(): string {
50 + public function get_name() : string {
75 51 return 'e-checklist';
76 52 }
77 53
78 - public static function get_experimental_data(): array {
79 - return [
80 - 'name' => self::EXPERIMENT_NAME,
81 - 'title' => esc_html__( 'Launchpad Checklist', 'elementor' ),
82 - 'description' => esc_html__( 'Launchpad Checklist feature to boost productivity and deliver your site faster', 'elementor' ),
83 - 'hidden' => true,
84 - 'default' => Experiments_Manager::STATE_INACTIVE,
85 - 'release_status' => Experiments_Manager::RELEASE_STATUS_STABLE,
86 - ];
54 + /**
55 + * Checks if the experiment is active
56 + *
57 + * @return bool
58 + */
59 + public function is_experiment_active() : bool {
60 + return Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_ID );
87 61 }
88 62
89 63 /**
90 64 * Gets user's progress from db
@@ -94,24 +68,15 @@
94 68 * @type int $last_opened_timestamp
95 69 * @type array $steps {
96 70 * @type string $step_id => {
97 71 * @type bool $is_marked_completed
98 - * @type bool $is_absolute_competed
99 - * @type bool $is_immutable_completed
72 + * @type bool $is_completed
100 73 * }
101 74 * }
102 75 * }
103 76 */
104 - public function get_user_progress_from_db(): array {
105 - $db_progress = json_decode( $this->wordpress_adapter->get_option( self::DB_OPTION_KEY ), true );
106 - $db_progress = is_array( $db_progress ) ? $db_progress : [];
107 -
108 - $progress = array_merge( $this->get_default_user_progress(), $db_progress );
109 -
110 - $editor_visit_count = $this->elementor_adapter->get_count( Elementor_Counter::EDITOR_COUNTER_KEY );
111 - $progress[ self::SHOULD_OPEN_IN_EDITOR ] = 2 === $editor_visit_count && ! $progress[ self::LAST_OPENED_TIMESTAMP ];
112 -
113 - return $progress;
77 + public function get_user_progress_from_db() : array {
78 + return json_decode( $this->wordpress_adapter->get_option( self::DB_OPTION_KEY ), true );
114 79 }
115 80
116 81 /**
117 82 * Using the step's ID, get the progress of the step should it exist
@@ -122,9 +87,9 @@
122 87 * @type bool $is_marked_completed
123 88 * @type bool $is_completed
124 89 * }
125 90 */
126 - public function get_step_progress( $step_id ): ?array {
91 + public function get_step_progress( $step_id ) : ?array {
127 92 return $this->user_progress['steps'][ $step_id ] ?? null;
128 93 }
129 94
130 95 /**
@@ -134,37 +99,17 @@
134 99 * @param $step_progress
135 100 *
136 101 * @return void
137 102 */
138 - public function set_step_progress( $step_id, $step_progress ): void {
103 + public function set_step_progress( $step_id, $step_progress ) : void {
139 104 $this->user_progress['steps'][ $step_id ] = $step_progress;
140 105 $this->update_user_progress_in_db();
141 106 }
142 107
143 - public function update_user_progress( $new_data ): void {
144 - $allowed_properties = [
145 - self::FIRST_CLOSED_CHECKLIST_IN_EDITOR => $new_data[ self::FIRST_CLOSED_CHECKLIST_IN_EDITOR ] ?? null,
146 - self::LAST_OPENED_TIMESTAMP => $new_data[ self::LAST_OPENED_TIMESTAMP ] ?? null,
147 - self::IS_POPUP_MINIMIZED_KEY => $new_data[ self::IS_POPUP_MINIMIZED_KEY ] ?? null,
148 - ];
149 -
150 - foreach ( $allowed_properties as $key => $value ) {
151 - if ( null !== $value ) {
152 - $this->user_progress[ $key ] = $this->get_formatted_value( $key, $value );
153 - }
154 - }
155 -
156 - $this->update_user_progress_in_db();
157 -
158 - if ( isset( $new_data[ Elementor_Counter::EDITOR_COUNTER_KEY ] ) ) {
159 - $this->elementor_adapter->set_count( Elementor_Counter::EDITOR_COUNTER_KEY, $new_data[ Elementor_Counter::EDITOR_COUNTER_KEY ] );
160 - }
161 - }
162 -
163 108 /**
164 109 * @return Steps_Manager
165 110 */
166 - public function get_steps_manager(): Steps_Manager {
111 + public function get_steps_manager() : Steps_Manager {
167 112 return $this->steps_manager;
168 113 }
169 114
170 115 /**
@@ -169,20 +114,13 @@
169 114
170 115 /**
171 116 * @return Wordpress_Adapter
172 117 */
173 - public function get_wordpress_adapter(): Wordpress_Adapter {
118 + public function get_wordpress_adapter() : Wordpress_Adapter {
174 119 return $this->wordpress_adapter;
175 120 }
176 121
177 - /**
178 - * @return Elementor_Adapter
179 - */
180 - public function get_elementor_adapter(): Elementor_Adapter {
181 - return $this->elementor_adapter;
182 - }
183 -
184 - public function enqueue_editor_scripts(): void {
122 + public function enqueue_editor_scripts() : void {
185 123 add_action( 'elementor/editor/before_enqueue_scripts', function () {
186 124 $min_suffix = Utils::is_script_debug() ? '' : '.min';
187 125
188 126 wp_enqueue_script(
@@ -204,60 +142,28 @@
204 142 wp_set_script_translations( $this->get_name(), 'elementor' );
205 143 } );
206 144 }
207 145
208 - public function is_preference_switch_on(): bool {
209 - if ( $this->should_switch_preferences_off() ) {
210 - return false;
211 - }
212 -
213 - $user_preferences = $this->wordpress_adapter->get_user_preferences( self::VISIBILITY_SWITCH_ID );
214 -
215 - return 'yes' === $user_preferences || $this->wordpress_adapter->is_new_installation();
146 + private function register_experiment() : void {
147 + Plugin::$instance->experiments->add_feature( [
148 + 'name' => self::EXPERIMENT_ID,
149 + 'title' => esc_html__( 'Launchpad Checklist', 'elementor' ),
150 + 'description' => esc_html__( 'Launchpad Checklist feature to boost productivity and deliver your site faster', 'elementor' ),
151 + 'release_status' => Manager::RELEASE_STATUS_ALPHA,
152 + 'hidden' => true,
153 + ] );
216 154 }
217 155
218 - public function should_switch_preferences_off(): bool {
219 - return ! $this->elementor_adapter->is_active_kit_default() && ! $this->user_progress[ self::LAST_OPENED_TIMESTAMP ] && ! $this->elementor_adapter->get_count( Elementor_Counter::EDITOR_COUNTER_KEY );
220 - }
156 + private function init_user_progress() : void {
157 + $default_settings = [
158 + 'is_hidden' => false,
159 + 'last_opened_timestamp' => time(),
160 + 'steps' => [],
161 + ];
221 162
222 - private function init_user_progress(): void {
223 - $default_settings = $this->get_default_user_progress();
224 -
225 163 $this->wordpress_adapter->add_option( self::DB_OPTION_KEY, wp_json_encode( $default_settings ) );
226 164 }
227 165
228 - private function get_default_user_progress(): array {
229 - return [
230 - self::LAST_OPENED_TIMESTAMP => null,
231 - self::FIRST_CLOSED_CHECKLIST_IN_EDITOR => false,
232 - self::IS_POPUP_MINIMIZED_KEY => false,
233 - 'steps' => [],
234 - ];
235 - }
236 -
237 - private function update_user_progress_in_db(): void {
166 + private function update_user_progress_in_db() : void {
238 167 $this->wordpress_adapter->update_option( self::DB_OPTION_KEY, wp_json_encode( $this->user_progress ) );
239 - }
240 -
241 - private function get_formatted_value( $key, $value ) {
242 - if ( self::LAST_OPENED_TIMESTAMP === $key ) {
243 - return $value ? time() : null;
244 - }
245 -
246 - return $value;
247 - }
248 -
249 - private function handle_checklist_visibility_with_kit() {
250 - if ( ! $this->should_switch_preferences_off() ) {
251 - return;
252 - }
253 -
254 - add_action( 'elementor/editor/init', function () {
255 - $this->wordpress_adapter->set_user_preferences( self::VISIBILITY_SWITCH_ID, '' );
256 - }, 11 );
257 - }
258 -
259 - public static function should_display_checklist_toggle_control(): bool {
260 - return Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_NAME )
261 - && current_user_can( 'manage_options' );
262 168 }
263 169 }