first commit
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\Checklist;
|
||||
|
||||
use Elementor\Core\Isolation\Wordpress_Adapter;
|
||||
use Elementor\Core\Isolation\Elementor_Adapter;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
interface Checklist_Module_Interface {
|
||||
public function get_name(): string;
|
||||
|
||||
public function get_user_progress_from_db(): array;
|
||||
|
||||
public function get_step_progress( $step_id ): ?array;
|
||||
|
||||
public function set_step_progress( $step_id, $step_progress ): void;
|
||||
|
||||
public function get_steps_manager(): Steps_Manager;
|
||||
|
||||
public function get_wordpress_adapter(): Wordpress_Adapter;
|
||||
|
||||
public function get_elementor_adapter(): Elementor_Adapter;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Elementor\Modules\Checklist\Data;
|
||||
|
||||
use Elementor\Data\V2\Base\Controller as Controller_Base;
|
||||
use Elementor\Modules\Checklist\Data\Endpoints\Steps;
|
||||
use Elementor\Modules\Checklist\Data\Endpoints\User_Progress;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Controller extends Controller_Base {
|
||||
public function get_name() {
|
||||
return 'checklist';
|
||||
}
|
||||
|
||||
public function register_endpoints() {
|
||||
$this->index_endpoint->register_item_route();
|
||||
$this->register_endpoint( new Steps( $this ) );
|
||||
$this->register_endpoint( new User_Progress( $this ) );
|
||||
}
|
||||
|
||||
public function update_items_permissions_check( $request ) {
|
||||
return current_user_can( 'manage_options' );
|
||||
}
|
||||
|
||||
public function update_item_permissions_check( $request ) {
|
||||
return current_user_can( 'manage_options' );
|
||||
}
|
||||
|
||||
public function get_item_permissions_check( $request ) {
|
||||
return current_user_can( 'manage_options' );
|
||||
}
|
||||
|
||||
public function get_items_permissions_check( $request ) {
|
||||
return current_user_can( 'manage_options' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace Elementor\Modules\Checklist\Data\Endpoints;
|
||||
|
||||
use Elementor\Data\V2\Base\Endpoint as Endpoint_Base;
|
||||
use Elementor\Modules\Checklist\Steps\Step_Base;
|
||||
use Elementor\Modules\Checklist\Steps_Manager;
|
||||
use Elementor\Modules\Checklist\Module as Checklist_Module;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Steps extends Endpoint_Base {
|
||||
|
||||
public function get_name(): string {
|
||||
return 'steps';
|
||||
}
|
||||
|
||||
public function get_format(): string {
|
||||
return 'checklist';
|
||||
}
|
||||
|
||||
public function get_items( $request ) {
|
||||
return $this->get_checklist_data();
|
||||
}
|
||||
|
||||
public function update_item( $id, $request ) {
|
||||
$checklist_module = Checklist_Module::instance();
|
||||
$step = $checklist_module->get_steps_manager()->get_step_by_id( $id );
|
||||
$step->update_step( $request->get_json_params() );
|
||||
|
||||
return [
|
||||
'data' => 'success',
|
||||
];
|
||||
}
|
||||
|
||||
private function get_checklist_data(): array {
|
||||
$checklist_module = Checklist_Module::instance();
|
||||
$steps_data = $checklist_module->get_steps_manager()->get_steps_for_frontend();
|
||||
|
||||
return [
|
||||
'data' => $steps_data,
|
||||
];
|
||||
}
|
||||
|
||||
protected function register() {
|
||||
parent::register();
|
||||
|
||||
$this->register_item_route();
|
||||
$this->register_item_route( \WP_REST_Server::EDITABLE, [
|
||||
'id_arg_name' => 'id',
|
||||
'id_arg_type_regex' => '[\w\-\_]+',
|
||||
'id' => [
|
||||
'type' => 'string',
|
||||
'description' => 'The step id.',
|
||||
'required' => true,
|
||||
'validate_callback' => function ( $step_id ) {
|
||||
return in_array( $step_id, Steps_Manager::get_step_ids() );
|
||||
},
|
||||
],
|
||||
] );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace Elementor\Modules\Checklist\Data\Endpoints;
|
||||
|
||||
use Elementor\Data\V2\Base\Endpoint as Endpoint_Base;
|
||||
use Elementor\Modules\Checklist\Module as Checklist_Module;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class User_Progress extends Endpoint_Base {
|
||||
protected function register() {
|
||||
parent::register();
|
||||
|
||||
$this->register_items_route( \WP_REST_Server::EDITABLE );
|
||||
}
|
||||
|
||||
public function get_name(): string {
|
||||
return 'user-progress';
|
||||
}
|
||||
|
||||
public function get_format(): string {
|
||||
return 'checklist';
|
||||
}
|
||||
|
||||
public function get_items( $request ) {
|
||||
return $this->get_checklist_data();
|
||||
}
|
||||
|
||||
public function update_items( $request ) {
|
||||
Checklist_Module::instance()->update_user_progress( $request->get_json_params() );
|
||||
|
||||
return [
|
||||
'data' => 'success',
|
||||
];
|
||||
}
|
||||
|
||||
private function get_checklist_data(): array {
|
||||
$checklist_module = Checklist_Module::instance();
|
||||
$progress_data = $checklist_module->get_user_progress_from_db();
|
||||
|
||||
return [
|
||||
'data' => $progress_data,
|
||||
];
|
||||
}
|
||||
}
|
||||
246
wp-content/plugins/elementor/modules/checklist/module.php
Normal file
246
wp-content/plugins/elementor/modules/checklist/module.php
Normal file
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\Checklist;
|
||||
|
||||
use Elementor\Core\Base\Module as BaseModule;
|
||||
use Elementor\Core\Experiments\Manager;
|
||||
use Elementor\Modules\ElementorCounter\Module as Elementor_Counter;
|
||||
use Elementor\Core\Isolation\Wordpress_Adapter;
|
||||
use Elementor\Core\Isolation\Wordpress_Adapter_Interface;
|
||||
use Elementor\Core\Isolation\Elementor_Adapter;
|
||||
use Elementor\Core\Isolation\Elementor_Adapter_Interface;
|
||||
use Elementor\Core\Isolation\Elementor_Counter_Adapter_Interface;
|
||||
use Elementor\Plugin;
|
||||
use Elementor\Utils;
|
||||
use Elementor\Modules\Checklist\Data\Controller;
|
||||
use Elementor\Core\Utils\Isolation_Manager;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Module extends BaseModule implements Checklist_Module_Interface {
|
||||
const DB_OPTION_KEY = 'elementor_checklist';
|
||||
const VISIBILITY_SWITCH_ID = 'show_launchpad_checklist';
|
||||
const FIRST_CLOSED_CHECKLIST_IN_EDITOR = 'first_closed_checklist_in_editor';
|
||||
const LAST_OPENED_TIMESTAMP = 'last_opened_timestamp';
|
||||
const SHOULD_OPEN_IN_EDITOR = 'should_open_in_editor';
|
||||
const IS_POPUP_MINIMIZED_KEY = 'is_popup_minimized';
|
||||
|
||||
private Steps_Manager $steps_manager;
|
||||
private Wordpress_Adapter_Interface $wordpress_adapter;
|
||||
private Elementor_Adapter_Interface $elementor_adapter;
|
||||
private Elementor_Counter_Adapter_Interface $counter_adapter;
|
||||
private $user_progress = null;
|
||||
|
||||
/**
|
||||
* @param ?Wordpress_Adapter_Interface $wordpress_adapter
|
||||
* @param ?Elementor_Adapter_Interface $elementor_adapter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
?Wordpress_Adapter_Interface $wordpress_adapter = null,
|
||||
?Elementor_Adapter_Interface $elementor_adapter = null
|
||||
) {
|
||||
$this->wordpress_adapter = $wordpress_adapter ?? Isolation_Manager::get_adapter( Wordpress_Adapter::class );
|
||||
$this->elementor_adapter = $elementor_adapter ?? Isolation_Manager::get_adapter( Elementor_Adapter::class );
|
||||
|
||||
parent::__construct();
|
||||
$this->init_user_progress();
|
||||
|
||||
Plugin::$instance->data_manager_v2->register_controller( new Controller() );
|
||||
$this->user_progress = $this->user_progress ?? $this->get_user_progress_from_db();
|
||||
$this->handle_checklist_visibility_with_kit();
|
||||
$this->steps_manager = new Steps_Manager( $this );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->enqueue_editor_scripts();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the module name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name(): string {
|
||||
return 'e-checklist';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets user's progress from db
|
||||
*
|
||||
* @return array {
|
||||
* @type bool $is_hidden
|
||||
* @type int $last_opened_timestamp
|
||||
* @type array $steps {
|
||||
* @type string $step_id => {
|
||||
* @type bool $is_marked_completed
|
||||
* @type bool $is_absolute_competed
|
||||
* @type bool $is_immutable_completed
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
public function get_user_progress_from_db(): array {
|
||||
$db_progress = json_decode( $this->wordpress_adapter->get_option( self::DB_OPTION_KEY ), true );
|
||||
$db_progress = is_array( $db_progress ) ? $db_progress : [];
|
||||
|
||||
$progress = array_merge( $this->get_default_user_progress(), $db_progress );
|
||||
|
||||
$editor_visit_count = $this->elementor_adapter->get_count( Elementor_Counter::EDITOR_COUNTER_KEY );
|
||||
$progress[ self::SHOULD_OPEN_IN_EDITOR ] = 2 === $editor_visit_count && ! $progress[ self::LAST_OPENED_TIMESTAMP ];
|
||||
|
||||
return $progress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Using the step's ID, get the progress of the step should it exist
|
||||
*
|
||||
* @param $step_id
|
||||
*
|
||||
* @return null|array {
|
||||
* @type bool $is_marked_completed
|
||||
* @type bool $is_completed
|
||||
* }
|
||||
*/
|
||||
public function get_step_progress( $step_id ): ?array {
|
||||
return $this->user_progress['steps'][ $step_id ] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the progress of a step
|
||||
*
|
||||
* @param $step_id
|
||||
* @param $step_progress
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set_step_progress( $step_id, $step_progress ): void {
|
||||
$this->user_progress['steps'][ $step_id ] = $step_progress;
|
||||
$this->update_user_progress_in_db();
|
||||
}
|
||||
|
||||
public function update_user_progress( $new_data ): void {
|
||||
$allowed_properties = [
|
||||
self::FIRST_CLOSED_CHECKLIST_IN_EDITOR => $new_data[ self::FIRST_CLOSED_CHECKLIST_IN_EDITOR ] ?? null,
|
||||
self::LAST_OPENED_TIMESTAMP => $new_data[ self::LAST_OPENED_TIMESTAMP ] ?? null,
|
||||
self::IS_POPUP_MINIMIZED_KEY => $new_data[ self::IS_POPUP_MINIMIZED_KEY ] ?? null,
|
||||
];
|
||||
|
||||
foreach ( $allowed_properties as $key => $value ) {
|
||||
if ( null !== $value ) {
|
||||
$this->user_progress[ $key ] = $this->get_formatted_value( $key, $value );
|
||||
}
|
||||
}
|
||||
|
||||
$this->update_user_progress_in_db();
|
||||
|
||||
if ( isset( $new_data[ Elementor_Counter::EDITOR_COUNTER_KEY ] ) ) {
|
||||
$this->elementor_adapter->set_count( Elementor_Counter::EDITOR_COUNTER_KEY, $new_data[ Elementor_Counter::EDITOR_COUNTER_KEY ] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Steps_Manager
|
||||
*/
|
||||
public function get_steps_manager(): Steps_Manager {
|
||||
return $this->steps_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Wordpress_Adapter
|
||||
*/
|
||||
public function get_wordpress_adapter(): Wordpress_Adapter {
|
||||
return $this->wordpress_adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Elementor_Adapter
|
||||
*/
|
||||
public function get_elementor_adapter(): Elementor_Adapter {
|
||||
return $this->elementor_adapter;
|
||||
}
|
||||
|
||||
public function enqueue_editor_scripts(): void {
|
||||
add_action( 'elementor/editor/before_enqueue_scripts', function () {
|
||||
$min_suffix = Utils::is_script_debug() ? '' : '.min';
|
||||
|
||||
wp_enqueue_script(
|
||||
$this->get_name(),
|
||||
ELEMENTOR_ASSETS_URL . 'js/checklist' . $min_suffix . '.js',
|
||||
[
|
||||
'react',
|
||||
'react-dom',
|
||||
'elementor-common',
|
||||
'elementor-v2-ui',
|
||||
'elementor-v2-icons',
|
||||
'elementor-v2-editor-app-bar',
|
||||
'elementor-web-cli',
|
||||
],
|
||||
ELEMENTOR_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
wp_set_script_translations( $this->get_name(), 'elementor' );
|
||||
} );
|
||||
}
|
||||
|
||||
public function is_preference_switch_on(): bool {
|
||||
if ( $this->should_switch_preferences_off() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user_preferences = $this->wordpress_adapter->get_user_preferences( self::VISIBILITY_SWITCH_ID );
|
||||
|
||||
return 'yes' === $user_preferences || $this->wordpress_adapter->is_new_installation();
|
||||
}
|
||||
|
||||
public function should_switch_preferences_off(): bool {
|
||||
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 );
|
||||
}
|
||||
|
||||
private function init_user_progress(): void {
|
||||
$default_settings = $this->get_default_user_progress();
|
||||
|
||||
$this->wordpress_adapter->add_option( self::DB_OPTION_KEY, wp_json_encode( $default_settings ) );
|
||||
}
|
||||
|
||||
private function get_default_user_progress(): array {
|
||||
return [
|
||||
self::LAST_OPENED_TIMESTAMP => null,
|
||||
self::FIRST_CLOSED_CHECKLIST_IN_EDITOR => false,
|
||||
self::IS_POPUP_MINIMIZED_KEY => false,
|
||||
'steps' => [],
|
||||
];
|
||||
}
|
||||
|
||||
private function update_user_progress_in_db(): void {
|
||||
$this->wordpress_adapter->update_option( self::DB_OPTION_KEY, wp_json_encode( $this->user_progress ) );
|
||||
}
|
||||
|
||||
private function get_formatted_value( $key, $value ) {
|
||||
if ( self::LAST_OPENED_TIMESTAMP === $key ) {
|
||||
return $value ? time() : null;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
private function handle_checklist_visibility_with_kit() {
|
||||
if ( ! $this->should_switch_preferences_off() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action( 'elementor/editor/init', function () {
|
||||
$this->wordpress_adapter->set_user_preferences( self::VISIBILITY_SWITCH_ID, '' );
|
||||
}, 11 );
|
||||
}
|
||||
|
||||
public static function should_display_checklist_toggle_control(): bool {
|
||||
return current_user_can( 'manage_options' );
|
||||
}
|
||||
}
|
||||
200
wp-content/plugins/elementor/modules/checklist/steps-manager.php
Normal file
200
wp-content/plugins/elementor/modules/checklist/steps-manager.php
Normal file
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\Checklist;
|
||||
|
||||
use Elementor\Modules\Checklist\Steps\Assign_Homepage;
|
||||
use Elementor\Modules\Checklist\Steps\Create_Pages;
|
||||
use Elementor\Modules\Checklist\Steps\Setup_Header;
|
||||
use Elementor\Modules\Checklist\Steps\Add_Logo;
|
||||
use Elementor\Modules\Checklist\Steps\Step_Base;
|
||||
use Elementor\Modules\Checklist\Steps\Set_Fonts_And_Colors;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Steps_Manager {
|
||||
/** @var Step_Base[] $step_instances */
|
||||
private array $step_instances = [];
|
||||
|
||||
private static array $step_ids = [
|
||||
Add_Logo::STEP_ID,
|
||||
Set_Fonts_And_Colors::STEP_ID,
|
||||
Create_Pages::STEP_ID,
|
||||
Setup_Header::STEP_ID,
|
||||
Assign_Homepage::STEP_ID,
|
||||
];
|
||||
|
||||
private Checklist_Module_Interface $module;
|
||||
|
||||
public function __construct( Checklist_Module_Interface $module ) {
|
||||
$this->module = $module;
|
||||
$this->register_steps();
|
||||
|
||||
add_action( 'elementor/init', function() {
|
||||
$this->filter_steps();
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets formatted and ordered array of step ( step data, is_marked_completed and is_completed )
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_steps_for_frontend(): array {
|
||||
$formatted_steps = [];
|
||||
|
||||
foreach ( self::$step_ids as $step_id ) {
|
||||
$instance = $this->step_instances[ $step_id ];
|
||||
$instance->maybe_immutably_mark_as_completed();
|
||||
|
||||
$step = [
|
||||
Step_Base::MARKED_AS_COMPLETED_KEY => $instance->is_marked_as_completed(),
|
||||
Step_Base::IMMUTABLE_COMPLETION_KEY => $instance->is_immutable_completed(),
|
||||
Step_Base::ABSOLUTE_COMPLETION_KEY => $instance->is_absolute_completed(),
|
||||
'config' => $this->get_step_config( $step_id ),
|
||||
];
|
||||
|
||||
$formatted_steps[] = $step;
|
||||
}
|
||||
|
||||
return $formatted_steps;
|
||||
}
|
||||
|
||||
public function update_step( string $step_id, array $data ): void {
|
||||
$step = $this->get_step_by_id( $step_id );
|
||||
|
||||
if ( ! $step ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$step->update_step( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks a step as completed, returns true if the step was found and marked or false otherwise
|
||||
*
|
||||
* @param string $step_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function mark_step_as_completed( string $step_id ): void {
|
||||
$this->update_step( $step_id, [ Step_Base::MARKED_AS_COMPLETED_KEY => true ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmarks a step as completed, returns true if the step was found and unmarked or false otherwise
|
||||
*
|
||||
* @param string $step_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unmark_step_as_completed( string $step_id ): void {
|
||||
$this->update_step( $step_id, [ Step_Base::MARKED_AS_COMPLETED_KEY => false ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe marks a step as completed (depending on if source allows it), returns true if the step was found and marked or false otherwise
|
||||
*
|
||||
* @param $step_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_set_step_as_immutable_completed( string $step_id ): void {
|
||||
$step = $this->get_step_by_id( $step_id );
|
||||
|
||||
if ( ! $step ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$step->maybe_immutably_mark_as_completed();
|
||||
}
|
||||
|
||||
public function get_step_by_id( string $step_id ): ?Step_Base {
|
||||
return $this->step_instances[ $step_id ] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function get_step_config( $step_id ): array {
|
||||
$step_instance = $this->step_instances[ $step_id ];
|
||||
|
||||
return $step_instance
|
||||
? [
|
||||
'id' => $step_instance->get_id(),
|
||||
'title' => $step_instance->get_title(),
|
||||
'description' => $step_instance->get_description(),
|
||||
'learn_more_text' => $step_instance->get_learn_more_text(),
|
||||
'learn_more_url' => $step_instance->get_learn_more_url(),
|
||||
Step_Base::IS_COMPLETION_IMMUTABLE => $step_instance->get_is_completion_immutable(),
|
||||
'cta_text' => $step_instance->get_cta_text(),
|
||||
'cta_url' => $step_instance->get_cta_url(),
|
||||
'image_src' => $step_instance->get_image_src(),
|
||||
'promotion_data' => $step_instance->get_promotion_data(),
|
||||
]
|
||||
: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Getting the step instances array based on source's order
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function register_steps(): void {
|
||||
foreach ( self::$step_ids as $step_id ) {
|
||||
$step_instance = $this->get_step_instance( $step_id );
|
||||
|
||||
if ( $step_instance && ! isset( $this->step_instances[ $step_id ] ) ) {
|
||||
$this->step_instances[ $step_id ] = $step_instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the steps config from source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_step_ids(): array {
|
||||
return self::$step_ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Using step data->id, instantiates and returns the step class or null if the class does not exist
|
||||
*
|
||||
* @param $step_data
|
||||
*
|
||||
* @return Step_Base|null
|
||||
*/
|
||||
private function get_step_instance( string $step_id ): ?Step_Base {
|
||||
$class_name = '\\Elementor\\Modules\\Checklist\\Steps\\' . $step_id;
|
||||
|
||||
if ( ! class_exists( $class_name ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Step_Base $step */
|
||||
return new $class_name( $this->module, $this->module->get_wordpress_adapter(), $this->module->get_elementor_adapter() );
|
||||
}
|
||||
|
||||
private function filter_steps() {
|
||||
$step_ids = [];
|
||||
$filtered_steps = apply_filters( 'elementor/checklist/steps', $this->step_instances );
|
||||
|
||||
foreach ( $filtered_steps as $step_id => $step_instance ) {
|
||||
if ( ! $step_instance instanceof Step_Base ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! $step_instance->is_visible() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->step_instances[ $step_id ] = $step_instance;
|
||||
$step_ids[] = $step_id;
|
||||
}
|
||||
|
||||
self::$step_ids = $step_ids;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\Checklist\Steps;
|
||||
|
||||
use Elementor\Core\DocumentTypes\Page;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Add_Logo extends Step_Base {
|
||||
const STEP_ID = 'add_logo';
|
||||
|
||||
const SITE_IDENTITY_TAB = 'settings-site-identity';
|
||||
|
||||
public function get_id(): string {
|
||||
return self::STEP_ID;
|
||||
}
|
||||
|
||||
public function is_absolute_completed(): bool {
|
||||
return $this->wordpress_adapter->has_custom_logo();
|
||||
}
|
||||
|
||||
public function get_title(): string {
|
||||
return esc_html__( 'Add your logo', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_description(): string {
|
||||
return __( 'Let\'s start by adding your logo and filling in the site identity settings. This will establish your initial presence and also improve SEO.', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_cta_text(): string {
|
||||
return esc_html__( 'Go to Site Identity', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_cta_url(): string {
|
||||
return Page::get_site_settings_url_config( self::SITE_IDENTITY_TAB )['url'];
|
||||
}
|
||||
|
||||
public function get_is_completion_immutable(): bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get_image_src(): string {
|
||||
return 'https://assets.elementor.com/checklist/v1/images/checklist-step-1.jpg';
|
||||
}
|
||||
|
||||
public function get_learn_more_url(): string {
|
||||
return 'http://go.elementor.com/app-website-checklist-logo-article';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\Checklist\Steps;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Assign_Homepage extends Step_Base {
|
||||
const STEP_ID = 'assign_homepage';
|
||||
|
||||
public function get_id(): string {
|
||||
return self::STEP_ID;
|
||||
}
|
||||
|
||||
public function is_absolute_completed(): bool {
|
||||
$front_page_id = (int) ( $this->wordpress_adapter->get_option( 'page_on_front' ) ?? 0 );
|
||||
|
||||
return (bool) $front_page_id;
|
||||
}
|
||||
|
||||
public function get_title(): string {
|
||||
return esc_html__( 'Assign a homepage', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_description(): string {
|
||||
return esc_html__( 'Before your launch, make sure to assign a homepage so visitors have a clear entry point into your site.', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_cta_text(): string {
|
||||
return esc_html__( 'Assign homepage', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_cta_url(): string {
|
||||
return admin_url( 'options-reading.php' );
|
||||
}
|
||||
|
||||
public function get_is_completion_immutable(): bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get_image_src(): string {
|
||||
return 'https://assets.elementor.com/checklist/v1/images/checklist-step-6.jpg';
|
||||
}
|
||||
|
||||
public function get_learn_more_url(): string {
|
||||
return 'http://go.elementor.com/app-website-checklist-assign-home-article';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\Checklist\Steps;
|
||||
|
||||
use Elementor\Plugin;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Create_Pages extends Step_Base {
|
||||
const STEP_ID = 'create_pages';
|
||||
|
||||
public function get_id(): string {
|
||||
return self::STEP_ID;
|
||||
}
|
||||
|
||||
public function is_absolute_completed(): bool {
|
||||
$pages = $this->wordpress_adapter->get_pages( [
|
||||
'meta_key' => '_elementor_version',
|
||||
'number' => 3,
|
||||
] ) ?? [];
|
||||
|
||||
return count( $pages ) >= 3;
|
||||
}
|
||||
|
||||
public function get_title(): string {
|
||||
return esc_html__( 'Create your first 3 pages', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_description(): string {
|
||||
return esc_html__( 'Jumpstart your creation with professional designs from the Template Library or start from scratch.', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_cta_text(): string {
|
||||
return esc_html__( 'Create a new page', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_cta_url(): string {
|
||||
return Plugin::$instance->documents->get_create_new_post_url( 'page' );
|
||||
}
|
||||
|
||||
public function get_learn_more_url(): string {
|
||||
return 'http://go.elementor.com/app-website-checklist-pages-article';
|
||||
}
|
||||
|
||||
public function get_is_completion_immutable(): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get_image_src(): string {
|
||||
return 'https://assets.elementor.com/checklist/v1/images/checklist-step-3.jpg';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\Checklist\Steps;
|
||||
|
||||
use Elementor\Core\DocumentTypes\Page;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Set_Fonts_And_Colors extends Step_Base {
|
||||
const STEP_ID = 'set_fonts_and_colors';
|
||||
|
||||
public function get_id(): string {
|
||||
return self::STEP_ID;
|
||||
}
|
||||
|
||||
public function is_absolute_completed(): bool {
|
||||
$settings = $this->elementor_adapter->get_kit_settings();
|
||||
$custom_color = $settings['custom_colors'] ?? '';
|
||||
$custom_fonts = $settings['custom_typography'] ?? '';
|
||||
|
||||
return ! empty( $custom_color ) && ! empty( $custom_fonts );
|
||||
}
|
||||
|
||||
public function get_title(): string {
|
||||
return __( 'Set up your Global Fonts & Colors', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_description(): string {
|
||||
return esc_html__( 'Global colors and fonts ensure a cohesive look across your site. Start by defining one color and one font.', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_cta_text(): string {
|
||||
return esc_html__( 'Go to Site Identity', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_cta_url(): string {
|
||||
$settings = $this->elementor_adapter->get_kit_settings();
|
||||
|
||||
$tab = ! $settings['custom_colors'] ? 'global-typography' : 'global-colors';
|
||||
|
||||
return Page::get_site_settings_url_config( $tab )['url'];
|
||||
}
|
||||
|
||||
public function get_is_completion_immutable(): bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get_image_src(): string {
|
||||
return 'https://assets.elementor.com/checklist/v1/images/checklist-step-2.jpg';
|
||||
}
|
||||
|
||||
public function get_learn_more_url(): string {
|
||||
return 'http://go.elementor.com/app-website-checklist-global-article';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\Checklist\Steps;
|
||||
|
||||
use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
|
||||
use Elementor\Utils;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Setup_Header extends Step_Base {
|
||||
const STEP_ID = 'setup_header';
|
||||
|
||||
public function __construct( $module, $wordpress_adapter = null, $elementor_adapter = null, $should_promote = true ) {
|
||||
$promotion_data = $should_promote
|
||||
? $this->render_promotion()
|
||||
: null;
|
||||
|
||||
parent::__construct( $module, $wordpress_adapter, $elementor_adapter, $promotion_data );
|
||||
}
|
||||
|
||||
public function get_id(): string {
|
||||
return self::STEP_ID;
|
||||
}
|
||||
|
||||
public function is_visible(): bool {
|
||||
if ( Utils::has_pro() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return parent::is_visible();
|
||||
}
|
||||
|
||||
public function is_absolute_completed(): bool {
|
||||
$args = [
|
||||
'post_type' => 'elementor_library',
|
||||
'meta_query' => [
|
||||
'relation' => 'AND',
|
||||
[
|
||||
'key' => '_elementor_template_type',
|
||||
'value' => 'header',
|
||||
'compare' => '=',
|
||||
],
|
||||
[
|
||||
'key' => '_elementor_conditions',
|
||||
],
|
||||
],
|
||||
'posts_per_page' => 1,
|
||||
'fields' => 'ids',
|
||||
'no_found_rows' => true,
|
||||
'update_post_term_cache' => false,
|
||||
'update_post_meta_cache' => false,
|
||||
];
|
||||
$query = $this->wordpress_adapter->get_query( $args );
|
||||
$header_templates = $query->posts ?? [];
|
||||
|
||||
return count( $header_templates ) >= 1;
|
||||
}
|
||||
|
||||
public function get_title(): string {
|
||||
return esc_html__( 'Set up a header', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_description(): string {
|
||||
return esc_html__( 'This element applies across different pages, so visitors can easily navigate around your site.', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_cta_text(): string {
|
||||
return esc_html__( 'Add a header', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_cta_url(): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
public function get_image_src(): string {
|
||||
return 'https://assets.elementor.com/checklist/v1/images/checklist-step-4.jpg';
|
||||
}
|
||||
|
||||
public function get_is_completion_immutable(): bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get_learn_more_url(): string {
|
||||
return 'https://go.elementor.com/app-website-checklist-header-article';
|
||||
}
|
||||
|
||||
private function render_promotion() {
|
||||
return Filtered_Promotions_Manager::get_filtered_promotion_data(
|
||||
[
|
||||
'url' => 'https://go.elementor.com/go-pro-website-checklist-header',
|
||||
'text' => esc_html__( 'Upgrade Now', 'elementor' ),
|
||||
'icon' => 'default',
|
||||
],
|
||||
'elementor/checklist/promotion',
|
||||
'upgrade_url'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\Checklist\Steps;
|
||||
|
||||
use Elementor\Core\Isolation\Wordpress_Adapter;
|
||||
use Elementor\Core\Isolation\Wordpress_Adapter_Interface;
|
||||
use Elementor\Core\Isolation\Elementor_Adapter;
|
||||
use Elementor\Core\Isolation\Elementor_Adapter_Interface;
|
||||
use Elementor\Core\Utils\Isolation_Manager;
|
||||
use Elementor\Modules\Checklist\Module as Checklist_Module;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
abstract class Step_Base {
|
||||
/**
|
||||
* @var string
|
||||
* This is the key to be set to true if the step can be completed, and still be considered completed even if the user later did something to the should have it marked as not completed
|
||||
*/
|
||||
const IS_COMPLETION_IMMUTABLE = 'is_completion_immutable';
|
||||
const MARKED_AS_COMPLETED_KEY = 'is_marked_completed';
|
||||
const IMMUTABLE_COMPLETION_KEY = 'is_immutable_completed';
|
||||
const ABSOLUTE_COMPLETION_KEY = 'is_absolute_completed';
|
||||
|
||||
private array $user_progress;
|
||||
protected Wordpress_Adapter_Interface $wordpress_adapter;
|
||||
protected Elementor_Adapter_Interface $elementor_adapter;
|
||||
protected ?array $promotion_data;
|
||||
protected Checklist_Module $module;
|
||||
|
||||
/**
|
||||
* Returns a steps current completion status
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function is_absolute_completed(): bool;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_id(): string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_title(): string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_description(): string;
|
||||
|
||||
/**
|
||||
* For instance; 'Create 3 pages'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_cta_text(): string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_cta_url(): string;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function get_is_completion_immutable(): bool;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_image_src(): string;
|
||||
|
||||
/**
|
||||
* Step_Base constructor.
|
||||
*
|
||||
* @param Checklist_Module $module
|
||||
* @param ?Wordpress_Adapter_Interface $wordpress_adapter
|
||||
* @param ?Elementor_Adapter_Interface $elementor_adapter
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( Checklist_Module $module, ?Wordpress_Adapter_Interface $wordpress_adapter = null, ?Elementor_Adapter_Interface $elementor_adapter = null, $promotion_data = null ) {
|
||||
$this->module = $module;
|
||||
$this->wordpress_adapter = $wordpress_adapter ?? Isolation_Manager::get_adapter( Wordpress_Adapter::class );
|
||||
$this->elementor_adapter = $elementor_adapter ?? Isolation_Manager::get_adapter( Elementor_Adapter::class );
|
||||
$this->promotion_data = $promotion_data;
|
||||
$this->user_progress = $module->get_step_progress( $this->get_id() ) ?? $this->get_step_initial_progress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns step visibility (by-default step is visible)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_visible(): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get_learn_more_text(): string {
|
||||
return esc_html__( 'Learn more', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_learn_more_url(): string {
|
||||
return 'https://go.elementor.com/getting-started-with-elementor/';
|
||||
}
|
||||
|
||||
public function update_step( array $step_data ): void {
|
||||
$allowed_properties = [
|
||||
self::MARKED_AS_COMPLETED_KEY => $step_data[ self::MARKED_AS_COMPLETED_KEY ] ?? null,
|
||||
self::IMMUTABLE_COMPLETION_KEY => $step_data[ self::IMMUTABLE_COMPLETION_KEY ] ?? null,
|
||||
self::ABSOLUTE_COMPLETION_KEY => $step_data[ self::ABSOLUTE_COMPLETION_KEY ] ?? null,
|
||||
];
|
||||
|
||||
foreach ( $allowed_properties as $key => $value ) {
|
||||
if ( null !== $value ) {
|
||||
$this->user_progress[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$this->set_step_progress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Marking a step as completed based on user's desire
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function mark_as_completed(): void {
|
||||
$this->update_step( [ self::MARKED_AS_COMPLETED_KEY => true ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmarking a step as completed based on user's desire
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unmark_as_completed(): void {
|
||||
$this->update_step( [ self::MARKED_AS_COMPLETED_KEY => false ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Marking a step as completed if it was completed once, and it's suffice to marketing's requirements
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_immutably_mark_as_completed(): void {
|
||||
$is_immutable_completed = $this->user_progress[ self::IMMUTABLE_COMPLETION_KEY ] ?? false;
|
||||
|
||||
if ( ! $is_immutable_completed && $this->get_is_completion_immutable() && $this->is_absolute_completed() ) {
|
||||
$this->update_step( [
|
||||
self::MARKED_AS_COMPLETED_KEY => false,
|
||||
self::IMMUTABLE_COMPLETION_KEY => true,
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the step marked as completed value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_marked_as_completed(): bool {
|
||||
return $this->user_progress[ self::MARKED_AS_COMPLETED_KEY ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the step completed value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_immutable_completed(): bool {
|
||||
return $this->get_is_completion_immutable() && $this->user_progress[ self::IMMUTABLE_COMPLETION_KEY ] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets and returns the initial progress of the step
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_step_initial_progress(): array {
|
||||
$initial_progress = [
|
||||
self::MARKED_AS_COMPLETED_KEY => false,
|
||||
self::IMMUTABLE_COMPLETION_KEY => false,
|
||||
];
|
||||
|
||||
$this->module->set_step_progress( $this->get_id(), $initial_progress );
|
||||
|
||||
return $initial_progress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?array
|
||||
*/
|
||||
public function get_promotion_data(): ?array {
|
||||
return $this->promotion_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the step progress
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function set_step_progress(): void {
|
||||
$this->module->set_step_progress( $this->get_id(), $this->user_progress );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user