Skip to content
Snippets Groups Projects
Commit b701e339 authored by dyszczo's avatar dyszczo
Browse files

Merge branch 'devel'

parents 634f2c8e 6d01f41f
No related branches found
No related tags found
1 merge request!3testy jednostkowe + trochę fixów + wsparcie dla openssl
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
} }
], ],
"require": { "require": {
"php": ">=5.5" "php": ">=5.2"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "<7", "phpunit/phpunit": "<7",
......
...@@ -21,6 +21,9 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable { ...@@ -21,6 +21,9 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
/** @var string */ /** @var string */
private $min_wp_version; private $min_wp_version;
/** @var string */
private $min_wc_version;
/** @var array */ /** @var array */
private $plugin_require; private $plugin_require;
...@@ -36,6 +39,8 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable { ...@@ -36,6 +39,8 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
/** @var @string */ /** @var @string */
private $text_domain; private $text_domain;
const EXTENSION_NAME_OPENSSL = 'openssl';
/** /**
* @param string $plugin_file * @param string $plugin_file
* @param string $plugin_name * @param string $plugin_name
...@@ -51,10 +56,10 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable { ...@@ -51,10 +56,10 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
$this->set_min_php_require( $php_version ); $this->set_min_php_require( $php_version );
$this->set_min_wp_require( $wp_version ); $this->set_min_wp_require( $wp_version );
$this->plugin_require = []; $this->plugin_require = array();
$this->module_require = []; $this->module_require = array();
$this->setting_require = []; $this->setting_require = array();
$this->notices = []; $this->notices = array();
} }
public function get_text_domain() { public function get_text_domain() {
...@@ -151,7 +156,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable { ...@@ -151,7 +156,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
* @return array * @return array
*/ */
private function prepare_requirement_notices() { private function prepare_requirement_notices() {
$notices = []; $notices = array();
if ( ! $this->is_php_at_least( $this->min_php_version ) ) { if ( ! $this->is_php_at_least( $this->min_php_version ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The &#8220;%s&#8221; plugin cannot run on PHP versions older than %s. Please contact your host and ask them to upgrade.', $notices[] = $this->prepare_notice_message( sprintf( __( 'The &#8220;%s&#8221; plugin cannot run on PHP versions older than %s. Please contact your host and ask them to upgrade.',
$this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_php_version ) ); $this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_php_version ) );
...@@ -160,6 +165,9 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable { ...@@ -160,6 +165,9 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The &#8220;%s&#8221; plugin cannot run on WordPress versions older than %s. Please update WordPress.', $notices[] = $this->prepare_notice_message( sprintf( __( 'The &#8220;%s&#8221; plugin cannot run on WordPress versions older than %s. Please update WordPress.',
$this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_wp_version ) ); $this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_wp_version ) );
} }
if ( ! is_null( $this->min_wc_version ) && $this->can_check_plugin_version() && ! $this->is_wc_at_least( $this->min_wc_version ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The &#8220;%s&#8221; plugin cannot run on WooCommerce versions older than %s. Please update WooCommerce.', $this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_wc_version ) );
}
$notices = $this->append_plugin_require_notices( $notices ); $notices = $this->append_plugin_require_notices( $notices );
$notices = $this->append_module_require_notices( $notices ); $notices = $this->append_module_require_notices( $notices );
$notices = $this->append_settings_require_notices( $notices ); $notices = $this->append_settings_require_notices( $notices );
...@@ -167,6 +175,27 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable { ...@@ -167,6 +175,27 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
return $notices; return $notices;
} }
/**
* Are plugins loaded so we can check the version
*
* @return bool
*/
private function can_check_plugin_version() {
return did_action('plugins_loaded') > 0;
}
/**
* Checks if plugin is active and have designated version. Needs to be enabled in deferred way.
*
* @param string $min_version
*
* @return bool
*/
public static function is_wc_at_least( $min_version ) {
return defined('WC_VERSION') &&
version_compare( WC_VERSION, $min_version, '>=' );
}
/** /**
* @param array $notices * @param array $notices
* *
...@@ -247,8 +276,8 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable { ...@@ -247,8 +276,8 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
* @return void * @return void
*/ */
public function disable_plugin_render_notice() { public function disable_plugin_render_notice() {
add_action( 'admin_notices', [ $this, 'deactivate_action' ] ); add_action( 'admin_notices', array( $this, 'deactivate_action' ) );
add_action( 'admin_notices', [ $this, 'render_notices_action' ] ); add_action( 'admin_notices', array( $this, 'render_notices_action' ) );
} }
/** /**
...@@ -308,12 +337,25 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable { ...@@ -308,12 +337,25 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
* @return bool * @return bool
*/ */
public static function is_wp_plugin_active( $plugin_file ) { public static function is_wp_plugin_active( $plugin_file ) {
$active_plugins = (array) get_option( 'active_plugins', [] ); $active_plugins = (array) get_option( 'active_plugins', array() );
if ( is_multisite() ) { if ( is_multisite() ) {
$active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', [] ) ); $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
} }
return in_array( $plugin_file, $active_plugins ) || array_key_exists( $plugin_file, $active_plugins ); return in_array( $plugin_file, $active_plugins ) || array_key_exists( $plugin_file, $active_plugins );
} }
/**
* Checks if ssl version is valid
*
* @param int $required_version Version in hex. Version 9.6 is 0x000906000
* @see https://www.openssl.org/docs/man1.1.0/crypto/OPENSSL_VERSION_NUMBER.html
*
* @return bool
*/
public static function is_open_ssl_at_least( $required_version ) {
return defined( 'OPENSSL_VERSION_NUMBER' ) && OPENSSL_VERSION_NUMBER > $required_version;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment