PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution with eCommerce Templates & Woo Widgets / 4.9.5
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution with eCommerce Templates & Woo Widgets v4.9.5
4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / utils / onboard / plugin-installer.php
shopengine / utils / onboard Last commit date
auto-install-notice.php 1 week ago auto-install-tracker.php 1 week ago plugin-installer.php 1 week ago plugin-skin.php 1 year ago
plugin-installer.php
127 lines
1 <?php
2
3 namespace ShopEngine\Utils\Onboard;
4
5 defined( 'ABSPATH' ) || exit;
6
7 class Plugin_Installer {
8
9 private $plugin_file;
10 private $plugin_slug;
11
12 public function __construct( $plugin_file ) {
13 $this->plugin_file = $plugin_file;
14 $this->plugin_slug = dirname( $plugin_file );
15 $this->initialize_filesystem();
16 }
17
18 /**
19 * Install and activate a plugin.
20 */
21 public function install_and_activate() {
22 if ( ! function_exists( 'is_plugin_active' ) ) {
23 require_once ABSPATH . 'wp-admin/includes/plugin.php';
24 }
25
26 if ( is_plugin_active( $this->plugin_file ) ) {
27 Auto_Install_Tracker::mark( $this->plugin_file );
28 return;
29 }
30
31 if ( $this->is_plugin_installed() ) {
32 $ignore_silent_activation = ['popup-builder-block/popup-builder-block.php'];
33 $silent = in_array( $this->plugin_file, $ignore_silent_activation ) ? false : true;
34
35 Auto_Install_Tracker::mark( $this->plugin_file );
36 activate_plugin( $this->plugin_file, '', false, $silent );
37 return true;
38 } else {
39 $this->install_plugin();
40 }
41 }
42
43 /**
44 * Install the plugin using WP_Upgrader.
45 */
46 private function install_plugin() {
47 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
48 include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
49 include_once ABSPATH . 'wp-admin/includes/plugin.php';
50
51 $plugin_info = $this->get_plugin_information( $this->plugin_slug );
52
53 if ( is_wp_error( $plugin_info ) || ! $plugin_info || empty( $plugin_info->download_link ) ) {
54 return false;
55 }
56
57 $skin = new \ShopEngine\Utils\Onboard\Plugin_Skin();
58
59 $upgrader = new \Plugin_Upgrader( $skin );
60 $upgrader->install( $plugin_info->download_link );
61
62 if ( $this->is_plugin_installed() ) {
63 $ignore_silent_activation = ['popup-builder-block/popup-builder-block.php'];
64 $silent = in_array( $this->plugin_file, $ignore_silent_activation ) ? false : true;
65
66 Auto_Install_Tracker::mark( $this->plugin_file );
67 activate_plugin( $this->plugin_file, '', false, $silent );
68 return true;
69 }
70 }
71
72 /**
73 * Get plugin info from WordPress.org.
74 */
75 private function get_plugin_information( $plugin_slug ) {
76 include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
77
78 $api = plugins_api( 'plugin_information', [
79 'slug' => $plugin_slug,
80 'fields' => [
81 'download_link' => true,
82 ],
83 ] );
84
85 return $api;
86 }
87
88 /**
89 * Check if plugin is installed.
90 */
91 private function is_plugin_installed() {
92 global $wp_filesystem;
93 return $wp_filesystem->exists( WP_PLUGIN_DIR . '/' . $this->plugin_file );
94 }
95
96 /**
97 * Init WordPress Filesystem API.
98 */
99 private function initialize_filesystem() {
100 global $wp_filesystem;
101
102 if ( ! function_exists( 'WP_Filesystem' ) ) {
103 require_once ABSPATH . 'wp-admin/includes/file.php';
104 }
105
106 WP_Filesystem();
107 }
108
109 /**
110 * Static method to bulk install/activate multiple plugins.
111 */
112 public static function single_install_and_activate( string $plugin_file ) {
113 $installer = new self( $plugin_file );
114 return $installer->install_and_activate();
115 }
116
117 /**
118 * Static method to bulk install/activate multiple plugins.
119 */
120 public static function bulk_install_and_activate( array $plugin_files ) {
121 foreach ( $plugin_files as $plugin_file ) {
122 $installer = new self( $plugin_file );
123 $installer->install_and_activate();
124 }
125 }
126 }
127