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