PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.5.9
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.5.9
1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / src / Integrations / PluginManager.php
hostinger-reach / src / Integrations Last commit date
Brave 5 months ago ContactForm7 4 months ago Elementor 2 months ago Forminator 2 months ago NinjaForms 5 months ago OptInMonster 5 months ago Reach 2 months ago SureForms 5 months ago ThriveLeads 5 months ago WPFormsLite 5 months ago WSForms 8 months ago WooCommerce 4 months ago ContactForm7Integration.php 10 months ago ImportManager.php 5 months ago Integration.php 5 months ago IntegrationInterface.php 9 months ago IntegrationWithForms.php 9 months ago PluginManager.php 9 months ago ReachFormIntegration.php 9 months ago WpFormsLiteIntegration.php 10 months ago
PluginManager.php
97 lines
1 <?php
2
3 namespace Hostinger\Reach\Integrations;
4
5 use Hostinger\Reach\Dto\PluginData;
6 use Plugin_Upgrader;
7 use Plugin_Upgrader_Skin;
8 use WP_Error;
9
10 if ( ! DEFINED( 'ABSPATH' ) ) {
11 die;
12 }
13
14 class PluginManager {
15
16 public static function plugin_data(): array {
17 return apply_filters( 'hostinger_reach_plugin_data', array() );
18 }
19
20 public function install( string $plugin_name ): bool|WP_Error {
21 if ( $this->is_installed( $plugin_name ) ) {
22 return true;
23 }
24
25 require_once ABSPATH . 'wp-admin/includes/file.php';
26 require_once ABSPATH . 'wp-admin/includes/misc.php';
27 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
28 require_once ABSPATH . 'wp-admin/includes/theme.php';
29
30 $plugin = $this->get_plugin( $plugin_name );
31 if ( is_null( $plugin ) ) {
32 return new WP_Error( 'plugin_not_found', 'Plugin not found' );
33 }
34
35 $plugin_data = $plugin->to_array();
36 $temp_file = download_url( $plugin_data['download_url'] );
37
38 if ( is_wp_error( $temp_file ) ) {
39 return $temp_file;
40 }
41
42 $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin() );
43 $result = $upgrader->install( $temp_file );
44
45 wp_delete_file( $temp_file );
46
47 if ( is_wp_error( $result ) ) {
48 return $result;
49 }
50
51 return true;
52 }
53
54 public function activate( string $plugin_name ): bool {
55 if ( ! $this->is_installed( $plugin_name ) ) {
56 return false;
57 }
58
59 if ( $this->is_active( $plugin_name ) ) {
60 return true;
61 }
62
63 return is_null( activate_plugin( $this->get_plugin_path( $plugin_name ) ) );
64 }
65
66 public function is_installed( string $plugin_name ): bool {
67 return file_exists( WP_PLUGIN_DIR . '/' . $this->get_plugin_path( $plugin_name ) );
68 }
69
70 public function is_active( string $plugin_name ): bool {
71 $plugin_path = $this->get_plugin_path( $plugin_name );
72
73 return is_plugin_active( $plugin_path );
74 }
75
76 public function get_plugin_path( string $plugin_name ): string {
77 $plugin = $this->get_plugin( $plugin_name );
78 if ( is_null( $plugin ) ) {
79 return '/';
80 }
81
82 $plugin_data = $plugin->to_array();
83
84 if ( ! isset( $plugin_data['folder'] ) || ! isset( $plugin_data['file'] ) ) {
85 return '/';
86 }
87
88 return $plugin_data['folder'] . '/' . $plugin_data['file'];
89 }
90
91 public function get_plugin( string $plugin_name ): ?PluginData {
92 $plugin_data = self::plugin_data();
93
94 return $plugin_data[ $plugin_name ] ?? null;
95 }
96 }
97