activation
5 months ago
assets-managment
5 months ago
components
5 months ago
entities
5 months ago
premium
5 months ago
updates
5 months ago
class-check-compatibility.php
6 months ago
class-factory-migrations.php
5 months ago
class-factory-notices.php
5 months ago
class-factory-options.php
4 months ago
class-factory-plugin-abstract.php
5 months ago
class-factory-plugin-base.php
5 months ago
class-factory-requests.php
5 months ago
class-factory-requirements.php
5 months ago
functions.php
5 months ago
index.php
6 months ago
class-factory-requirements.php
297 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class to check if the current WordPress and PHP versions meet our requirements |
| 5 | * |
| 6 | * @version 2.0.0 |
| 7 | * @since 4.0.9 |
| 8 | */ |
| 9 | // @formatter:off |
| 10 | if ( ! class_exists( 'Wbcr_Factory600_Requirements' ) ) { |
| 11 | class Wbcr_Factory600_Requirements { |
| 12 | |
| 13 | /** |
| 14 | * Factory framework version |
| 15 | * |
| 16 | * @var string |
| 17 | */ |
| 18 | protected $factory_version; |
| 19 | |
| 20 | /** |
| 21 | * @var string |
| 22 | */ |
| 23 | protected $plugin_version; |
| 24 | |
| 25 | /** |
| 26 | * Plugin file path |
| 27 | * |
| 28 | * @var string |
| 29 | */ |
| 30 | protected $plugin_file; |
| 31 | |
| 32 | /** |
| 33 | * Plugin dir |
| 34 | * |
| 35 | * @var string |
| 36 | */ |
| 37 | protected $plugin_abs_path; |
| 38 | |
| 39 | /** |
| 40 | * Plugin base dir |
| 41 | * |
| 42 | * @var string |
| 43 | */ |
| 44 | protected $plugin_basename; |
| 45 | |
| 46 | /** |
| 47 | * Plugin url |
| 48 | * |
| 49 | * @var string |
| 50 | */ |
| 51 | protected $plugin_url; |
| 52 | |
| 53 | /** |
| 54 | * Plugin prefix |
| 55 | * |
| 56 | * @var string |
| 57 | */ |
| 58 | protected $plugin_prefix; |
| 59 | |
| 60 | /** |
| 61 | * Plugin name |
| 62 | * |
| 63 | * @var string |
| 64 | */ |
| 65 | protected $plugin_name; |
| 66 | |
| 67 | /** |
| 68 | * Plugin title |
| 69 | * |
| 70 | * @var string |
| 71 | */ |
| 72 | protected $plugin_title = '(no title)'; |
| 73 | |
| 74 | /** |
| 75 | * @var string |
| 76 | */ |
| 77 | protected $plugin_text_domain; |
| 78 | |
| 79 | /** |
| 80 | * Required PHP version |
| 81 | * |
| 82 | * @var string |
| 83 | */ |
| 84 | protected $required_php_version = '5.3'; |
| 85 | |
| 86 | /** |
| 87 | * Required WordPress version |
| 88 | * |
| 89 | * @var string |
| 90 | */ |
| 91 | protected $required_wp_version = '4.2.0'; |
| 92 | |
| 93 | /** |
| 94 | * Is this plugin already activated? |
| 95 | * |
| 96 | * @var bool |
| 97 | */ |
| 98 | protected $plugin_already_activate = false; |
| 99 | |
| 100 | /** |
| 101 | * WFF_Requirements constructor. |
| 102 | * |
| 103 | * @param string $plugin_file |
| 104 | * @param array $plugin_info |
| 105 | */ |
| 106 | public function __construct( $plugin_file, array $plugin_info ) { |
| 107 | |
| 108 | foreach ( (array) $plugin_info as $property => $value ) { |
| 109 | if ( property_exists( $this, $property ) ) { |
| 110 | $this->$property = $value; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | $this->plugin_file = $plugin_file; |
| 115 | $this->plugin_abs_path = dirname( $plugin_file ); |
| 116 | $this->plugin_basename = plugin_basename( $plugin_file ); |
| 117 | $this->plugin_url = plugins_url( '', $plugin_file ); |
| 118 | |
| 119 | $plugin_info = get_file_data( |
| 120 | $this->plugin_file, |
| 121 | [ |
| 122 | 'Version' => 'Version', |
| 123 | 'FrameworkVersion' => 'Framework Version', |
| 124 | 'TextDomain' => 'Text Domain', |
| 125 | ], |
| 126 | 'plugin' |
| 127 | ); |
| 128 | |
| 129 | if ( isset( $plugin_info['FrameworkVersion'] ) ) { |
| 130 | $this->factory_version = $plugin_info['FrameworkVersion']; |
| 131 | } |
| 132 | |
| 133 | if ( isset( $plugin_info['Version'] ) ) { |
| 134 | $this->plugin_version = $plugin_info['Version']; |
| 135 | } |
| 136 | |
| 137 | if ( isset( $plugin_info['TextDomain'] ) ) { |
| 138 | $this->plugin_text_domain = $plugin_info['TextDomain']; |
| 139 | } |
| 140 | |
| 141 | add_action( 'admin_init', [ $this, 'register_notices' ] ); |
| 142 | } |
| 143 | |
| 144 | public function get_plugin_version() { |
| 145 | return $this->plugin_version; |
| 146 | } |
| 147 | |
| 148 | public function get_text_domain() { |
| 149 | return $this->plugin_text_domain; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * @since 4.1.1 |
| 154 | * @return void |
| 155 | */ |
| 156 | public function register_notices() { |
| 157 | if ( current_user_can( 'activate_plugins' ) && current_user_can( 'edit_plugins' ) && current_user_can( 'install_plugins' ) ) { |
| 158 | |
| 159 | if ( is_multisite() ) { |
| 160 | add_action( 'network_admin_notices', [ $this, 'show_notice' ] ); |
| 161 | |
| 162 | if ( ! empty( $this->plugin_basename ) && in_array( $this->plugin_basename, (array) get_option( 'active_plugins', [] ) ) ) { |
| 163 | add_action( 'admin_notices', [ $this, 'show_notice' ] ); |
| 164 | } |
| 165 | } else { |
| 166 | add_action( 'admin_notices', [ $this, 'show_notice' ] ); |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Shows the incompatibility notification. |
| 173 | * |
| 174 | * @since 4.1.1 |
| 175 | * @return void |
| 176 | */ |
| 177 | public function show_notice() { |
| 178 | if ( $this->check() ) { |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | echo '<div class="notice notice-error"><p>' . wp_kses( $this->get_notice_text(), 'default' ) . '</p></div>'; |
| 183 | } |
| 184 | |
| 185 | |
| 186 | /** |
| 187 | * The method checks the compatibility of the plugin with php and WordPress version. |
| 188 | * |
| 189 | * @since 4.1.1 |
| 190 | * @return bool |
| 191 | */ |
| 192 | public function check() { |
| 193 | |
| 194 | // Fix for ithemes sync. When the ithemes sync plugin accepts the request, set the WP_ADMIN constant, |
| 195 | // Solution to simply terminate the plugin if there is a request from ithemes sync |
| 196 | // -------------------------------------- |
| 197 | if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'ithemes_sync_request' ) { |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | if ( isset( $_GET['ithemes-sync-request'] ) && ! empty( $_GET['ithemes-sync-request'] ) ) { |
| 202 | return false; |
| 203 | } |
| 204 | // ---------------------------------------- |
| 205 | |
| 206 | if ( ! $this->check_php_compat() || ! $this->check_wp_compat() || $this->plugin_already_activate ) { |
| 207 | return false; |
| 208 | } |
| 209 | |
| 210 | return true; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * The method checks the compatibility of the plugin with the php version of the server. |
| 215 | * |
| 216 | * @return mixed |
| 217 | */ |
| 218 | public function check_php_compat() { |
| 219 | return version_compare( PHP_VERSION, $this->required_php_version, '>=' ); |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * The method checks the compatibility of the plugin with the WordPress version of the site. |
| 224 | * |
| 225 | * @return mixed |
| 226 | */ |
| 227 | public function check_wp_compat() { |
| 228 | // Get the WP Version global. |
| 229 | global $wp_version; |
| 230 | |
| 231 | return version_compare( $wp_version, $this->required_wp_version, '>=' ); |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Method returns notification text |
| 236 | * |
| 237 | * @return string |
| 238 | */ |
| 239 | protected function get_notice_text() { |
| 240 | $notice_text = $notice_default_text = ''; |
| 241 | $notice_default_text .= '<b>' . $this->plugin_title . ' ' . __( 'warning', 'robin-image-optimizer' ) . ':</b>' . '<br>'; |
| 242 | |
| 243 | // translators: %s is the plugin title |
| 244 | $notice_default_text .= sprintf( __( 'The %s plugin has stopped.', 'robin-image-optimizer' ), $this->plugin_title ) . ' '; |
| 245 | $notice_default_text .= __( 'Possible reasons:', 'robin-image-optimizer' ) . ' <br>'; |
| 246 | |
| 247 | $has_one = false; |
| 248 | |
| 249 | if ( ! $this->check_php_compat() ) { |
| 250 | $has_one = true; |
| 251 | $notice_text .= '- ' . $this->get_php_incompat_text() . '<br>'; |
| 252 | } |
| 253 | |
| 254 | if ( ! $this->check_wp_compat() ) { |
| 255 | $has_one = true; |
| 256 | $notice_text .= '- ' . $this->get_wp_incompat_text() . '<br>'; |
| 257 | } |
| 258 | |
| 259 | if ( $this->plugin_already_activate ) { |
| 260 | $has_one = true; |
| 261 | $notice_text = '- ' . $this->get_plugin_already_activate_text() . '<br>'; |
| 262 | } |
| 263 | |
| 264 | if ( $has_one ) { |
| 265 | $notice_text = $notice_default_text . $notice_text; |
| 266 | } |
| 267 | |
| 268 | return $notice_text; |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * @return string |
| 273 | */ |
| 274 | protected function get_php_incompat_text() { |
| 275 | // translators: %s is the required php version |
| 276 | return sprintf( __( 'You need to update the PHP version to %s or higher!', 'robin-image-optimizer' ), $this->required_php_version ); |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * @return string |
| 281 | */ |
| 282 | protected function get_wp_incompat_text() { |
| 283 | // translators: %s is the required WordPress version |
| 284 | return sprintf( __( 'You need to update WordPress to %s or higher!', 'robin-image-optimizer' ), $this->required_wp_version ); |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * @return string |
| 289 | */ |
| 290 | protected function get_plugin_already_activate_text() { |
| 291 | // translators: %s is the plugin title |
| 292 | return sprintf( __( 'Plugin %s is already activated, you are trying to activate it again.', 'robin-image-optimizer' ), $this->plugin_title ); |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | // @formatter:on |
| 297 |