PluginProbe ʕ •ᴥ•ʔ
Really Simple Security – Simple and Performant Security (formerly Really Simple SSL) / 9.4.0
Really Simple Security – Simple and Performant Security (formerly Really Simple SSL) v9.4.0
9.5.11 9.5.10.1 9.5.10 trunk 9.4.0 9.4.1 9.4.2 9.4.3 9.5.0 9.5.0.1 9.5.0.2 9.5.1 9.5.2 9.5.2.2 9.5.2.3 9.5.3 9.5.3.1 9.5.3.2 9.5.4 9.5.5 9.5.6 9.5.7 9.5.8 9.5.9
really-simple-ssl / class-installer.php
really-simple-ssl Last commit date
assets 11 months ago languages 11 months ago lets-encrypt 1 year ago lib 1 year ago mailer 1 year ago modal 11 months ago onboarding 1 year ago placeholders 1 year ago progress 1 year ago security 11 months ago settings 11 months ago testssl 5 years ago upgrade 1 year ago class-admin.php 1 year ago class-cache.php 2 years ago class-certificate.php 2 years ago class-front-end.php 1 year ago class-installer.php 1 year ago class-mixed-content-fixer.php 3 years ago class-multisite.php 1 year ago class-server.php 1 year ago class-site-health.php 1 year ago class-wp-cli.php 11 months ago compatibility.php 1 year ago force-deactivate.txt 1 year ago functions.php 1 year ago index.php 2 years ago readme.txt 11 months ago rector.php 1 year ago rlrsssl-really-simple-ssl.php 11 months ago rsssl-auto-loader.php 1 year ago security.md 2 years ago ssl-test-page.php 2 years ago system-status.php 1 year ago uninstall.php 1 year ago upgrade.php 11 months ago
class-installer.php
181 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5 if ( ! function_exists( 'is_plugin_active' ) ) {
6 include_once ABSPATH . 'wp-admin/includes/plugin.php';
7 }
8 /**
9 * Install suggested plugins
10 */
11
12 if ( ! class_exists( 'rsssl_installer' ) ) {
13 class rsssl_installer {
14 private $slug = '';
15 public function __construct( $slug ) {
16 if ( ! current_user_can( 'install_plugins' ) ) {
17 return;
18 }
19
20 $this->slug = $slug;
21 }
22
23 /**
24 * Check if plugin is downloaded
25 * @return bool
26 */
27
28 public function plugin_is_downloaded() {
29 return file_exists( trailingslashit( WP_PLUGIN_DIR ) . $this->get_activation_slug() );
30 }
31 /**
32 * Check if plugin is activated
33 * @return bool
34 */
35 public function plugin_is_activated() {
36 return is_plugin_active( $this->get_activation_slug() );
37 }
38
39 /**
40 * Install plugin
41 * @param string $step
42 *
43 * @return void
44 */
45 public function install( $step ) {
46 if ( ! current_user_can( 'install_plugins' ) ) {
47 return;
48 }
49
50 if ( 'download' === $step ) {
51 $this->download_plugin();
52 }
53 if ( 'activate' === $step ) {
54 $this->activate_plugin();
55 }
56 }
57
58 /**
59 * Get slug to activate plugin with
60 * @return string
61 */
62 public function get_activation_slug() {
63 $slugs = [
64 'complianz-gdpr' => 'complianz-gdpr/complianz-gpdr.php',
65 'complianz-terms-conditions' => 'complianz-terms-conditions/complianz-terms-conditions.php',
66 'simplybook' => 'simplybook/simplybook.php',
67 ];
68 return $slugs[ $this->slug ];
69 }
70
71 /**
72 * Cancel shepherd tour
73 * @return void
74 */
75 public function cancel_tour() {
76 $prefixes = [
77 'complianz-gdpr' => 'cmplz',
78 'complianz-terms-conditions' => 'cmplz_tc',
79 'simplybook' => 'simplybook',
80 ];
81 $prefix = $prefixes[ $this->slug ];
82 update_site_option( $prefix . '_tour_started', false );
83 update_site_option( $prefix . '_tour_shown_once', true );
84 delete_transient( $prefix . '_redirect_to_settings' );
85 delete_transient( $prefix . '_redirect_to_settings_page' );
86 }
87
88 /**
89 * Download the plugin
90 * @return bool
91 */
92 public function download_plugin() {
93 if ( ! current_user_can( 'install_plugins' ) ) {
94 return false;
95 }
96
97 if ( get_transient( 'rsssl_plugin_download_active' ) !== $this->slug ) {
98 set_transient( 'rsssl_plugin_download_active', $this->slug, MINUTE_IN_SECONDS );
99 $info = $this->get_plugin_info();
100
101 $download_link = esc_url_raw( $info->versions['trunk'] );
102
103 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
104 require_once ABSPATH . 'wp-admin/includes/file.php';
105 include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
106
107 if ( ! is_writable( WP_PLUGIN_DIR ) ) {
108 return false;
109 }
110
111 $skin = new WP_Ajax_Upgrader_Skin();
112 $upgrader = new Plugin_Upgrader( $skin );
113
114 $result = $upgrader->install( $download_link );
115
116 if ( is_wp_error( $result ) ) {
117 return false;
118 }
119
120 delete_transient( 'rsssl_plugin_download_active' );
121 }
122
123 return true;
124 }
125
126 /**
127 * Activate the plugin
128 *
129 * @return bool
130 */
131 public function activate_plugin() {
132 if ( ! current_user_can( 'install_plugins' ) ) {
133 return false;
134 }
135
136 $slug = $this->get_activation_slug();
137 $plugin_file_path = trailingslashit( WP_PLUGIN_DIR ) . $slug;
138
139 // Make sure the plugin file exists before trying to activate it
140 if ( ! file_exists( $plugin_file_path ) ) {
141 return false;
142 }
143
144 // Use plugin_basename to generate the correct slug, considering the WP_PLUGIN_DIR
145 $plugin_slug = plugin_basename( $plugin_file_path );
146
147 $networkwide = is_multisite() && rsssl_is_networkwide_active();
148
149 if ( ! defined( 'DOING_CRON' ) ) {
150 define( 'DOING_CRON', true );//phpcs:ignore
151 }
152
153 $result = activate_plugin( $plugin_slug, '', $networkwide );
154 if ( is_wp_error( $result ) ) {
155 return false;
156 }
157
158 $this->cancel_tour();
159 return true;
160 }
161
162
163 /**
164 * Get plugin info
165 * @return array|WP_Error
166 */
167 public function get_plugin_info() {
168 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
169 $plugin_info = get_transient( 'rsssl_' . $this->slug . '_plugin_info' );
170 if ( empty( $plugin_info ) ) {
171 $plugin_info = plugins_api( 'plugin_information', array( 'slug' => $this->slug ) );
172 if ( ! is_wp_error( $plugin_info ) ) {
173 set_transient( 'rsssl_' . $this->slug . '_plugin_info', $plugin_info, WEEK_IN_SECONDS );
174 }
175 }
176 return $plugin_info;
177 }
178 }
179
180 }
181