PluginProbe
Elementor Website Builder – more than just a page builder / 3.26.0-dev5
Elementor Website Builder – more than just a page builder v3.26.0-dev5
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 4.0.7 All 451 releases
← All changes | modules/checklist/module.php +52 -18 4.1.03.26.0-dev5 View file →
@@ -2,8 +2,9 @@
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;
6 7 use Elementor\Modules\ElementorCounter\Module as Elementor_Counter;
7 8 use Elementor\Core\Isolation\Wordpress_Adapter;
8 9 use Elementor\Core\Isolation\Wordpress_Adapter_Interface;
9 10 use Elementor\Core\Isolation\Elementor_Adapter;
@@ -11,8 +12,10 @@
11 12 use Elementor\Core\Isolation\Elementor_Counter_Adapter_Interface;
12 13 use Elementor\Plugin;
13 14 use Elementor\Utils;
14 15 use Elementor\Modules\Checklist\Data\Controller;
16 +use Elementor\Core\Utils\Isolation_Manager;
17 +use Elementor\Modules\EditorAppBar\Module as AppBarModule;
15 18
16 19 if ( ! defined( 'ABSPATH' ) ) {
17 20 exit; // Exit if accessed directly.
18 21 }
@@ -17,8 +20,9 @@
17 20 exit; // Exit if accessed directly.
18 21 }
19 22
20 23 class Module extends BaseModule implements Checklist_Module_Interface {
24 + const EXPERIMENT_ID = 'launchpad-checklist';
21 25 const DB_OPTION_KEY = 'elementor_checklist';
22 26 const VISIBILITY_SWITCH_ID = 'show_launchpad_checklist';
23 27 const FIRST_CLOSED_CHECKLIST_IN_EDITOR = 'first_closed_checklist_in_editor';
24 28 const LAST_OPENED_TIMESTAMP = 'last_opened_timestamp';
@@ -40,14 +44,19 @@
40 44 public function __construct(
41 45 ?Wordpress_Adapter_Interface $wordpress_adapter = null,
42 46 ?Elementor_Adapter_Interface $elementor_adapter = null
43 47 ) {
44 - $this->wordpress_adapter = $wordpress_adapter ?? new Wordpress_Adapter();
45 - $this->elementor_adapter = $elementor_adapter ?? new Elementor_Adapter();
48 + $this->wordpress_adapter = $wordpress_adapter ?? Isolation_Manager::get_adapter( Wordpress_Adapter::class );
49 + $this->elementor_adapter = $elementor_adapter ?? Isolation_Manager::get_adapter( Elementor_Adapter::class );
46 50
47 51 parent::__construct();
52 + $this->register_experiment();
48 53 $this->init_user_progress();
49 54
55 + if ( ! $this->is_experiment_active() ) {
56 + return;
57 + }
58 +
50 59 Plugin::$instance->data_manager_v2->register_controller( new Controller() );
51 60 $this->user_progress = $this->user_progress ?? $this->get_user_progress_from_db();
52 61 $this->handle_checklist_visibility_with_kit();
53 62 $this->steps_manager = new Steps_Manager( $this );
@@ -63,13 +72,22 @@
63 72 * Get the module name.
64 73 *
65 74 * @return string
66 75 */
67 - public function get_name(): string {
76 + public function get_name() : string {
68 77 return 'e-checklist';
69 78 }
70 79
71 80 /**
81 + * Checks if the experiment is active
82 + *
83 + * @return bool
84 + */
85 + public function is_experiment_active() : bool {
86 + return Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_ID );
87 + }
88 +
89 + /**
72 90 * Gets user's progress from db
73 91 *
74 92 * @return array {
75 93 * @type bool $is_hidden
@@ -82,9 +100,9 @@
82 100 * }
83 101 * }
84 102 * }
85 103 */
86 - public function get_user_progress_from_db(): array {
104 + public function get_user_progress_from_db() : array {
87 105 $db_progress = json_decode( $this->wordpress_adapter->get_option( self::DB_OPTION_KEY ), true );
88 106 $db_progress = is_array( $db_progress ) ? $db_progress : [];
89 107
90 108 $progress = array_merge( $this->get_default_user_progress(), $db_progress );
@@ -104,9 +122,9 @@
104 122 * @type bool $is_marked_completed
105 123 * @type bool $is_completed
106 124 * }
107 125 */
108 - public function get_step_progress( $step_id ): ?array {
126 + public function get_step_progress( $step_id ) : ?array {
109 127 return $this->user_progress['steps'][ $step_id ] ?? null;
110 128 }
111 129
112 130 /**
@@ -116,14 +134,14 @@
116 134 * @param $step_progress
117 135 *
118 136 * @return void
119 137 */
120 - public function set_step_progress( $step_id, $step_progress ): void {
138 + public function set_step_progress( $step_id, $step_progress ) : void {
121 139 $this->user_progress['steps'][ $step_id ] = $step_progress;
122 140 $this->update_user_progress_in_db();
123 141 }
124 142
125 - public function update_user_progress( $new_data ): void {
143 + public function update_user_progress( $new_data ) : void {
126 144 $allowed_properties = [
127 145 self::FIRST_CLOSED_CHECKLIST_IN_EDITOR => $new_data[ self::FIRST_CLOSED_CHECKLIST_IN_EDITOR ] ?? null,
128 146 self::LAST_OPENED_TIMESTAMP => $new_data[ self::LAST_OPENED_TIMESTAMP ] ?? null,
129 147 self::IS_POPUP_MINIMIZED_KEY => $new_data[ self::IS_POPUP_MINIMIZED_KEY ] ?? null,
@@ -144,9 +162,9 @@
144 162
145 163 /**
146 164 * @return Steps_Manager
147 165 */
148 - public function get_steps_manager(): Steps_Manager {
166 + public function get_steps_manager() : Steps_Manager {
149 167 return $this->steps_manager;
150 168 }
151 169
152 170 /**
@@ -151,9 +169,9 @@
151 169
152 170 /**
153 171 * @return Wordpress_Adapter
154 172 */
155 - public function get_wordpress_adapter(): Wordpress_Adapter {
173 + public function get_wordpress_adapter() : Wordpress_Adapter {
156 174 return $this->wordpress_adapter;
157 175 }
158 176
159 177 /**
@@ -158,13 +176,13 @@
158 176
159 177 /**
160 178 * @return Elementor_Adapter
161 179 */
162 - public function get_elementor_adapter(): Elementor_Adapter {
180 + public function get_elementor_adapter() : Elementor_Adapter {
163 181 return $this->elementor_adapter;
164 182 }
165 183
166 - public function enqueue_editor_scripts(): void {
184 + public function enqueue_editor_scripts() : void {
167 185 add_action( 'elementor/editor/before_enqueue_scripts', function () {
168 186 $min_suffix = Utils::is_script_debug() ? '' : '.min';
169 187
170 188 wp_enqueue_script(
@@ -186,9 +204,9 @@
186 204 wp_set_script_translations( $this->get_name(), 'elementor' );
187 205 } );
188 206 }
189 207
190 - public function is_preference_switch_on(): bool {
208 + public function is_preference_switch_on() : bool {
191 209 if ( $this->should_switch_preferences_off() ) {
192 210 return false;
193 211 }
194 212
@@ -196,19 +214,33 @@
196 214
197 215 return 'yes' === $user_preferences || $this->wordpress_adapter->is_new_installation();
198 216 }
199 217
200 - public function should_switch_preferences_off(): bool {
218 + public function should_switch_preferences_off() : bool {
201 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 );
202 220 }
203 221
204 - private function init_user_progress(): void {
222 + private function register_experiment() : void {
223 + Plugin::$instance->experiments->add_feature( [
224 + 'name' => self::EXPERIMENT_ID,
225 + 'title' => esc_html__( 'Launchpad Checklist', 'elementor' ),
226 + 'description' => esc_html__( 'Launchpad Checklist feature to boost productivity and deliver your site faster', 'elementor' ),
227 + 'release_status' => Manager::RELEASE_STATUS_ALPHA,
228 + 'hidden' => true,
229 + 'new_site' => [
230 + 'default_active' => true,
231 + 'minimum_installation_version' => '3.25.0',
232 + ],
233 + ] );
234 + }
235 +
236 + private function init_user_progress() : void {
205 237 $default_settings = $this->get_default_user_progress();
206 238
207 239 $this->wordpress_adapter->add_option( self::DB_OPTION_KEY, wp_json_encode( $default_settings ) );
208 240 }
209 241
210 - private function get_default_user_progress(): array {
242 + private function get_default_user_progress() : array {
211 243 return [
212 244 self::LAST_OPENED_TIMESTAMP => null,
213 245 self::FIRST_CLOSED_CHECKLIST_IN_EDITOR => false,
214 246 self::IS_POPUP_MINIMIZED_KEY => false,
@@ -215,9 +247,9 @@
215 247 'steps' => [],
216 248 ];
217 249 }
218 250
219 - private function update_user_progress_in_db(): void {
251 + private function update_user_progress_in_db() : void {
220 252 $this->wordpress_adapter->update_option( self::DB_OPTION_KEY, wp_json_encode( $this->user_progress ) );
221 253 }
222 254
223 255 private function get_formatted_value( $key, $value ) {
@@ -237,8 +269,10 @@
237 269 $this->wordpress_adapter->set_user_preferences( self::VISIBILITY_SWITCH_ID, '' );
238 270 }, 11 );
239 271 }
240 272
241 - public static function should_display_checklist_toggle_control(): bool {
242 - return current_user_can( 'manage_options' );
273 + public static function should_display_checklist_toggle_control() : bool {
274 + return Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_ID ) &&
275 + Plugin::$instance->experiments->is_feature_active( AppBarModule::EXPERIMENT_NAME ) &&
276 + current_user_can( 'manage_options' );
243 277 }
244 278 }