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,89 @@
<?php
namespace Elementor\App\Modules\Onboarding\Data\Endpoints;
use Elementor\Data\V2\Base\Endpoint as Endpoint_Base;
use Elementor\Modules\ProInstall\Plugin_Installer;
use Elementor\Plugin;
use Elementor\Utils;
use WP_REST_Server;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Install_Pro extends Endpoint_Base {
public function get_name(): string {
return 'install-pro';
}
public function get_format(): string {
return 'onboarding';
}
protected function register(): void {
parent::register();
$this->register_items_route( WP_REST_Server::CREATABLE );
}
public function create_items( $request ) {
if ( Utils::has_pro() || Utils::is_pro_installed_and_not_active() ) {
return [
'data' => [
'success' => true,
'message' => 'already_installed',
],
];
}
$connect = Plugin::$instance->common->get_component( 'connect' );
if ( ! $connect ) {
return new \WP_Error(
'connect_unavailable',
__( 'Connect module is not available.', 'elementor' ),
[ 'status' => 500 ]
);
}
$pro_install_app = $connect->get_app( 'pro-install' );
if ( ! $pro_install_app || ! $pro_install_app->is_connected() ) {
return new \WP_Error(
'not_connected',
__( 'You must be connected to install Elementor Pro.', 'elementor' ),
[ 'status' => 400 ]
);
}
$download_link = $pro_install_app->get_download_link();
if ( empty( $download_link ) ) {
return new \WP_Error(
'no_subscription',
__( 'There are no available subscriptions at the moment.', 'elementor' ),
[ 'status' => 400 ]
);
}
$plugin_installer = new Plugin_Installer( 'elementor-pro', $download_link );
$result = $plugin_installer->install();
if ( is_wp_error( $result ) ) {
return new \WP_Error(
'install_failed',
$result->get_error_message(),
[ 'status' => 500 ]
);
}
return [
'data' => [
'success' => true,
'message' => 'installed',
],
];
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace Elementor\App\Modules\Onboarding\Data\Endpoints;
use Elementor\Data\V2\Base\Endpoint as Endpoint_Base;
use WP_REST_Server;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Install_Theme extends Endpoint_Base {
const ALLOWED_THEMES = [ 'hello-elementor', 'hello-biz' ];
public function get_name(): string {
return 'install-theme';
}
public function get_format(): string {
return 'onboarding';
}
protected function register(): void {
parent::register();
$this->register_items_route( WP_REST_Server::CREATABLE );
}
public function create_items( $request ) {
$permission = $this->check_permission();
if ( is_wp_error( $permission ) ) {
return $permission;
}
$params = $request->get_json_params();
$theme_slug = $params['theme_slug'] ?? '';
if ( empty( $theme_slug ) || ! in_array( $theme_slug, self::ALLOWED_THEMES, true ) ) {
return new \WP_Error(
'invalid_theme',
__( 'Invalid or unsupported theme.', 'elementor' ),
[ 'status' => 400 ]
);
}
if ( ! current_user_can( 'install_themes' ) || ! current_user_can( 'switch_themes' ) ) {
return new \WP_Error(
'insufficient_permissions',
__( 'You do not have permission to install themes.', 'elementor' ),
[ 'status' => 403 ]
);
}
$theme = wp_get_theme( $theme_slug );
if ( ! $theme->exists() ) {
if ( ! function_exists( 'request_filesystem_credentials' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
if ( ! class_exists( '\Theme_Upgrader' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
}
if ( ! class_exists( '\WP_Ajax_Upgrader_Skin' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php';
}
$skin = new \WP_Ajax_Upgrader_Skin();
$upgrader = new \Theme_Upgrader( $skin );
$result = $upgrader->install( "https://downloads.wordpress.org/theme/{$theme_slug}.latest-stable.zip" );
if ( is_wp_error( $result ) || ! $result ) {
return new \WP_Error(
'theme_install_failed',
__( 'Failed to install the theme.', 'elementor' ),
[ 'status' => 500 ]
);
}
}
switch_theme( $theme_slug );
return [
'data' => [
'success' => true,
'message' => 'theme_installed',
],
];
}
private function check_permission() {
if ( ! current_user_can( 'manage_options' ) ) {
return new \WP_Error(
'rest_forbidden',
__( 'Sorry, you are not allowed to access onboarding data.', 'elementor' ),
[ 'status' => 403 ]
);
}
return true;
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Elementor\App\Modules\Onboarding\Data\Endpoints;
use Elementor\App\Modules\Onboarding\Module;
use Elementor\Data\V2\Base\Endpoint as Endpoint_Base;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Pro_Install_Screen extends Endpoint_Base {
public function get_name(): string {
return 'pro-install-screen';
}
public function get_format(): string {
return 'onboarding';
}
protected function register(): void {
parent::register();
$this->register_items_route();
}
public function get_items( $request ) {
return [
'data' => [
'shouldShowProInstallScreen' => Module::should_show_pro_install_screen(),
],
];
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace Elementor\App\Modules\Onboarding\Data\Endpoints;
use Elementor\App\Modules\Onboarding\Storage\Onboarding_Progress_Manager;
use Elementor\App\Modules\Onboarding\Validation\User_Choices_Validator;
use Elementor\Data\V2\Base\Endpoint as Endpoint_Base;
use WP_REST_Server;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class User_Choices extends Endpoint_Base {
public function get_name(): string {
return 'user-choices';
}
public function get_format(): string {
return 'onboarding';
}
protected function register(): void {
parent::register();
$this->register_items_route( WP_REST_Server::EDITABLE );
}
public function get_items( $request ) {
$permission = $this->check_permission();
if ( is_wp_error( $permission ) ) {
return $permission;
}
$manager = Onboarding_Progress_Manager::instance();
$choices = $manager->get_choices();
return [
'data' => $choices->to_array(),
];
}
public function update_items( $request ) {
$permission = $this->check_permission();
if ( is_wp_error( $permission ) ) {
return $permission;
}
$params = $request->get_json_params();
$validator = new User_Choices_Validator();
$validated = $validator->validate( $params ?? [] );
if ( is_wp_error( $validated ) ) {
return $validated;
}
$manager = Onboarding_Progress_Manager::instance();
$choices = $manager->update_choices( $validated );
return [
'data' => 'success',
'choices' => $choices->to_array(),
];
}
private function check_permission() {
if ( ! current_user_can( 'manage_options' ) ) {
return new \WP_Error(
'rest_forbidden',
__( 'Sorry, you are not allowed to access onboarding data.', 'elementor' ),
[ 'status' => 403 ]
);
}
return true;
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace Elementor\App\Modules\Onboarding\Data\Endpoints;
use Elementor\App\Modules\Onboarding\Module;
use Elementor\App\Modules\Onboarding\Storage\Onboarding_Progress_Manager;
use Elementor\App\Modules\Onboarding\Validation\User_Progress_Validator;
use Elementor\Data\V2\Base\Endpoint as Endpoint_Base;
use WP_REST_Server;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class User_Progress extends Endpoint_Base {
public function get_name(): string {
return 'user-progress';
}
public function get_format(): string {
return 'onboarding';
}
protected function register(): void {
parent::register();
$this->register_items_route( WP_REST_Server::EDITABLE );
}
public function get_items( $request ) {
$permission = $this->check_permission();
if ( is_wp_error( $permission ) ) {
return $permission;
}
$manager = Onboarding_Progress_Manager::instance();
$progress = $manager->get_progress();
return [
'data' => $progress->to_array(),
'meta' => [
'had_unexpected_exit' => $progress->had_unexpected_exit( Module::has_user_finished_onboarding() ),
],
];
}
public function update_items( $request ) {
$permission = $this->check_permission();
if ( is_wp_error( $permission ) ) {
return $permission;
}
$params = $request->get_json_params();
$validator = new User_Progress_Validator();
$validated = $validator->validate( $params ?? [] );
if ( is_wp_error( $validated ) ) {
return $validated;
}
$manager = Onboarding_Progress_Manager::instance();
$progress = $manager->update_progress( $validated );
return [
'data' => 'success',
'progress' => $progress->to_array(),
];
}
private function check_permission() {
if ( ! current_user_can( 'manage_options' ) ) {
return new \WP_Error(
'rest_forbidden',
__( 'Sorry, you are not allowed to access onboarding data.', 'elementor' ),
[ 'status' => 403 ]
);
}
return true;
}
}