PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.0
Elementor Website Builder – more than just a page builder v4.2.0
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / pro-install / plugin-installer.php

plugin-installer.php in Elementor Website Builder – more than just a page builder 4.2.0, at modules/pro-install/plugin-installer.php

89 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\ProInstall;
3
4 class Plugin_Installer {
5
6 private $plugin_slug;
7 private $package_url;
8
9 public function __construct( $plugin_slug, $package_url = null ) {
10 $this->plugin_slug = $plugin_slug;
11 $this->package_url = $package_url;
12 }
13
14 public function install() {
15 $this->includes_dependencies();
16
17 $plugin_data = $this->get_plugin_path();
18 if ( empty( $plugin_data ) ) {
19 $install_result = $this->do_install();
20 if ( null === $install_result || is_wp_error( $install_result ) ) {
21 return new \WP_Error( 'cant_installed', esc_html__( 'There are no available subscriptions at the moment.', 'elementor' ) );
22 }
23 }
24
25 $is_activated = $this->activate();
26 if ( is_wp_error( $is_activated ) ) {
27 return $is_activated;
28 }
29
30 return true;
31 }
32
33 private function get_package_url() {
34 return $this->package_url;
35 }
36
37 private function includes_dependencies() {
38 include_once ABSPATH . '/wp-admin/includes/admin.php';
39 include_once ABSPATH . '/wp-admin/includes/plugin-install.php';
40 include_once ABSPATH . '/wp-admin/includes/plugin.php';
41 include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
42 include_once ABSPATH . '/wp-admin/includes/class-plugin-upgrader.php';
43 }
44
45 private function do_install() {
46 $package_url = $this->get_package_url();
47 if ( empty( $package_url ) ) {
48 return new \WP_Error( 'no_package_url', sprintf( 'The requested plugin `%s` has no package URL', $this->plugin_slug ) );
49 }
50
51 $upgrader = new \Plugin_Upgrader( new \Automatic_Upgrader_Skin() );
52
53 return $upgrader->install( $package_url );
54 }
55
56 private function get_plugin_path() {
57 $plugins = get_plugins();
58 $installed_plugins = [];
59
60 foreach ( $plugins as $path => $plugin ) {
61 $path_parts = explode( '/', $path );
62 $slug = $path_parts[0];
63 $installed_plugins[ $slug ] = $path;
64 }
65
66 if ( empty( $installed_plugins[ $this->plugin_slug ] ) ) {
67 return false;
68 }
69
70 return $installed_plugins[ $this->plugin_slug ];
71 }
72
73 public function activate() {
74 $plugin_path = $this->get_plugin_path();
75
76 if ( ! $plugin_path ) {
77 return new \WP_Error( 'no_installed', sprintf( 'The requested plugin `%s` is not installed', $this->plugin_slug ) );
78 }
79
80 $activate_result = activate_plugin( $plugin_path );
81
82 if ( is_wp_error( $activate_result ) ) {
83 return $activate_result;
84 }
85
86 return true;
87 }
88 }
89