really-simple-ssl
Last commit date
assets
10 months ago
languages
10 months ago
lets-encrypt
10 months ago
lib
10 months ago
mailer
10 months ago
modal
10 months ago
onboarding
10 months ago
placeholders
10 months ago
progress
10 months ago
security
10 months ago
settings
10 months ago
testssl
10 months ago
upgrade
10 months ago
.wp-env.json
10 months ago
class-admin.php
10 months ago
class-cache.php
10 months ago
class-certificate.php
10 months ago
class-front-end.php
10 months ago
class-installer.php
10 months ago
class-mixed-content-fixer.php
10 months ago
class-multisite.php
10 months ago
class-server.php
10 months ago
class-site-health.php
10 months ago
class-wp-cli.php
10 months ago
compatibility.php
10 months ago
force-deactivate.txt
10 months ago
functions.php
10 months ago
index.php
10 months ago
readme.txt
10 months ago
rector.php
10 months ago
rlrsssl-really-simple-ssl.php
10 months ago
rsssl-auto-loader.php
10 months ago
security.md
10 months ago
ssl-test-page.php
10 months ago
system-status.php
10 months ago
uninstall.php
10 months ago
upgrade.php
10 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 ( ! wp_doing_cron() && ! 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 ( ! wp_doing_cron() && ! 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 ( ! wp_doing_cron() && ! 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 |