first commit

This commit is contained in:
2026-05-25 14:34:29 +02:00
commit 64f5e06629
4236 changed files with 1314148 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
<?php
namespace Elementor\App\Modules\Onboarding\Storage\Entities;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class User_Choices {
private ?string $building_for = null;
private array $site_about = [];
private ?string $experience_level = null;
private ?string $theme_selection = null;
private array $site_features = [];
public static function from_array( array $data ): self {
$instance = new self();
$instance->building_for = $data['building_for'] ?? null;
$instance->site_about = $data['site_about'] ?? [];
$instance->experience_level = $data['experience_level'] ?? null;
$instance->theme_selection = $data['theme_selection'] ?? null;
$instance->site_features = $data['site_features'] ?? [];
return $instance;
}
public function to_array(): array {
return [
'building_for' => $this->building_for,
'site_about' => $this->site_about,
'experience_level' => $this->experience_level,
'theme_selection' => $this->theme_selection,
'site_features' => $this->site_features,
];
}
public function get_building_for(): ?string {
return $this->building_for;
}
public function set_building_for( ?string $value ): void {
$this->building_for = $value;
}
public function get_site_about(): array {
return $this->site_about;
}
public function set_site_about( array $value ): void {
$this->site_about = $value;
}
public function get_experience_level(): ?string {
return $this->experience_level;
}
public function set_experience_level( ?string $value ): void {
$this->experience_level = $value;
}
public function get_theme_selection(): ?string {
return $this->theme_selection;
}
public function set_theme_selection( ?string $value ): void {
$this->theme_selection = $value;
}
public function get_site_features(): array {
return $this->site_features;
}
public function set_site_features( array $value ): void {
$this->site_features = $value;
}
}

View File

@@ -0,0 +1,129 @@
<?php
namespace Elementor\App\Modules\Onboarding\Storage\Entities;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class User_Progress {
private int $current_step_index = 0;
private ?string $current_step_id = null;
private array $completed_steps = [];
private ?string $exit_type = null;
private ?int $last_active_timestamp = null;
private ?int $started_at = null;
private bool $starter_dismissed = false;
public static function from_array( array $data ): self {
$instance = new self();
$instance->current_step_index = $data['current_step_index'] ?? $data['current_step'] ?? 0;
$instance->current_step_id = $data['current_step_id'] ?? null;
$instance->completed_steps = $data['completed_steps'] ?? [];
$instance->exit_type = $data['exit_type'] ?? null;
$instance->last_active_timestamp = $data['last_active_timestamp'] ?? null;
$instance->started_at = $data['started_at'] ?? null;
$instance->starter_dismissed = ! empty( $data['starter_dismissed'] );
return $instance;
}
public function to_array(): array {
return [
'current_step' => $this->current_step_index,
'current_step_index' => $this->current_step_index,
'current_step_id' => $this->current_step_id,
'completed_steps' => $this->completed_steps,
'exit_type' => $this->exit_type,
'last_active_timestamp' => $this->last_active_timestamp,
'started_at' => $this->started_at,
'starter_dismissed' => $this->starter_dismissed,
];
}
public function get_current_step(): int {
return $this->current_step_index;
}
public function get_current_step_index(): int {
return $this->current_step_index;
}
public function set_current_step_index( int $index ): void {
$this->current_step_index = $index;
}
public function get_current_step_id(): ?string {
return $this->current_step_id;
}
public function set_current_step_id( ?string $step_id ): void {
$this->current_step_id = $step_id;
}
public function set_current_step( int $step, ?string $step_id = null ): void {
$this->current_step_index = $step;
if ( null !== $step_id ) {
$this->current_step_id = $step_id;
}
}
public function get_completed_steps(): array {
return $this->completed_steps;
}
public function set_completed_steps( array $steps ): void {
$this->completed_steps = $steps;
}
public function add_completed_step( $step ): void {
if ( ! in_array( $step, $this->completed_steps, true ) ) {
$this->completed_steps[] = $step;
}
}
public function is_step_completed( $step ): bool {
return in_array( $step, $this->completed_steps, true );
}
public function get_exit_type(): ?string {
return $this->exit_type;
}
public function set_exit_type( ?string $type ): void {
$this->exit_type = $type;
}
public function get_last_active_timestamp(): ?int {
return $this->last_active_timestamp;
}
public function set_last_active_timestamp( ?int $timestamp ): void {
$this->last_active_timestamp = $timestamp;
}
public function get_started_at(): ?int {
return $this->started_at;
}
public function set_started_at( ?int $timestamp ): void {
$this->started_at = $timestamp;
}
public function is_starter_dismissed(): bool {
return $this->starter_dismissed;
}
public function set_starter_dismissed( bool $dismissed ): void {
$this->starter_dismissed = $dismissed;
}
public function had_unexpected_exit( bool $is_completed ): bool {
return null === $this->exit_type
&& $this->current_step_index > 0
&& ! $is_completed;
}
}

View File

@@ -0,0 +1,148 @@
<?php
namespace Elementor\App\Modules\Onboarding\Storage;
use Elementor\App\Modules\Onboarding\Module;
use Elementor\App\Modules\Onboarding\Storage\Entities\User_Choices;
use Elementor\App\Modules\Onboarding\Storage\Entities\User_Progress;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Onboarding_Progress_Manager {
const PROGRESS_OPTION_KEY = 'elementor_onboarding_progress';
const CHOICES_OPTION_KEY = 'elementor_onboarding_choices';
const DEFAULT_TOTAL_STEPS = 5;
private static ?Onboarding_Progress_Manager $instance = null;
public static function instance(): Onboarding_Progress_Manager {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function get_progress(): User_Progress {
$data = get_option( self::PROGRESS_OPTION_KEY, [] );
return User_Progress::from_array( $data );
}
public function save_progress( User_Progress $progress ): User_Progress {
update_option( self::PROGRESS_OPTION_KEY, $progress->to_array() );
return $progress;
}
public function update_progress( array $params ): User_Progress {
$progress = $this->get_progress();
if ( isset( $params['current_step'] ) ) {
$progress->set_current_step( (int) $params['current_step'] );
}
if ( isset( $params['completed_steps'] ) ) {
$progress->set_completed_steps( (array) $params['completed_steps'] );
}
if ( isset( $params['exit_type'] ) ) {
$progress->set_exit_type( $params['exit_type'] );
}
if ( isset( $params['complete_step'] ) ) {
$step = $params['complete_step'];
$progress->add_completed_step( $step );
$step_index = $params['step_index'] ?? $progress->get_current_step_index();
$total_steps = $params['total_steps'] ?? self::DEFAULT_TOTAL_STEPS;
$next_index = $step_index + 1;
if ( $next_index < $total_steps ) {
$progress->set_current_step_index( $next_index );
$progress->set_current_step_id( null );
}
}
if ( ! empty( $params['skip_step'] ) ) {
$step_index = $params['step_index'] ?? $progress->get_current_step_index();
$total_steps = $params['total_steps'] ?? self::DEFAULT_TOTAL_STEPS;
$next_index = $step_index + 1;
if ( $next_index < $total_steps ) {
$progress->set_current_step_index( $next_index );
$progress->set_current_step_id( null );
}
}
if ( isset( $params['start'] ) && $params['start'] ) {
$progress->set_started_at( current_time( 'timestamp' ) );
$progress->set_exit_type( null );
}
if ( isset( $params['complete'] ) && $params['complete'] ) {
$progress->set_exit_type( 'user_exit' );
update_option( Module::ONBOARDING_OPTION, Module::VERSION );
}
if ( isset( $params['user_exit'] ) && $params['user_exit'] ) {
$progress->set_exit_type( 'user_exit' );
}
if ( isset( $params['starter_dismissed'] ) && $params['starter_dismissed'] ) {
$progress->set_starter_dismissed( true );
}
$progress->set_last_active_timestamp( current_time( 'timestamp' ) );
return $this->save_progress( $progress );
}
public function get_choices(): User_Choices {
$data = get_option( self::CHOICES_OPTION_KEY, [] );
return User_Choices::from_array( $data );
}
public function save_choices( User_Choices $choices ): User_Choices {
update_option( self::CHOICES_OPTION_KEY, $choices->to_array() );
return $choices;
}
public function update_choices( array $params ): User_Choices {
$choices = $this->get_choices();
if ( isset( $params['building_for'] ) ) {
$choices->set_building_for( $params['building_for'] );
}
if ( isset( $params['site_about'] ) ) {
$choices->set_site_about( (array) $params['site_about'] );
}
if ( isset( $params['experience_level'] ) ) {
$choices->set_experience_level( $params['experience_level'] );
}
if ( isset( $params['theme_selection'] ) ) {
$choices->set_theme_selection( $params['theme_selection'] );
}
if ( isset( $params['site_features'] ) ) {
$choices->set_site_features( (array) $params['site_features'] );
}
return $this->save_choices( $choices );
}
public function reset(): void {
delete_option( self::PROGRESS_OPTION_KEY );
delete_option( self::CHOICES_OPTION_KEY );
}
private function __construct() {}
}