PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 1.3.6
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v1.3.6
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
templately / core / api / class-requirement-installer.php

class-requirement-installer.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 1.3.6, at core/api/class-requirement-installer.php

133 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Templately;
3
4 class RequirementInstaller {
5 /**
6 * Plugin Instance
7 * @var \Templately\RequirementInstaller
8 */
9 private static $_instance = null;
10 /**
11 * Get a single instance of Plugin
12 * @return Plugin
13 */
14 public static function get_instance() {
15 if (is_null(self::$_instance)) {
16 self::$_instance = new self();
17 }
18 return self::$_instance;
19 }
20 /**
21 * Some process take long time to execute
22 * for that need to raise the limit.
23 */
24 public static function raise_limits() {
25 wp_raise_memory_limit( 'admin' );
26 if ( wp_is_ini_value_changeable( 'max_execution_time' ) && function_exists('ini_set') ) {
27 ini_set( 'max_execution_time', 0 );
28 }
29 if( function_exists('set_time_limit') ) {
30 @ set_time_limit( 0 );
31 }
32 }
33
34 public function install_plugin( $plugin_details ) {
35 require_once ABSPATH . 'wp-admin/includes/plugin.php';
36 require_once ABSPATH . 'wp-admin/includes/file.php';
37 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
38 include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
39
40 $all_plugins = get_plugins();
41 $is_installed = isset( $all_plugins[ $plugin_details['plugin_file'] ] );
42
43 if( isset( $plugin_details['is_pro'] ) && $plugin_details['is_pro'] == true ) {
44 if( ! $is_installed ) {
45 $status = [
46 'success' => false,
47 ];
48 $status['errorCode'] = 'pro_plugin';
49 $status['message'] = 'Pro Plugin';
50 Helper::send_error( $status );
51 }
52 }
53
54 if ( $is_installed ) {
55 $activate_status = $this->activate_plugin( $plugin_details['plugin_file'] );
56 } else {
57 $status = [
58 'success' => false,
59 ];
60 $api = plugins_api(
61 'plugin_information',
62 array(
63 'slug' => sanitize_key( wp_unslash( $plugin_details['plugin_original_slug'] ) ),
64 'fields' => array(
65 'sections' => false,
66 ),
67 )
68 );
69
70 if ( is_wp_error( $api ) ) {
71 $status['message'] = $api->get_error_message();
72 return $status;
73 }
74
75 $status['plugin_name'] = $api->name;
76
77 $skin = new \WP_Ajax_Upgrader_Skin();
78 $upgrader = new \Plugin_Upgrader( $skin );
79 $result = $upgrader->install( $api->download_link );
80
81 if ( is_wp_error( $result ) ) {
82 $status['errorCode'] = $result->get_error_code();
83 $status['message'] = $result->get_error_message();
84
85 return $status;
86 } elseif ( is_wp_error( $skin->result ) ) {
87 $status['errorCode'] = $skin->result->get_error_code();
88 $status['message'] = $skin->result->get_error_message();
89
90 return $status;
91 } elseif ( $skin->get_errors()->has_errors() ) {
92 $status['message'] = $skin->get_error_messages();
93
94 return $status;
95 } elseif ( is_null( $result ) ) {
96 global $wp_filesystem;
97
98 $status['errorCode'] = 'unable_to_connect_to_filesystem';
99 $status['message'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
100
101 if ( $wp_filesystem instanceof \WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
102 $status['message'] = esc_html( $wp_filesystem->errors->get_error_message() );
103 }
104
105 return $status;
106 }
107
108 $install_status = install_plugin_install_status( $api );
109 $activate_status = $this->activate_plugin( $install_status['file'] );
110 }
111
112 if ( $activate_status && ! is_wp_error( $activate_status ) ) {
113 $status['success'] = true;
114 }
115 $status['slug'] = $plugin_details['plugin_original_slug'];
116
117 return $status;
118 }
119
120 private function activate_plugin( $file ) {
121 if ( current_user_can( 'activate_plugin', $file ) && is_plugin_inactive( $file ) ) {
122 $result = activate_plugin( $file, false, false );
123 if ( is_wp_error( $result ) ) {
124 return $result;
125 } else {
126 return true;
127 }
128 }
129
130 return false;
131 }
132
133 }