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

Minor refactor changes

parent fba049c3
No related branches found
No related tags found
2 merge requests!8Devel,!6Feature/refactor
Pipeline #7959 failed
...@@ -13,9 +13,9 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable { ...@@ -13,9 +13,9 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable {
const HOOK_ADMIN_NOTICES_ACTION = 'admin_notices'; const HOOK_ADMIN_NOTICES_ACTION = 'admin_notices';
/** @var string */ /** @var string */
private $plugin_name = ''; private $plugin_name;
/** @var string */ /** @var string */
private $plugin_file = ''; private $plugin_file;
/** @var string */ /** @var string */
private $min_php_version; private $min_php_version;
/** @var string */ /** @var string */
...@@ -107,7 +107,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable { ...@@ -107,7 +107,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable {
* @return $this * @return $this
*/ */
public function add_plugin_require( $plugin_name, $nice_plugin_name = null ) { public function add_plugin_require( $plugin_name, $nice_plugin_name = null ) {
if ( is_null( $nice_plugin_name ) ) { if ( $nice_plugin_name === null ) {
$this->plugin_require[ $plugin_name ] = $plugin_name; $this->plugin_require[ $plugin_name ] = $plugin_name;
} else { } else {
$this->plugin_require[ $plugin_name ] = $nice_plugin_name; $this->plugin_require[ $plugin_name ] = $nice_plugin_name;
...@@ -123,7 +123,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable { ...@@ -123,7 +123,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable {
* @return $this * @return $this
*/ */
public function add_php_module_require( $module_name, $nice_name = null ) { public function add_php_module_require( $module_name, $nice_name = null ) {
if ( is_null( $nice_name ) ) { if ( $nice_name === null ) {
$this->module_require[ $module_name ] = $module_name; $this->module_require[ $module_name ] = $module_name;
} else { } else {
$this->module_require[ $module_name ] = $nice_name; $this->module_require[ $module_name ] = $nice_name;
...@@ -158,19 +158,19 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable { ...@@ -158,19 +158,19 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable {
*/ */
private function prepare_requirement_notices() { private function prepare_requirement_notices() {
$notices = array(); $notices = array();
if ( ! $this->is_php_at_least( $this->min_php_version ) ) { if ( ! self::is_php_at_least( $this->min_php_version ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” 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 “%s” 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 ) );
} }
if ( ! $this->is_wp_at_least( $this->min_wp_version ) ) { if ( ! self::is_wp_at_least( $this->min_wp_version ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run on WordPress versions older than %s. Please update WordPress.', $notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” 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 ) ) { if ( $this->min_wc_version !== null && $this->can_check_plugin_version() && ! self::is_wc_at_least( $this->min_wc_version ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run on WooCommerce versions older than %s. Please update WooCommerce.', $notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” 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 ) ); $this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_wc_version ) );
} }
if ( ! is_null( $this->min_openssl_version ) && ! $this->is_open_ssl_at_least( $this->min_openssl_version ) ) { if ( $this->min_openssl_version !== null && ! self::is_open_ssl_at_least( $this->min_openssl_version ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run without OpenSSL module version at least %s. Please update OpenSSL module.', $notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run without OpenSSL module version at least %s. Please update OpenSSL module.',
$this->get_text_domain() ), esc_html( $this->plugin_name ), $this->get_text_domain() ), esc_html( $this->plugin_name ),
'0x' . dechex( $this->min_openssl_version ) ) ); '0x' . dechex( $this->min_openssl_version ) ) );
...@@ -189,7 +189,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable { ...@@ -189,7 +189,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable {
* @return mixed * @return mixed
*/ */
public static function is_php_at_least( $min_version ) { public static function is_php_at_least( $min_version ) {
return version_compare( phpversion(), $min_version, '>=' ); return version_compare( PHP_VERSION, $min_version, '>=' );
} }
/** /**
...@@ -258,7 +258,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable { ...@@ -258,7 +258,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable {
private function append_plugin_require_notices( $notices ) { private function append_plugin_require_notices( $notices ) {
if ( count( $this->plugin_require ) > 0 ) { if ( count( $this->plugin_require ) > 0 ) {
foreach ( $this->plugin_require as $plugin_name => $nice_plugin_name ) { foreach ( $this->plugin_require as $plugin_name => $nice_plugin_name ) {
if ( ! $this->is_wp_plugin_active( $plugin_name ) ) { if ( ! self::is_wp_plugin_active( $plugin_name ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run without %s active. Please install and activate %s plugin.', $notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run without %s active. Please install and activate %s plugin.',
$this->get_text_domain() ), esc_html( $this->plugin_name ), $this->get_text_domain() ), esc_html( $this->plugin_name ),
esc_html( basename( $nice_plugin_name ) ), esc_html( basename( $nice_plugin_name ) ) ) ); esc_html( basename( $nice_plugin_name ) ), esc_html( basename( $nice_plugin_name ) ) ) );
...@@ -294,7 +294,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable { ...@@ -294,7 +294,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable {
private function append_module_require_notices( $notices ) { private function append_module_require_notices( $notices ) {
if ( count( $this->module_require ) > 0 ) { if ( count( $this->module_require ) > 0 ) {
foreach ( $this->module_require as $module_name => $nice_module_name ) { foreach ( $this->module_require as $module_name => $nice_module_name ) {
if ( ! $this->is_module_active( $module_name ) ) { if ( ! self::is_module_active( $module_name ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run without %s php module installed. Please contact your host and ask them to install %s.', $notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run without %s php module installed. Please contact your host and ask them to install %s.',
$this->get_text_domain() ), esc_html( $this->plugin_name ), $this->get_text_domain() ), esc_html( $this->plugin_name ),
esc_html( basename( $nice_module_name ) ), esc_html( basename( $nice_module_name ) ) ) ); esc_html( basename( $nice_module_name ) ), esc_html( basename( $nice_module_name ) ) ) );
...@@ -322,7 +322,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable { ...@@ -322,7 +322,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable {
private function append_settings_require_notices( $notices ) { private function append_settings_require_notices( $notices ) {
if ( count( $this->setting_require ) > 0 ) { if ( count( $this->setting_require ) > 0 ) {
foreach ( $this->setting_require as $setting => $value ) { foreach ( $this->setting_require as $setting => $value ) {
if ( ! $this->is_setting_set( $setting, $value ) ) { if ( ! self::is_setting_set( $setting, $value ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run without %s php setting set to %s. Please contact your host and ask them to set %s.', $notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run without %s php setting set to %s. Please contact your host and ask them to set %s.',
$this->get_text_domain() ), esc_html( $this->plugin_name ), esc_html( basename( $setting ) ), $this->get_text_domain() ), esc_html( $this->plugin_name ), esc_html( basename( $setting ) ),
esc_html( basename( $value ) ), esc_html( basename( $setting ) ) ) ); esc_html( basename( $value ) ), esc_html( basename( $setting ) ) ) );
...@@ -340,7 +340,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable { ...@@ -340,7 +340,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable {
* @return bool * @return bool
*/ */
public static function is_setting_set( $name, $value ) { public static function is_setting_set( $name, $value ) {
return ini_get( $name ) === strval( $value ); return ini_get( $name ) === (string) $value;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment