| @@ -2,9 +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 as Experiments_Manager; | |
| 6 | +use Elementor\Core\Experiments\Manager; | |
| 7 | 7 | use Elementor\Modules\ElementorCounter\Module as Elementor_Counter; |
| 8 | 8 | use Elementor\Core\Isolation\Wordpress_Adapter; |
| 9 | 9 | use Elementor\Core\Isolation\Wordpress_Adapter_Interface; |
| 10 | 10 | use Elementor\Core\Isolation\Elementor_Adapter; |
| @@ -12,8 +12,10 @@ | ||
| 12 | 12 | use Elementor\Core\Isolation\Elementor_Counter_Adapter_Interface; |
| 13 | 13 | use Elementor\Plugin; |
| 14 | 14 | use Elementor\Utils; |
| 15 | 15 | use Elementor\Modules\Checklist\Data\Controller; |
| 16 | +use Elementor\Core\Utils\Isolation_Manager; | |
| 17 | +use Elementor\Modules\EditorAppBar\Module as AppBarModule; | |
| 16 | 18 | |
| 17 | 19 | if ( ! defined( 'ABSPATH' ) ) { |
| 18 | 20 | exit; // Exit if accessed directly. |
| 19 | 21 | } |
| @@ -18,9 +20,9 @@ | ||
| 18 | 20 | exit; // Exit if accessed directly. |
| 19 | 21 | } |
| 20 | 22 | |
| 21 | 23 | class Module extends BaseModule implements Checklist_Module_Interface { |
| 22 | - const EXPERIMENT_NAME = 'launchpad-checklist'; | |
| 24 | + const EXPERIMENT_ID = 'launchpad-checklist'; | |
| 23 | 25 | const DB_OPTION_KEY = 'elementor_checklist'; |
| 24 | 26 | const VISIBILITY_SWITCH_ID = 'show_launchpad_checklist'; |
| 25 | 27 | const FIRST_CLOSED_CHECKLIST_IN_EDITOR = 'first_closed_checklist_in_editor'; |
| 26 | 28 | const LAST_OPENED_TIMESTAMP = 'last_opened_timestamp'; |
| @@ -42,19 +44,18 @@ | ||
| 42 | 44 | public function __construct( |
| 43 | 45 | ?Wordpress_Adapter_Interface $wordpress_adapter = null, |
| 44 | 46 | ?Elementor_Adapter_Interface $elementor_adapter = null |
| 45 | 47 | ) { |
| 46 | - $this->wordpress_adapter = $wordpress_adapter ?? new Wordpress_Adapter(); | |
| 47 | - $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 ); | |
| 48 | 50 | |
| 49 | 51 | parent::__construct(); |
| 52 | + $this->init_user_progress(); | |
| 50 | 53 | |
| 51 | - if ( ! Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_NAME ) ) { | |
| 54 | + if ( ! $this->is_experiment_active() ) { | |
| 52 | 55 | return; |
| 53 | 56 | } |
| 54 | 57 | |
| 55 | - $this->init_user_progress(); | |
| 56 | - | |
| 57 | 58 | Plugin::$instance->data_manager_v2->register_controller( new Controller() ); |
| 58 | 59 | $this->user_progress = $this->user_progress ?? $this->get_user_progress_from_db(); |
| 59 | 60 | $this->handle_checklist_visibility_with_kit(); |
| 60 | 61 | $this->steps_manager = new Steps_Manager( $this ); |
| @@ -74,17 +75,15 @@ | ||
| 74 | 75 | public function get_name(): string { |
| 75 | 76 | return 'e-checklist'; |
| 76 | 77 | } |
| 77 | 78 | |
| 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 | - ]; | |
| 79 | + /** | |
| 80 | + * Checks if the experiment is active | |
| 81 | + * | |
| 82 | + * @return bool | |
| 83 | + */ | |
| 84 | + public function is_experiment_active(): bool { | |
| 85 | + return Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_ID ); | |
| 87 | 86 | } |
| 88 | 87 | |
| 89 | 88 | /** |
| 90 | 89 | * Gets user's progress from db |
| @@ -218,8 +217,22 @@ | ||
| 218 | 217 | public function should_switch_preferences_off(): bool { |
| 219 | 218 | 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 | 219 | } |
| 221 | 220 | |
| 221 | + public static function get_experimental_data(): array { | |
| 222 | + return [ | |
| 223 | + 'name' => self::EXPERIMENT_ID, | |
| 224 | + 'title' => esc_html__( 'Launchpad Checklist', 'elementor' ), | |
| 225 | + 'description' => esc_html__( 'Launchpad Checklist feature to boost productivity and deliver your site faster', 'elementor' ), | |
| 226 | + 'release_status' => Manager::RELEASE_STATUS_STABLE, | |
| 227 | + 'hidden' => true, | |
| 228 | + 'new_site' => [ | |
| 229 | + 'default_active' => true, | |
| 230 | + 'minimum_installation_version' => '3.25.0', | |
| 231 | + ], | |
| 232 | + ]; | |
| 233 | + } | |
| 234 | + | |
| 222 | 235 | private function init_user_progress(): void { |
| 223 | 236 | $default_settings = $this->get_default_user_progress(); |
| 224 | 237 | |
| 225 | 238 | $this->wordpress_adapter->add_option( self::DB_OPTION_KEY, wp_json_encode( $default_settings ) ); |
| @@ -256,8 +269,9 @@ | ||
| 256 | 269 | }, 11 ); |
| 257 | 270 | } |
| 258 | 271 | |
| 259 | 272 | 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' ); | |
| 273 | + return Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_ID ) && | |
| 274 | + Plugin::$instance->experiments->is_feature_active( AppBarModule::EXPERIMENT_NAME ) && | |
| 275 | + current_user_can( 'manage_options' ); | |
| 262 | 276 | } |
| 263 | 277 | } |