PluginProbe ʕ •ᴥ•ʔ
Elementor Website Builder – more than just a page builder / 3.26.0-beta1
Elementor Website Builder – more than just a page builder v3.26.0-beta1
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 4.0.6 4.0.5 4.0.4 4.0.3 3.22.0-dev1 4.0.0-beta3 3.22.0-dev2 4.0.0-beta4 3.22.0-dev3 4.0.0-beta5 3.22.0-dev4 4.0.0-dev1 3.22.0-dev5 4.0.0-dev2 3.22.0-dev6 4.0.0-dev3 3.22.1 4.0.0-dev4 3.22.2 4.0.0-dev5 3.22.3 4.0.1 3.23.0 4.0.2 3.23.0-beta1 3.23.0-beta2 3.23.0-beta3 3.23.0-beta4 3.23.0-beta5 3.23.0-beta6 3.23.0-dev1 3.23.0-dev2 3.23.0-dev3 3.23.0-dev4 3.23.0-dev5 3.23.0-dev6 3.23.1 3.23.2 3.23.3 3.23.4 3.24.0 3.24.0-beta1 3.24.0-beta2 3.24.0-beta3 3.24.0-dev1 3.24.0-dev2 3.24.0-dev3 3.24.1 3.24.2 3.24.3 3.24.4 3.24.5 3.24.6 3.24.7 3.24.8 3.25.0 3.25.0-beta1 3.25.0-beta2 3.25.0-beta3 3.25.0-dev1 3.25.0-dev2 3.25.0-dev3 3.25.1 3.25.10 3.25.11 3.25.2 3.25.3 3.25.4 3.25.5 3.25.6 3.25.7 3.25.8 3.25.9 3.26.0 3.26.0-beta1 3.26.0-beta2 3.26.0-beta3 3.26.0-beta4 3.26.0-beta5 3.26.0-dev1 3.26.0-dev2 3.26.0-dev3 3.26.0-dev4 3.26.0-dev5 3.26.1 3.26.2 3.26.3 3.26.4 3.26.5 3.27.0 3.27.0-beta1 3.27.0-beta2 3.27.0-dev1 3.27.0-dev2 3.27.1 3.27.2 3.27.3 3.27.4 3.27.5 3.27.6 3.27.7 3.28.0 3.28.0-beta1 3.28.0-beta2 3.28.0-beta3 3.28.0-dev1 3.28.0-dev2 3.28.0-dev3 3.28.1 3.28.2 3.28.3 3.28.4 3.29.0 3.29.0-beta1 trunk 3.29.0-beta2 3.0.0 3.29.0-beta3 3.0.1 3.29.0-beta4 3.0.10 3.29.0-dev1 3.0.11 3.29.0-dev2 3.0.12 3.29.0-dev3 3.0.13 3.29.0-dev4 3.0.14 3.29.1 3.0.15 3.29.2 3.0.16 3.3.0 3.0.2 3.3.1 3.0.3 3.30.0 3.0.4 3.30.0-beta1 3.0.5 3.30.0-beta2 3.0.6 3.30.0-beta3 3.0.7 3.30.0-dev1 3.0.8 3.30.0-dev2 3.0.8.1 3.30.0-dev3 3.0.9 3.30.1 3.1.0 3.30.2 3.1.0-beta1 3.30.3 3.1.0-beta2 3.30.4 3.1.0-beta3 3.31.0 3.1.0-beta4 3.31.0-beta1 3.1.0-dev1 3.31.0-beta2 3.1.0-dev2 3.31.0-dev1 3.1.0-dev3 3.31.0-dev2 3.1.1 3.31.1 3.1.2 3.31.2 3.1.3 3.31.3 3.1.4 3.31.4 3.10.0 3.31.5 3.10.0-dev1 3.32.0 3.10.1 3.32.0-beta1 3.10.2 3.32.0-beta2 3.11.0 3.32.0-beta3 3.11.0-beta1 3.32.0-dev1 3.11.0-beta2 3.32.0-dev2 3.11.0-beta3 3.32.0-dev3 3.11.0-dev1 3.32.1 3.11.0-dev2 3.32.2 3.11.0-dev3 3.32.3 3.11.1 3.32.4 3.11.2 3.32.5 3.11.3 3.33.0 3.11.4 3.33.0-beta1 3.11.5 3.33.0-beta2 3.12.0 3.33.0-beta3 3.12.1 3.33.0-beta4 3.12.2 3.33.0-dev1 3.13.0 3.33.0-dev2 3.13.0-beta1 3.33.0-dev3 3.13.0-beta2 3.33.0-dev4 3.13.0-beta3 3.33.1 3.13.0-dev3 3.33.2 3.13.0-dev4 3.33.3 3.13.1 3.33.4 3.13.2 3.33.5 3.13.3 3.33.6 3.13.4 3.34.0 3.14.0 3.34.0-beta1 3.14.0-beta1 3.34.0-beta2 3.14.0-beta2 3.34.0-beta3 3.14.0-beta3 3.34.0-dev1 3.14.0-beta4 3.34.0-dev2 3.14.0-beta5 3.34.1 3.14.1 3.34.2 3.15.0 3.34.3 3.15.1 3.34.4 3.15.2 3.35.0 3.15.3 3.35.0-beta1 3.16.0 3.35.0-beta2 3.16.0-beta3 3.35.0-beta3 3.16.0-beta4 3.35.0-beta4 3.16.0-dev1 3.35.0-dev1 3.16.0-dev2 3.35.0-dev2 3.16.1 3.35.0-dev3 3.16.2 3.35.0-dev4 3.16.3 3.35.1 3.16.4 3.35.2 3.16.5 3.35.3 3.16.6 3.35.4 3.17.0 3.35.5 3.17.0-dev2 3.35.6 3.17.0-dev3 3.35.7 3.17.0-dev4 3.35.8 3.17.1 3.35.9 3.17.2 3.4.0 3.17.3 3.4.0-dev7 3.18.0 3.4.0-dev8 3.18.0-beta1 3.4.0-dev9 3.18.0-beta2 3.4.1 3.18.0-beta3 3.4.2 3.18.0-beta4 3.4.3 3.18.0-dev1 3.4.4 3.18.1 3.4.5 3.18.2 3.4.6 3.18.3 3.4.7 3.19.0 3.4.8 3.19.0-beta1 3.5.0 3.19.0-beta2 3.5.0-beta1 3.19.0-beta3 3.5.0-beta2 3.19.0-beta4 3.5.0-beta3 3.19.0-beta5 3.5.0-beta4 3.19.0-beta6 3.5.0-beta5 3.19.0-dev1 3.5.0-beta7 3.19.0-dev2 3.5.0-beta8 3.19.0-dev3 3.5.0-dev8 3.19.0-dev4 3.5.0-dev9 3.19.0-dev5 3.5.1 3.19.0-dev6 3.5.2 3.19.1 3.5.3 3.19.2 3.5.4 3.19.3 3.5.5 3.19.4 3.5.6 3.2.0 3.6.0 3.2.1 3.6.0-beta1 3.2.2 3.6.0-beta2 3.2.3 3.6.0-beta3 3.2.4 3.6.0-beta4 3.2.5 3.6.0-beta5 3.20.0 3.6.0-dev1 3.20.0-beta1 3.6.0-dev10 3.20.0-beta2 3.6.1 3.20.0-beta3 3.6.2 3.20.0-beta4 3.6.3 3.20.0-dev1 3.6.4 3.20.0-dev2 3.6.5 3.20.0-dev3 3.6.6 3.20.0-dev4 3.6.7 3.20.1 3.6.8 3.20.2 3.7.0 3.20.3 3.7.0-beta1 3.20.4 3.7.0-beta2 3.21.0 3.7.0-beta3 3.21.0-beta1 3.7.0-beta4 3.21.0-beta2 3.7.0-dev1 3.21.0-beta3 3.7.1 3.21.0-dev1 3.7.2 3.21.0-dev2 3.7.3 3.21.0-dev3 3.7.4 3.21.1 3.7.5 3.21.2 3.7.6 3.21.3 3.7.7 3.21.4 3.7.8 3.21.5 3.8.0 3.21.6 3.8.0-beta1 3.21.7 3.8.0-beta2 3.21.8 3.8.0-beta3 3.22.0 3.8.1 3.22.0-beta1 3.9.0 3.22.0-beta2 3.9.1 3.22.0-beta3 3.9.2 3.22.0-beta4 4.0.0 3.22.0-beta5 4.0.0-beta1 3.22.0-beta6 4.0.0-beta2
elementor / modules / checklist / module.php
elementor / modules / checklist Last commit date
data 1 year ago steps 1 year ago checklist-module-interface.php 1 year ago module.php 1 year ago steps-manager.php 1 year ago
module.php
279 lines
1 <?php
2
3 namespace Elementor\Modules\Checklist;
4
5 use Elementor\Core\Base\Module as BaseModule;
6 use Elementor\Core\Experiments\Manager;
7 use Elementor\Modules\ElementorCounter\Module as Elementor_Counter;
8 use Elementor\Core\Isolation\Wordpress_Adapter;
9 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 use Elementor\Plugin;
14 use Elementor\Utils;
15 use Elementor\Modules\Checklist\Data\Controller;
16 use Elementor\Core\Utils\Isolation_Manager;
17 use Elementor\Modules\EditorAppBar\Module as AppBarModule;
18
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit; // Exit if accessed directly.
21 }
22
23 class Module extends BaseModule implements Checklist_Module_Interface {
24 const EXPERIMENT_ID = 'launchpad-checklist';
25 const DB_OPTION_KEY = 'elementor_checklist';
26 const VISIBILITY_SWITCH_ID = 'show_launchpad_checklist';
27 const FIRST_CLOSED_CHECKLIST_IN_EDITOR = 'first_closed_checklist_in_editor';
28 const LAST_OPENED_TIMESTAMP = 'last_opened_timestamp';
29 const SHOULD_OPEN_IN_EDITOR = 'should_open_in_editor';
30 const IS_POPUP_MINIMIZED_KEY = 'is_popup_minimized';
31
32 private Steps_Manager $steps_manager;
33 private Wordpress_Adapter_Interface $wordpress_adapter;
34 private Elementor_Adapter_Interface $elementor_adapter;
35 private Elementor_Counter_Adapter_Interface $counter_adapter;
36 private $user_progress = null;
37
38 /**
39 * @param ?Wordpress_Adapter_Interface $wordpress_adapter
40 * @param ?Elementor_Adapter_Interface $elementor_adapter
41 *
42 * @return void
43 */
44 public function __construct(
45 ?Wordpress_Adapter_Interface $wordpress_adapter = null,
46 ?Elementor_Adapter_Interface $elementor_adapter = null
47 ) {
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 );
50
51 parent::__construct();
52 $this->register_experiment();
53 $this->init_user_progress();
54
55 if ( ! $this->is_experiment_active() ) {
56 return;
57 }
58
59 Plugin::$instance->data_manager_v2->register_controller( new Controller() );
60 $this->user_progress = $this->user_progress ?? $this->get_user_progress_from_db();
61 $this->handle_checklist_visibility_with_kit();
62 $this->steps_manager = new Steps_Manager( $this );
63
64 if ( ! current_user_can( 'manage_options' ) ) {
65 return;
66 }
67
68 $this->enqueue_editor_scripts();
69 }
70
71 /**
72 * Get the module name.
73 *
74 * @return string
75 */
76 public function get_name() : string {
77 return 'e-checklist';
78 }
79
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 /**
90 * Gets user's progress from db
91 *
92 * @return array {
93 * @type bool $is_hidden
94 * @type int $last_opened_timestamp
95 * @type array $steps {
96 * @type string $step_id => {
97 * @type bool $is_marked_completed
98 * @type bool $is_absolute_competed
99 * @type bool $is_immutable_completed
100 * }
101 * }
102 * }
103 */
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;
114 }
115
116 /**
117 * Using the step's ID, get the progress of the step should it exist
118 *
119 * @param $step_id
120 *
121 * @return null|array {
122 * @type bool $is_marked_completed
123 * @type bool $is_completed
124 * }
125 */
126 public function get_step_progress( $step_id ) : ?array {
127 return $this->user_progress['steps'][ $step_id ] ?? null;
128 }
129
130 /**
131 * Update the progress of a step
132 *
133 * @param $step_id
134 * @param $step_progress
135 *
136 * @return void
137 */
138 public function set_step_progress( $step_id, $step_progress ) : void {
139 $this->user_progress['steps'][ $step_id ] = $step_progress;
140 $this->update_user_progress_in_db();
141 }
142
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 /**
164 * @return Steps_Manager
165 */
166 public function get_steps_manager() : Steps_Manager {
167 return $this->steps_manager;
168 }
169
170 /**
171 * @return Wordpress_Adapter
172 */
173 public function get_wordpress_adapter() : Wordpress_Adapter {
174 return $this->wordpress_adapter;
175 }
176
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 {
185 add_action( 'elementor/editor/before_enqueue_scripts', function () {
186 $min_suffix = Utils::is_script_debug() ? '' : '.min';
187
188 wp_enqueue_script(
189 $this->get_name(),
190 ELEMENTOR_ASSETS_URL . 'js/checklist' . $min_suffix . '.js',
191 [
192 'react',
193 'react-dom',
194 'elementor-common',
195 'elementor-v2-ui',
196 'elementor-v2-icons',
197 'elementor-v2-editor-app-bar',
198 'elementor-web-cli',
199 ],
200 ELEMENTOR_VERSION,
201 true
202 );
203
204 wp_set_script_translations( $this->get_name(), 'elementor' );
205 } );
206 }
207
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();
216 }
217
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 }
221
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 {
237 $default_settings = $this->get_default_user_progress();
238
239 $this->wordpress_adapter->add_option( self::DB_OPTION_KEY, wp_json_encode( $default_settings ) );
240 }
241
242 private function get_default_user_progress() : array {
243 return [
244 self::LAST_OPENED_TIMESTAMP => null,
245 self::FIRST_CLOSED_CHECKLIST_IN_EDITOR => false,
246 self::IS_POPUP_MINIMIZED_KEY => false,
247 'steps' => [],
248 ];
249 }
250
251 private function update_user_progress_in_db() : void {
252 $this->wordpress_adapter->update_option( self::DB_OPTION_KEY, wp_json_encode( $this->user_progress ) );
253 }
254
255 private function get_formatted_value( $key, $value ) {
256 if ( self::LAST_OPENED_TIMESTAMP === $key ) {
257 return $value ? time() : null;
258 }
259
260 return $value;
261 }
262
263 private function handle_checklist_visibility_with_kit() {
264 if ( ! $this->should_switch_preferences_off() ) {
265 return;
266 }
267
268 add_action( 'elementor/editor/init', function () {
269 $this->wordpress_adapter->set_user_preferences( self::VISIBILITY_SWITCH_ID, '' );
270 }, 11 );
271 }
272
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' );
277 }
278 }
279