| 1 |
<?php |
| 2 |
namespace Elementor\Modules\ProInstall; |
| 3 |
|
| 4 |
use Elementor\Core\Common\Modules\Connect\Module as ConnectModule; |
| 5 |
use Elementor\Core\Base\Module as BaseModule; |
| 6 |
use Elementor\Plugin; |
| 7 |
use Elementor\Utils; |
| 8 |
use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; // Exit if accessed directly. |
| 12 |
} |
| 13 |
|
| 14 |
class Module extends BaseModule { |
| 15 |
|
| 16 |
public function get_name() { |
| 17 |
return 'pro-install'; |
| 18 |
} |
| 19 |
|
| 20 |
public static function is_active() { |
| 21 |
return ! Utils::has_pro() && current_user_can( 'manage_options' ); |
| 22 |
} |
| 23 |
|
| 24 |
public function __construct() { |
| 25 |
parent::__construct(); |
| 26 |
|
| 27 |
add_action( 'admin_post_elementor_do_pro_install', [ $this, 'admin_post_elementor_do_pro_install' ] ); |
| 28 |
|
| 29 |
add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) { |
| 30 |
$connect_module->register_app( 'pro-install', Connect::get_class_name() ); |
| 31 |
} ); |
| 32 |
|
| 33 |
add_action( 'elementor/editor-one/menu/excluded_level3_slugs', function ( array $excluded_slugs ): array { |
| 34 |
$excluded_slugs[] = 'elementor-connect'; |
| 35 |
return $excluded_slugs; |
| 36 |
} ); |
| 37 |
|
| 38 |
add_action( 'elementor/editor-one/menu/register', function( Menu_Data_Provider $menu_data_provider ) { |
| 39 |
$menu_data_provider->register_menu( |
| 40 |
new Editor_One_Connect_Account_Menu_Item( |
| 41 |
$this->get_connect_app(), |
| 42 |
$this->get_pro_install_page_assets() |
| 43 |
) |
| 44 |
); |
| 45 |
} ); |
| 46 |
} |
| 47 |
|
| 48 |
private function get_connect_app(): Connect { |
| 49 |
return Plugin::$instance->common->get_component( 'connect' )->get_app( 'pro-install' ); |
| 50 |
} |
| 51 |
|
| 52 |
public function admin_post_elementor_do_pro_install() { |
| 53 |
if ( ! current_user_can( 'install_plugins' ) ) { |
| 54 |
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'elementor' ) ); |
| 55 |
} |
| 56 |
|
| 57 |
check_admin_referer( 'elementor_do_pro_install' ); |
| 58 |
|
| 59 |
$app = $this->get_connect_app(); |
| 60 |
$download_link = $app->get_download_link(); |
| 61 |
|
| 62 |
if ( empty( $download_link ) ) { |
| 63 |
wp_die( esc_html__( 'There are no available subscriptions at the moment.', 'elementor' ) ); |
| 64 |
} |
| 65 |
|
| 66 |
$plugin_installer = new Plugin_Installer( 'elementor-pro', $download_link ); |
| 67 |
$response = $plugin_installer->install(); |
| 68 |
|
| 69 |
if ( is_wp_error( $response ) ) { |
| 70 |
wp_die( esc_html( $response->get_error_message() ) ); |
| 71 |
} |
| 72 |
|
| 73 |
wp_safe_redirect( admin_url( 'admin.php?page=elementor-license' ) ); |
| 74 |
} |
| 75 |
|
| 76 |
private function get_pro_install_page_assets(): array { |
| 77 |
return [ |
| 78 |
'elementor-pro-install-events', |
| 79 |
$this->get_js_assets_url( 'pro-install-events' ), |
| 80 |
[ 'elementor-common' ], |
| 81 |
ELEMENTOR_VERSION, |
| 82 |
true, |
| 83 |
]; |
| 84 |
} |
| 85 |
} |
| 86 |
|