first commit
This commit is contained in:
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
namespace Elementor\Modules\ProInstall;
|
||||
|
||||
use Elementor\Plugin;
|
||||
use Elementor\Utils;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Connect_Page_Renderer {
|
||||
|
||||
private Connect $connect;
|
||||
|
||||
private string $page_url;
|
||||
|
||||
private ?array $script_config;
|
||||
|
||||
public function __construct( Connect $connect, string $page_url, ?array $script_config = null ) {
|
||||
$this->connect = $connect;
|
||||
$this->page_url = $page_url;
|
||||
$this->script_config = $script_config;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
if ( $this->script_config ) {
|
||||
wp_enqueue_script( ...$this->script_config );
|
||||
}
|
||||
?>
|
||||
<div class="wrap elementor-admin-page-license">
|
||||
<h2 class="wp-heading-inline"><?php echo esc_html__( 'Connect Settings', 'elementor' ); ?></h2>
|
||||
<?php
|
||||
if ( ! $this->connect->is_connected() ) {
|
||||
$this->render_connect_box();
|
||||
} else {
|
||||
$this->render_license_box();
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private function render_connect_box() {
|
||||
$connect_url = $this->connect->get_admin_url( 'authorize', [
|
||||
'utm_source' => 'license-page-connect-free',
|
||||
'utm_medium' => 'wp-dash',
|
||||
'utm_campaign' => 'connect-and-activate-license',
|
||||
'redirect_to' => $this->page_url,
|
||||
] );
|
||||
|
||||
?>
|
||||
<div class="<?php echo esc_attr( $this->get_license_box_classes() ); ?>">
|
||||
<h3><?php echo esc_html__( 'Connect your Elementor Account', 'elementor' ); ?></h3>
|
||||
|
||||
<p>
|
||||
<?php echo esc_html__( 'Gain access to dozens of professionally designed templates, and connect your site to your My Elementor Dashboard.', 'elementor' ); ?>
|
||||
</p>
|
||||
|
||||
<div class="elementor-box-action">
|
||||
<a id="elementor-connect-license" class="button button-primary" href="<?php echo esc_url( $connect_url ); ?>">
|
||||
<?php echo esc_html__( 'Connect to Elementor', 'elementor' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private function render_license_box() {
|
||||
$disconnect_url = $this->connect->get_admin_url( 'disconnect', [
|
||||
'redirect_to' => $this->page_url,
|
||||
] );
|
||||
$download_link = $this->connect->get_download_link();
|
||||
|
||||
?>
|
||||
<div class="<?php echo esc_attr( $this->get_license_box_classes() ); ?>">
|
||||
<h3>
|
||||
<?php echo esc_html__( 'Status', 'elementor' ); ?>:
|
||||
<span style="color: #008000; font-style: italic;"><?php echo esc_html__( 'Connected', 'elementor' ); ?></span>
|
||||
<small>
|
||||
<a class="button" href="https://go.elementor.com/my-account/" target="_blank">
|
||||
<?php echo esc_html__( 'My Account', 'elementor' ); ?>
|
||||
</a>
|
||||
</small>
|
||||
</h3>
|
||||
|
||||
<p class="e-row-stretch e-row-divider-bottom">
|
||||
<span>
|
||||
<?php
|
||||
$connected_user = $this->get_connected_account();
|
||||
|
||||
if ( $connected_user ) :
|
||||
printf(
|
||||
/* translators: %s: Connected user. */
|
||||
esc_html__( 'You\'re connected as %s.', 'elementor' ),
|
||||
'<strong>' . esc_html( $connected_user ) . '</strong>'
|
||||
);
|
||||
endif;
|
||||
?>
|
||||
</span>
|
||||
</p>
|
||||
|
||||
<p class="e-row-stretch">
|
||||
<span><?php echo esc_html__( 'Want to disconnect for any reason?', 'elementor' ); ?></span>
|
||||
<a class="button" href="<?php echo esc_url( $disconnect_url ); ?>">
|
||||
<?php echo esc_html__( 'Disconnect', 'elementor' ); ?>
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
if ( empty( $download_link ) ) {
|
||||
$this->render_promotion_box();
|
||||
} else {
|
||||
$this->render_install_or_activate_box();
|
||||
}
|
||||
}
|
||||
|
||||
private function get_connected_account() {
|
||||
$user = $this->connect->get( 'user' );
|
||||
|
||||
$email = '';
|
||||
if ( $user ) {
|
||||
$email = $user->email;
|
||||
}
|
||||
|
||||
return $email;
|
||||
}
|
||||
|
||||
private function render_promotion_box() {
|
||||
?>
|
||||
<div class="<?php echo esc_attr( $this->get_license_box_classes( 'elementor-pro-connect-promotion' ) ); ?>">
|
||||
<div>
|
||||
<h2><?php echo esc_html__( 'Upgrade to Pro to unlock powerful design tools and advanced features.', 'elementor' ); ?></h2>
|
||||
<p><?php echo esc_html__( 'Build custom headers, footers, forms, popups, and WooCommerce stores.', 'elementor' ); ?></p>
|
||||
<div class="elementor-box-action">
|
||||
<a class="button button-upgrade" href="https://go.elementor.com/go-pro-connect-account-screen" target="_blank">
|
||||
<i class="eicon-upgrade-crown" aria-hidden="true"></i>
|
||||
<?php echo esc_html__( 'Upgrade Now', 'elementor' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<img src="https://assets.elementor.com/free-to-pro-upsell/v1/images/connect-pro-upgrade.jpg" alt="<?php echo esc_attr__( 'Pro Upgrade', 'elementor' ); ?>" />
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private function render_install_or_activate_box() {
|
||||
$cta_data = $this->get_cta_data();
|
||||
$cta_url = wp_nonce_url( admin_url( 'admin-post.php?action=elementor_do_pro_install' ), 'elementor_do_pro_install' );
|
||||
$cta_id = Utils::is_pro_installed_and_not_active() ? 'elementor-connect-activate-pro' : 'elementor-connect-install-pro';
|
||||
|
||||
?>
|
||||
<div class="<?php echo esc_attr( $this->get_license_box_classes() ); ?>">
|
||||
<h3><?php echo esc_html__( 'You\'ve got Elementor Pro', 'elementor' ); ?></h3>
|
||||
|
||||
<p><?php echo esc_html( $cta_data['description'] ); ?></p>
|
||||
<p class="elementor-box-action">
|
||||
<a id="<?php echo esc_attr( $cta_id ); ?>" class="button button-primary" href="<?php echo esc_url( $cta_url ); ?>">
|
||||
<?php echo esc_html( $cta_data['button_text'] ); ?>
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private function get_cta_data(): array {
|
||||
return [
|
||||
'description' => esc_html__( 'Enjoy full access to powerful design tools, advanced widgets, and everything you need to create next-level websites.', 'elementor' ),
|
||||
'button_text' => Utils::is_pro_installed_and_not_active() ? esc_html__( 'Activate Elementor Pro', 'elementor' ) : esc_html__( 'Install & Activate', 'elementor' ),
|
||||
];
|
||||
}
|
||||
|
||||
private function get_license_box_classes( string $additional_classes = '' ): string {
|
||||
$classes = [ 'elementor-license-box' ];
|
||||
|
||||
if ( $additional_classes ) {
|
||||
$classes[] = $additional_classes;
|
||||
}
|
||||
|
||||
if ( Plugin::$instance->experiments->is_feature_active( 'e_editor_one' ) ) {
|
||||
$classes[] = 'e-one-section-outlined';
|
||||
}
|
||||
|
||||
return implode( ' ', $classes );
|
||||
}
|
||||
}
|
||||
|
||||
43
wp-content/plugins/elementor/modules/pro-install/connect.php
Normal file
43
wp-content/plugins/elementor/modules/pro-install/connect.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace Elementor\Modules\ProInstall;
|
||||
|
||||
use Elementor\Core\Common\Modules\Connect\Apps\Library;
|
||||
use Elementor\Utils as ElementorUtils;
|
||||
use Elementor\Plugin;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Connect extends Library {
|
||||
|
||||
const API_URL = 'https://my.elementor.com/api/v2/artifacts/PLUGIN/';
|
||||
|
||||
public function get_title() {
|
||||
return esc_html__( 'pro-install', 'elementor' );
|
||||
}
|
||||
|
||||
protected function get_api_url() {
|
||||
return static::API_URL . '/';
|
||||
}
|
||||
|
||||
public function get_download_link() {
|
||||
$response = $this->http_request(
|
||||
'GET',
|
||||
'latest/download-link',
|
||||
[],
|
||||
[
|
||||
'return_type' => static::HTTP_RETURN_TYPE_ARRAY,
|
||||
'with_error_data' => true,
|
||||
]
|
||||
);
|
||||
|
||||
if ( is_wp_error( $response ) || empty( $response['downloadLink'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $response['downloadLink'];
|
||||
}
|
||||
|
||||
protected function init() {}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\ProInstall;
|
||||
|
||||
use Elementor\Core\Admin\EditorOneMenu\Interfaces\Menu_Item_Interface;
|
||||
use Elementor\Modules\EditorOne\Classes\Menu_Config;
|
||||
use Elementor\Plugin;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Editor_One_Connect_Account_Menu_Item implements Menu_Item_Interface {
|
||||
|
||||
private $connect;
|
||||
private $script_config;
|
||||
|
||||
public function __construct( Connect $connect, array $script_config ) {
|
||||
$this->connect = $connect;
|
||||
$this->script_config = $script_config;
|
||||
}
|
||||
|
||||
public function get_capability(): string {
|
||||
return 'manage_options';
|
||||
}
|
||||
|
||||
public function get_parent_slug(): string {
|
||||
return Menu_Config::ELEMENTOR_MENU_SLUG;
|
||||
}
|
||||
|
||||
public function is_visible(): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get_label(): string {
|
||||
return esc_html__( 'Connect Account', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_page_title(): string {
|
||||
return esc_html__( 'Connect Settings', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_position(): int {
|
||||
return 1000;
|
||||
}
|
||||
|
||||
public function get_slug(): string {
|
||||
return 'elementor-connect-account';
|
||||
}
|
||||
|
||||
public function get_icon(): string {
|
||||
return 'sync';
|
||||
}
|
||||
|
||||
public function get_group_id(): string {
|
||||
return Menu_Config::SYSTEM_GROUP_ID;
|
||||
}
|
||||
|
||||
public function has_children(): bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
$page_url = admin_url( 'admin.php?page=elementor-connect-account' );
|
||||
$renderer = new Connect_Page_Renderer( $this->connect, $page_url, $this->script_config );
|
||||
$renderer->render();
|
||||
}
|
||||
}
|
||||
102
wp-content/plugins/elementor/modules/pro-install/module.php
Normal file
102
wp-content/plugins/elementor/modules/pro-install/module.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
namespace Elementor\Modules\ProInstall;
|
||||
|
||||
use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
|
||||
use Elementor\Core\Common\Modules\Connect\Module as ConnectModule;
|
||||
use Elementor\Core\Base\Module as BaseModule;
|
||||
use Elementor\Plugin;
|
||||
use Elementor\Utils;
|
||||
use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Module extends BaseModule {
|
||||
|
||||
public function get_name() {
|
||||
return 'pro-install';
|
||||
}
|
||||
|
||||
public static function is_active() {
|
||||
return ! Utils::has_pro() && current_user_can( 'manage_options' );
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
add_action( 'admin_post_elementor_do_pro_install', [ $this, 'admin_post_elementor_do_pro_install' ] );
|
||||
|
||||
add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) {
|
||||
$connect_module->register_app( 'pro-install', Connect::get_class_name() );
|
||||
} );
|
||||
|
||||
add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) {
|
||||
if ( ! $this->is_editor_one_active() ) {
|
||||
$admin_menu->register(
|
||||
'elementor-connect-account',
|
||||
new Pro_Install_Menu_Item(
|
||||
$this->get_connect_app(),
|
||||
$this->get_pro_install_page_assets(),
|
||||
)
|
||||
);
|
||||
}
|
||||
}, 116 );
|
||||
|
||||
add_action( 'elementor/editor-one/menu/excluded_level3_slugs', function ( array $excluded_slugs ): array {
|
||||
$excluded_slugs[] = 'elementor-connect';
|
||||
return $excluded_slugs;
|
||||
} );
|
||||
|
||||
add_action( 'elementor/editor-one/menu/register', function( Menu_Data_Provider $menu_data_provider ) {
|
||||
$menu_data_provider->register_menu(
|
||||
new Editor_One_Connect_Account_Menu_Item(
|
||||
$this->get_connect_app(),
|
||||
$this->get_pro_install_page_assets()
|
||||
)
|
||||
);
|
||||
} );
|
||||
}
|
||||
|
||||
private function is_editor_one_active(): bool {
|
||||
return (bool) Plugin::instance()->modules_manager->get_modules( 'editor-one' );
|
||||
}
|
||||
|
||||
private function get_connect_app(): Connect {
|
||||
return Plugin::$instance->common->get_component( 'connect' )->get_app( 'pro-install' );
|
||||
}
|
||||
|
||||
public function admin_post_elementor_do_pro_install() {
|
||||
if ( ! current_user_can( 'install_plugins' ) ) {
|
||||
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'elementor' ) );
|
||||
}
|
||||
|
||||
check_admin_referer( 'elementor_do_pro_install' );
|
||||
|
||||
$app = $this->get_connect_app();
|
||||
$download_link = $app->get_download_link();
|
||||
|
||||
if ( empty( $download_link ) ) {
|
||||
wp_die( esc_html__( 'There are no available subscriptions at the moment.', 'elementor' ) );
|
||||
}
|
||||
|
||||
$plugin_installer = new Plugin_Installer( 'elementor-pro', $download_link );
|
||||
$response = $plugin_installer->install();
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
wp_die( esc_html( $response->get_error_message() ) );
|
||||
}
|
||||
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=elementor-license' ) );
|
||||
}
|
||||
|
||||
private function get_pro_install_page_assets(): array {
|
||||
return [
|
||||
'elementor-pro-install-events',
|
||||
$this->get_js_assets_url( 'pro-install-events' ),
|
||||
[ 'elementor-common' ],
|
||||
ELEMENTOR_VERSION,
|
||||
true,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace Elementor\Modules\ProInstall;
|
||||
|
||||
class Plugin_Installer {
|
||||
|
||||
private $plugin_slug;
|
||||
private $package_url;
|
||||
|
||||
public function __construct( $plugin_slug, $package_url = null ) {
|
||||
$this->plugin_slug = $plugin_slug;
|
||||
$this->package_url = $package_url;
|
||||
}
|
||||
|
||||
public function install() {
|
||||
$this->includes_dependencies();
|
||||
|
||||
$plugin_data = $this->get_plugin_path();
|
||||
if ( empty( $plugin_data ) ) {
|
||||
$install_result = $this->do_install();
|
||||
if ( null === $install_result || is_wp_error( $install_result ) ) {
|
||||
return new \WP_Error( 'cant_installed', esc_html__( 'There are no available subscriptions at the moment.', 'elementor' ) );
|
||||
}
|
||||
}
|
||||
|
||||
$is_activated = $this->activate();
|
||||
if ( is_wp_error( $is_activated ) ) {
|
||||
return $is_activated;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function get_package_url() {
|
||||
return $this->package_url;
|
||||
}
|
||||
|
||||
private function includes_dependencies() {
|
||||
include_once ABSPATH . '/wp-admin/includes/admin.php';
|
||||
include_once ABSPATH . '/wp-admin/includes/plugin-install.php';
|
||||
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
||||
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
|
||||
include_once ABSPATH . '/wp-admin/includes/class-plugin-upgrader.php';
|
||||
}
|
||||
|
||||
private function do_install() {
|
||||
$package_url = $this->get_package_url();
|
||||
if ( empty( $package_url ) ) {
|
||||
return new \WP_Error( 'no_package_url', sprintf( 'The requested plugin `%s` has no package URL', $this->plugin_slug ) );
|
||||
}
|
||||
|
||||
$upgrader = new \Plugin_Upgrader( new \Automatic_Upgrader_Skin() );
|
||||
|
||||
return $upgrader->install( $package_url );
|
||||
}
|
||||
|
||||
private function get_plugin_path() {
|
||||
$plugins = get_plugins();
|
||||
$installed_plugins = [];
|
||||
|
||||
foreach ( $plugins as $path => $plugin ) {
|
||||
$path_parts = explode( '/', $path );
|
||||
$slug = $path_parts[0];
|
||||
$installed_plugins[ $slug ] = $path;
|
||||
}
|
||||
|
||||
if ( empty( $installed_plugins[ $this->plugin_slug ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $installed_plugins[ $this->plugin_slug ];
|
||||
}
|
||||
|
||||
public function activate() {
|
||||
$plugin_path = $this->get_plugin_path();
|
||||
|
||||
if ( ! $plugin_path ) {
|
||||
return new \WP_Error( 'no_installed', sprintf( 'The requested plugin `%s` is not installed', $this->plugin_slug ) );
|
||||
}
|
||||
|
||||
$activate_result = activate_plugin( $plugin_path );
|
||||
|
||||
if ( is_wp_error( $activate_result ) ) {
|
||||
return $activate_result;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace Elementor\Modules\ProInstall;
|
||||
|
||||
use Elementor\Core\Admin\Menu\Interfaces\Admin_Menu_Item_With_Page;
|
||||
use Elementor\Settings;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Pro_Install_Menu_Item implements Admin_Menu_Item_With_Page {
|
||||
|
||||
private Connect_Page_Renderer $renderer;
|
||||
|
||||
public function __construct( Connect $connect, array $script_config ) {
|
||||
$page_url = admin_url( 'admin.php?page=elementor-connect-account' );
|
||||
$this->renderer = new Connect_Page_Renderer( $connect, $page_url, $script_config );
|
||||
}
|
||||
|
||||
public function get_label(): string {
|
||||
return esc_html__( 'Connect Account', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_page_title(): string {
|
||||
return esc_html__( 'Connect Settings', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_capability(): string {
|
||||
return 'manage_options';
|
||||
}
|
||||
|
||||
public function get_parent_slug(): string {
|
||||
return Settings::PAGE_ID;
|
||||
}
|
||||
|
||||
public function is_visible(): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
$this->renderer->render();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user