diff --git a/CHANGELOG.md b/CHANGELOG.md index b2f92a2c20517f394b7eaaa6f2aa1a62748c41d5..e717803baa4c0ed815de6e92b5ca6abd339795e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ -## [3.3.0] - 2022-04-21 +## [3.2.8] - 2022-04-22 ### Added -- classmap autoload +- __DIR__ for requires ## [3.2.7] - 2021-03-01 ### Fixed diff --git a/composer.json b/composer.json index 1c4d14314ac2e4fb5f072dbb81dbea9ee4017595..5ab9f3e522a1d5ae48397fad0eb441849ae712d3 100644 --- a/composer.json +++ b/composer.json @@ -19,10 +19,10 @@ "wimg/php-compatibility": "^8" }, "autoload": { - "classmap": ["src"] + }, "autoload-dev": { - "classmap": ["tests"] + "classmap": ["src", "tests"] }, "extra": { "text-domain": "wp-basic-requirements", diff --git a/src/Basic_Requirement_Checker.php b/src/Basic_Requirement_Checker.php index e2aeca02434cbe5cea87af3c8a1976eb2c66aa31..797516627b07717411a1b42499a12816ada15539 100644 --- a/src/Basic_Requirement_Checker.php +++ b/src/Basic_Requirement_Checker.php @@ -1,623 +1,633 @@ <?php -class WPDesk_Basic_Requirement_Checker implements WPDesk_Requirement_Checker { - const EXTENSION_NAME_OPENSSL = 'openssl'; - const HOOK_ADMIN_NOTICES_ACTION = 'admin_notices'; - const HOOK_PLUGIN_DEACTIVATED_ACTION = 'deactivated_plugin'; - const HOOK_PLUGIN_ACTIVATED_ACTION = 'activated_plugin'; - - const PLUGIN_INFO_KEY_NICE_NAME = 'nice_name'; - const PLUGIN_INFO_KEY_NAME = 'name'; - const PLUGIN_INFO_VERSION = 'version'; - const PLUGIN_INFO_FAKE_REQUIRED_MINIMUM_VERSION = '0.0'; - const PLUGIN_INFO_APPEND_PLUGIN_DATA = 'required_version'; - const PLUGIN_INFO_TRANSIENT_NAME = 'require_plugins_data'; - const PLUGIN_INFO_TRANSIENT_EXPIRATION_TIME = 16; - - /** @var string */ - protected $plugin_name; - /** @var string */ - private $plugin_file; - /** @var string */ - private $min_php_version; - /** @var string */ - private $min_wp_version; - /** @var string|null */ - private $min_wc_version = null; - /** @var int|null */ - private $min_openssl_version = null; - /** @var array */ - protected $plugin_require; - /** @var bool */ - protected $should_check_plugin_versions = false; - /** @var array */ - private $module_require; - /** @var array */ - private $setting_require; - /** @var array */ - protected $notices; - /** @var @string */ - private $text_domain; +if ( ! interface_exists( 'WPDesk_Requirement_Checker' ) ) { + require_once __DIR__ . '/Requirement_Checker.php'; +} - /** - * @param string $plugin_file - * @param string $plugin_name - * @param string $text_domain - * @param string $php_version - * @param string $wp_version - */ - public function __construct( $plugin_file, $plugin_name, $text_domain, $php_version, $wp_version ) { - $this->plugin_file = $plugin_file; - $this->plugin_name = $plugin_name; - $this->text_domain = $text_domain; - - $this->set_min_php_require( $php_version ); - $this->set_min_wp_require( $wp_version ); - - $this->plugin_require = array(); - $this->module_require = array(); - $this->setting_require = array(); - $this->notices = array(); - } +if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { + /** + * Checks requirements for plugin + * have to be compatible with PHP 5.3.x + */ + class WPDesk_Basic_Requirement_Checker implements WPDesk_Requirement_Checker { + const EXTENSION_NAME_OPENSSL = 'openssl'; + const HOOK_ADMIN_NOTICES_ACTION = 'admin_notices'; + const HOOK_PLUGIN_DEACTIVATED_ACTION = 'deactivated_plugin'; + const HOOK_PLUGIN_ACTIVATED_ACTION = 'activated_plugin'; + + const PLUGIN_INFO_KEY_NICE_NAME = 'nice_name'; + const PLUGIN_INFO_KEY_NAME = 'name'; + const PLUGIN_INFO_VERSION = 'version'; + const PLUGIN_INFO_FAKE_REQUIRED_MINIMUM_VERSION = '0.0'; + const PLUGIN_INFO_APPEND_PLUGIN_DATA = 'required_version'; + const PLUGIN_INFO_TRANSIENT_NAME = 'require_plugins_data'; + const PLUGIN_INFO_TRANSIENT_EXPIRATION_TIME = 16; + + /** @var string */ + protected $plugin_name; + /** @var string */ + private $plugin_file; + /** @var string */ + private $min_php_version; + /** @var string */ + private $min_wp_version; + /** @var string|null */ + private $min_wc_version = null; + /** @var int|null */ + private $min_openssl_version = null; + /** @var array */ + protected $plugin_require; + /** @var bool */ + protected $should_check_plugin_versions = false; + /** @var array */ + private $module_require; + /** @var array */ + private $setting_require; + /** @var array */ + protected $notices; + /** @var @string */ + private $text_domain; + + /** + * @param string $plugin_file + * @param string $plugin_name + * @param string $text_domain + * @param string $php_version + * @param string $wp_version + */ + public function __construct( $plugin_file, $plugin_name, $text_domain, $php_version, $wp_version ) { + $this->plugin_file = $plugin_file; + $this->plugin_name = $plugin_name; + $this->text_domain = $text_domain; + + $this->set_min_php_require( $php_version ); + $this->set_min_wp_require( $wp_version ); + + $this->plugin_require = array(); + $this->module_require = array(); + $this->setting_require = array(); + $this->notices = array(); + } - /** - * @param string $version - * - * @return $this - */ - public function set_min_php_require( $version ) { - $this->min_php_version = $version; + /** + * @param string $version + * + * @return $this + */ + public function set_min_php_require( $version ) { + $this->min_php_version = $version; - return $this; - } + return $this; + } - /** - * @param string $version - * - * @return $this - */ - public function set_min_wp_require( $version ) { - $this->min_wp_version = $version; + /** + * @param string $version + * + * @return $this + */ + public function set_min_wp_require( $version ) { + $this->min_wp_version = $version; - return $this; - } - - /** - * @param string $version - * - * @return $this - */ - public function set_min_wc_require( $version ) { - $this->min_wc_version = $version; + return $this; + } - return $this; - } + /** + * @param string $version + * + * @return $this + */ + public function set_min_wc_require( $version ) { + $this->min_wc_version = $version; - /** - * @param $version - * - * @return $this - */ - public function set_min_openssl_require( $version ) { - $this->min_openssl_version = $version; + return $this; + } - return $this; - } + /** + * @param $version + * + * @return $this + */ + public function set_min_openssl_require( $version ) { + $this->min_openssl_version = $version; - /** - * @param string $plugin_name Name in wp format dir/file.php - * @param string $nice_plugin_name Nice plugin name for better looks in notice - * @param string $plugin_require_version required plugin minimum version - * - * @return $this - */ - public function add_plugin_require( $plugin_name, $nice_plugin_name = null, $plugin_require_version = null ) { - if ( $plugin_require_version ) { - $this->should_check_plugin_versions = true; - } - $this->plugin_require[ $plugin_name ] = array( - self::PLUGIN_INFO_KEY_NAME => $plugin_name, - self::PLUGIN_INFO_KEY_NICE_NAME => $nice_plugin_name === null ? $plugin_name : $nice_plugin_name, - self::PLUGIN_INFO_VERSION => $plugin_require_version === null ? - self::PLUGIN_INFO_FAKE_REQUIRED_MINIMUM_VERSION : $plugin_require_version, - ); - - return $this; - } + return $this; + } - /** - * Add plugin to require list. Plugin is from repository so we can ask for installation. - * - * @param string $plugin_name Name in wp format dir/file.php - * @param string $version Required version of the plugin. - * @param string $nice_plugin_name Nice plugin name for better looks in notice - * - * @return $this - */ - public function add_plugin_repository_require( $plugin_name, $version, $nice_plugin_name = null ) { - $this->plugin_require[ $plugin_name ] = array( - self::PLUGIN_INFO_KEY_NAME => $plugin_name, - self::PLUGIN_INFO_VERSION => $version, - 'repository_url' => 'http://downloads.wordpress.org/plugin/' . dirname( $plugin_name ) . '.latest-stable.zip', - self::PLUGIN_INFO_KEY_NICE_NAME => $nice_plugin_name === null ? $plugin_name : $nice_plugin_name - ); - - return $this; - } + /** + * @param string $plugin_name Name in wp format dir/file.php + * @param string $nice_plugin_name Nice plugin name for better looks in notice + * @param string $plugin_require_version required plugin minimum version + * + * @return $this + */ + public function add_plugin_require( $plugin_name, $nice_plugin_name = null, $plugin_require_version = null ) { + if ( $plugin_require_version ) { + $this->should_check_plugin_versions = true; + } + $this->plugin_require[ $plugin_name ] = array( + self::PLUGIN_INFO_KEY_NAME => $plugin_name, + self::PLUGIN_INFO_KEY_NICE_NAME => $nice_plugin_name === null ? $plugin_name : $nice_plugin_name, + self::PLUGIN_INFO_VERSION => $plugin_require_version === null ? + self::PLUGIN_INFO_FAKE_REQUIRED_MINIMUM_VERSION : $plugin_require_version, + ); + + return $this; + } - /** - * @param string $module_name - * @param string $nice_name Nice module name for better looks in notice - * - * @return $this - */ - public function add_php_module_require( $module_name, $nice_name = null ) { - if ( $nice_name === null ) { - $this->module_require[ $module_name ] = $module_name; - } else { - $this->module_require[ $module_name ] = $nice_name; + /** + * Add plugin to require list. Plugin is from repository so we can ask for installation. + * + * @param string $plugin_name Name in wp format dir/file.php + * @param string $version Required version of the plugin. + * @param string $nice_plugin_name Nice plugin name for better looks in notice + * + * @return $this + */ + public function add_plugin_repository_require( $plugin_name, $version, $nice_plugin_name = null ) { + $this->plugin_require[ $plugin_name ] = array( + self::PLUGIN_INFO_KEY_NAME => $plugin_name, + self::PLUGIN_INFO_VERSION => $version, + 'repository_url' => 'http://downloads.wordpress.org/plugin/' . dirname( $plugin_name ) . '.latest-stable.zip', + self::PLUGIN_INFO_KEY_NICE_NAME => $nice_plugin_name === null ? $plugin_name : $nice_plugin_name + ); + + return $this; } - return $this; - } + /** + * @param string $module_name + * @param string $nice_name Nice module name for better looks in notice + * + * @return $this + */ + public function add_php_module_require( $module_name, $nice_name = null ) { + if ( $nice_name === null ) { + $this->module_require[ $module_name ] = $module_name; + } else { + $this->module_require[ $module_name ] = $nice_name; + } - /** - * @param string $setting - * @param mixed $value - * - * @return $this - */ - public function add_php_setting_require( $setting, $value ) { - $this->setting_require[ $setting ] = $value; + return $this; + } - return $this; - } + /** + * @param string $setting + * @param mixed $value + * + * @return $this + */ + public function add_php_setting_require( $setting, $value ) { + $this->setting_require[ $setting ] = $value; - /** - * Returns true if are requirements are met. - * - * @return bool - */ - public function are_requirements_met() { - $this->notices = $this->prepare_requirement_notices(); + return $this; + } - return count( $this->notices ) === 0; - } + /** + * Returns true if are requirements are met. + * + * @return bool + */ + public function are_requirements_met() { + $this->notices = $this->prepare_requirement_notices(); - /** - * @return array - */ - private function prepare_requirement_notices() { - $notices = array(); - 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.', - $this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_php_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.', - $this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_wp_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.', - $this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_wc_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.', - $this->get_text_domain() ), esc_html( $this->plugin_name ), - '0x' . dechex( $this->min_openssl_version ) ) ); + return count( $this->notices ) === 0; } - $notices = $this->append_plugin_require_notices( $notices ); - $notices = $this->append_module_require_notices( $notices ); - $notices = $this->append_settings_require_notices( $notices ); - if ( $this->should_check_plugin_versions ) { - $notices = $this->check_minimum_require_plugins_version_and_append_notices( $notices ); - } + /** + * @return array + */ + private function prepare_requirement_notices() { + $notices = array(); + 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.', + $this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_php_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.', + $this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_wp_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.', + $this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_wc_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.', + $this->get_text_domain() ), esc_html( $this->plugin_name ), + '0x' . dechex( $this->min_openssl_version ) ) ); + } - return $notices; - } + $notices = $this->append_plugin_require_notices( $notices ); + $notices = $this->append_module_require_notices( $notices ); + $notices = $this->append_settings_require_notices( $notices ); + if ( $this->should_check_plugin_versions ) { + $notices = $this->check_minimum_require_plugins_version_and_append_notices( $notices ); + } - /** - * @param $min_version - * - * @return mixed - */ - public static function is_php_at_least( $min_version ) { - return version_compare( PHP_VERSION, $min_version, '>=' ); - } + return $notices; + } - /** - * Prepares message in html format - * - * @param string $message - * - * @return string - */ - protected function prepare_notice_message( $message ) { - return '<div class="error"><p>' . $message . '</p></div>'; - } + /** + * @param $min_version + * + * @return mixed + */ + public static function is_php_at_least( $min_version ) { + return version_compare( PHP_VERSION, $min_version, '>=' ); + } - public function get_text_domain() { - return $this->text_domain; - } + /** + * Prepares message in html format + * + * @param string $message + * + * @return string + */ + protected function prepare_notice_message( $message ) { + return '<div class="error"><p>' . $message . '</p></div>'; + } - /** - * @param string $min_version - * - * @return bool - */ - public static function is_wp_at_least( $min_version ) { - return version_compare( get_bloginfo( 'version' ), $min_version, '>=' ); - } + public function get_text_domain() { + return $this->text_domain; + } - /** - * Are plugins loaded so we can check the version - * - * @return bool - */ - private function can_check_plugin_version() { - return did_action( 'plugins_loaded' ) > 0; - } + /** + * @param string $min_version + * + * @return bool + */ + public static function is_wp_at_least( $min_version ) { + return version_compare( get_bloginfo( 'version' ), $min_version, '>=' ); + } - /** - * 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, '>=' ); - } + /** + * 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 ssl version is valid - * - * @param int $required_version Version in hex. Version 9.6 is 0x000906000 - * - * @return bool - * @see https://www.openssl.org/docs/man1.1.0/crypto/OPENSSL_VERSION_NUMBER.html - * - */ - public static function is_open_ssl_at_least( $required_version ) { - return defined( 'OPENSSL_VERSION_NUMBER' ) && OPENSSL_VERSION_NUMBER > (int) $required_version; - } + /** + * 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 $notices array - * - * @return array - */ - private function check_minimum_require_plugins_version_and_append_notices( $notices ) { - $required_plugins = $this->retrieve_required_plugins_data(); - if ( count( $required_plugins ) > 0 ) { - foreach ( $required_plugins as $plugin ) { - if ( version_compare( $plugin['Version'], $plugin[ self::PLUGIN_INFO_APPEND_PLUGIN_DATA ], '<' ) ) { - $notices[] = $this->prepare_notice_message( - sprintf( - __( 'The “%1$s” plugin requires at least %2$s version of %3$s to work correctly. Please update it to its latest release.', $this->get_text_domain() ), - esc_html( $this->plugin_name ), - $plugin[ self::PLUGIN_INFO_APPEND_PLUGIN_DATA ], - $plugin['Name'] - ) - ); + /** + * Checks if ssl version is valid + * + * @param int $required_version Version in hex. Version 9.6 is 0x000906000 + * + * @return bool + * @see https://www.openssl.org/docs/man1.1.0/crypto/OPENSSL_VERSION_NUMBER.html + * + */ + public static function is_open_ssl_at_least( $required_version ) { + return defined( 'OPENSSL_VERSION_NUMBER' ) && OPENSSL_VERSION_NUMBER > (int) $required_version; + } + + /** + * @param $notices array + * + * @return array + */ + private function check_minimum_require_plugins_version_and_append_notices( $notices ) { + $required_plugins = $this->retrieve_required_plugins_data(); + if ( count( $required_plugins ) > 0 ) { + foreach ( $required_plugins as $plugin ) { + if ( version_compare( $plugin['Version'], $plugin[ self::PLUGIN_INFO_APPEND_PLUGIN_DATA ], '<' ) ) { + $notices[] = $this->prepare_notice_message( + sprintf( + __( 'The “%1$s” plugin requires at least %2$s version of %3$s to work correctly. Please update it to its latest release.', $this->get_text_domain() ), + esc_html( $this->plugin_name ), + $plugin[ self::PLUGIN_INFO_APPEND_PLUGIN_DATA ], + $plugin['Name'] + ) + ); + } } } - } - return $notices; - } + return $notices; + } - /** - * Check the plugins directory and retrieve all plugin files with plugin data. - * - * @return array In format [ 'plugindir/pluginfile.php' => ['Name' => 'Plugin Name', 'Version' => '1.0.1', ...], ] - */ - private static function retrieve_plugins_data_in_transient() { - static $never_executed = true; - if ( $never_executed ) { - $never_executed = false; - /** Required when WC starts later and these data should be in cache */ - add_filter( 'extra_plugin_headers', function ( $headers = array() ) { - $headers[] = 'WC tested up to'; - $headers[] = 'WC requires at least'; - $headers[] = 'Woo'; + /** + * Check the plugins directory and retrieve all plugin files with plugin data. + * + * @return array In format [ 'plugindir/pluginfile.php' => ['Name' => 'Plugin Name', 'Version' => '1.0.1', ...], ] + */ + private static function retrieve_plugins_data_in_transient() { + static $never_executed = true; + if ( $never_executed ) { + $never_executed = false; + /** Required when WC starts later and these data should be in cache */ + add_filter( 'extra_plugin_headers', function ( $headers = array() ) { + $headers[] = 'WC tested up to'; + $headers[] = 'WC requires at least'; + $headers[] = 'Woo'; + + return array_unique( $headers ); + } ); + } - return array_unique( $headers ); - } ); - } + $plugins = get_transient( self::PLUGIN_INFO_TRANSIENT_NAME ); - $plugins = get_transient( self::PLUGIN_INFO_TRANSIENT_NAME ); + if ( $plugins === false ) { + if ( ! function_exists( 'get_plugins' ) ) { + require_once ABSPATH . '/wp-admin/includes/plugin.php'; + } - if ( $plugins === false ) { - if ( ! function_exists( 'get_plugins' ) ) { - require_once ABSPATH . '/wp-admin/includes/plugin.php'; + $plugins = function_exists( 'get_plugins' ) ? get_plugins() : array(); + set_transient( self::PLUGIN_INFO_TRANSIENT_NAME, $plugins, + self::PLUGIN_INFO_TRANSIENT_EXPIRATION_TIME ); } - $plugins = function_exists( 'get_plugins' ) ? get_plugins() : array(); - set_transient( self::PLUGIN_INFO_TRANSIENT_NAME, $plugins, - self::PLUGIN_INFO_TRANSIENT_EXPIRATION_TIME ); + return $plugins; } - return $plugins; - } - - /** - * Check the plugins directory and retrieve all required plugin files with plugin data. - * - * @return array In format [ 'plugindir/pluginfile.php' => ['Name' => 'Plugin Name', 'Version' => '1.0.1', 'required_version' => '1.0.2']... ] - */ - private function retrieve_required_plugins_data() { - - $require_plugins = array(); - $plugins = self::retrieve_plugins_data_in_transient(); - if ( is_array( $plugins ) ) { - if ( count( $plugins ) > 0 ) { - if ( ! empty( $this->plugin_require ) ) { - foreach ( $this->plugin_require as $plugin ) { - $plugin_file_name = $plugin[ self::PLUGIN_INFO_KEY_NAME ]; - $plugin_version = $plugin[ self::PLUGIN_INFO_VERSION ]; - - if ( self::is_wp_plugin_active( $plugin_file_name ) ) { - $require_plugins[ $plugin_file_name ] = $plugins[ $plugin_file_name ]; - $require_plugins[ $plugin_file_name ][ self::PLUGIN_INFO_APPEND_PLUGIN_DATA ] = $plugin_version; + /** + * Check the plugins directory and retrieve all required plugin files with plugin data. + * + * @return array In format [ 'plugindir/pluginfile.php' => ['Name' => 'Plugin Name', 'Version' => '1.0.1', 'required_version' => '1.0.2']... ] + */ + private function retrieve_required_plugins_data() { + + $require_plugins = array(); + $plugins = self::retrieve_plugins_data_in_transient(); + if ( is_array( $plugins ) ) { + if ( count( $plugins ) > 0 ) { + if ( ! empty( $this->plugin_require ) ) { + foreach ( $this->plugin_require as $plugin ) { + $plugin_file_name = $plugin[ self::PLUGIN_INFO_KEY_NAME ]; + $plugin_version = $plugin[ self::PLUGIN_INFO_VERSION ]; + + if ( self::is_wp_plugin_active( $plugin_file_name ) ) { + $require_plugins[ $plugin_file_name ] = $plugins[ $plugin_file_name ]; + $require_plugins[ $plugin_file_name ][ self::PLUGIN_INFO_APPEND_PLUGIN_DATA ] = $plugin_version; + } } } } } - } - return $require_plugins; - } + return $require_plugins; + } - /** - * @param array $notices - * - * @return array - */ - private function append_plugin_require_notices( $notices ) { - if ( count( $this->plugin_require ) > 0 ) { - foreach ( $this->plugin_require as $plugin_name => $plugin_info ) { - $notice = null; - if ( isset( $plugin_info['repository_url'] ) ) { - $notice = $this->prepare_plugin_repository_require_notice( $plugin_info ); - } elseif ( ! self::is_wp_plugin_active( $plugin_name ) ) { - $notice = $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 ), - esc_html( basename( $plugin_info[ self::PLUGIN_INFO_KEY_NICE_NAME ] ) ), - esc_html( basename( $plugin_info[ self::PLUGIN_INFO_KEY_NICE_NAME ] ) ) ) ); - } + /** + * @param array $notices + * + * @return array + */ + private function append_plugin_require_notices( $notices ) { + if ( count( $this->plugin_require ) > 0 ) { + foreach ( $this->plugin_require as $plugin_name => $plugin_info ) { + $notice = null; + if ( isset( $plugin_info['repository_url'] ) ) { + $notice = $this->prepare_plugin_repository_require_notice( $plugin_info ); + } elseif ( ! self::is_wp_plugin_active( $plugin_name ) ) { + $notice = $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 ), + esc_html( basename( $plugin_info[ self::PLUGIN_INFO_KEY_NICE_NAME ] ) ), + esc_html( basename( $plugin_info[ self::PLUGIN_INFO_KEY_NICE_NAME ] ) ) ) ); + } - if ( $notice !== null ) { - $notices[] = $notice; + if ( $notice !== null ) { + $notices[] = $notice; + } } } - } - return $notices; - } + return $notices; + } - /** - * Prepares WP install url and injects info about plugin to the WP update engine. - * - * @param array $plugin_info - * - * @return string - */ - private function prepare_plugin_repository_install_url( $plugin_info ) { - $slug = basename( $plugin_info[ self::PLUGIN_INFO_KEY_NAME ] ); - $install_url = self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ); - if ( function_exists( 'wp_nonce_url' ) && function_exists( 'wp_create_nonce' ) ) { - $install_url = wp_nonce_url( $install_url, 'install-plugin_' . $slug ); - } - add_filter( 'plugins_api', function ( $api, $action, $args ) use ( $plugin_info, $slug ) { - if ( 'plugin_information' !== $action || - false !== $api || - ! isset( $args->slug ) || - $slug !== $args->slug - ) { - return $api; + /** + * Prepares WP install url and injects info about plugin to the WP update engine. + * + * @param array $plugin_info + * + * @return string + */ + private function prepare_plugin_repository_install_url( $plugin_info ) { + $slug = basename( $plugin_info[ self::PLUGIN_INFO_KEY_NAME ] ); + $install_url = self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ); + if ( function_exists( 'wp_nonce_url' ) && function_exists( 'wp_create_nonce' ) ) { + $install_url = wp_nonce_url( $install_url, 'install-plugin_' . $slug ); } + add_filter( 'plugins_api', function ( $api, $action, $args ) use ( $plugin_info, $slug ) { + if ( 'plugin_information' !== $action || + false !== $api || + ! isset( $args->slug ) || + $slug !== $args->slug + ) { + return $api; + } - $api = new stdClass(); - $api->name = $plugin_info['nice_name']; // self in closures requires 5.4 - $api->version = ''; - $api->download_link = esc_url( $plugin_info['repository_url'] ); // self in closures requires 5.4 - - return $api; - }, 10, 3 ); + $api = new stdClass(); + $api->name = $plugin_info['nice_name']; // self in closures requires 5.4 + $api->version = ''; + $api->download_link = esc_url( $plugin_info['repository_url'] ); // self in closures requires 5.4 - return $install_url; - } + return $api; + }, 10, 3 ); - /** - * @param array $plugin_info Internal required plugin info data. - * - * @return string|null Return null if no notice is needed. - */ - private function prepare_plugin_repository_require_notice( $plugin_info ) { - $name = $plugin_info[ self::PLUGIN_INFO_KEY_NAME ]; - $nice_name = $plugin_info[ self::PLUGIN_INFO_KEY_NICE_NAME ]; + return $install_url; + } - if ( ! self::is_wp_plugin_active( $name ) ) { - if ( ! self::is_wp_plugin_installed( $name ) ) { - $install_url = $this->prepare_plugin_repository_install_url( $plugin_info ); + /** + * @param array $plugin_info Internal required plugin info data. + * + * @return string|null Return null if no notice is needed. + */ + private function prepare_plugin_repository_require_notice( $plugin_info ) { + $name = $plugin_info[ self::PLUGIN_INFO_KEY_NAME ]; + $nice_name = $plugin_info[ self::PLUGIN_INFO_KEY_NICE_NAME ]; + + if ( ! self::is_wp_plugin_active( $name ) ) { + if ( ! self::is_wp_plugin_installed( $name ) ) { + $install_url = $this->prepare_plugin_repository_install_url( $plugin_info ); + + return $this->prepare_notice_message( sprintf( wp_kses( __( 'The “%s” plugin requires free %s plugin. <a href="%s">Install %s →</a>', + $this->get_text_domain() ), array( 'a' => array( 'href' => array() ) ) ), + $this->plugin_name, $nice_name, esc_url( $install_url ), $nice_name ) ); + } + $activate_url = 'plugins.php?action=activate&plugin=' . urlencode( $plugin_info[ self::PLUGIN_INFO_KEY_NAME ] ) . '&plugin_status=all&paged=1&s'; + if ( function_exists( 'wp_create_nonce' ) ) { + $activate_url .= '&_wpnonce=' . urlencode( wp_create_nonce( 'activate-plugin_' . $name ) ); + } - return $this->prepare_notice_message( sprintf( wp_kses( __( 'The “%s” plugin requires free %s plugin. <a href="%s">Install %s →</a>', + return $this->prepare_notice_message( sprintf( wp_kses( __( 'The “%s” plugin requires activating %s plugin. <a href="%s">Activate %s →</a>', $this->get_text_domain() ), array( 'a' => array( 'href' => array() ) ) ), - $this->plugin_name, $nice_name, esc_url( $install_url ), $nice_name ) ); - } - $activate_url = 'plugins.php?action=activate&plugin=' . urlencode( $plugin_info[ self::PLUGIN_INFO_KEY_NAME ] ) . '&plugin_status=all&paged=1&s'; - if ( function_exists( 'wp_create_nonce' ) ) { - $activate_url .= '&_wpnonce=' . urlencode( wp_create_nonce( 'activate-plugin_' . $name ) ); + $this->plugin_name, $nice_name, esc_url( admin_url( $activate_url ) ), $nice_name ) ); } - return $this->prepare_notice_message( sprintf( wp_kses( __( 'The “%s” plugin requires activating %s plugin. <a href="%s">Activate %s →</a>', - $this->get_text_domain() ), array( 'a' => array( 'href' => array() ) ) ), - $this->plugin_name, $nice_name, esc_url( admin_url( $activate_url ) ), $nice_name ) ); + return null; } - return null; - } - - /** - * Checks if plugin is active. Needs to be used in deferred way. - * - * @param string $plugin_file - * - * @return bool - */ - public static function is_wp_plugin_active( $plugin_file ) { - $active_plugins = (array) get_option( 'active_plugins', array() ); + /** + * Checks if plugin is active. Needs to be used in deferred way. + * + * @param string $plugin_file + * + * @return bool + */ + public static function is_wp_plugin_active( $plugin_file ) { + $active_plugins = (array) get_option( 'active_plugins', array() ); + + if ( is_multisite() ) { + $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); + } - if ( is_multisite() ) { - $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 plugin is installed. Needs to be enabled in deferred way. - * - * @param string $plugin_file - * - * @return bool - */ - public static function is_wp_plugin_installed( $plugin_file ) { - $plugins_data = self::retrieve_plugins_data_in_transient(); - - return array_key_exists( $plugin_file, (array) $plugins_data ); - } + /** + * Checks if plugin is installed. Needs to be enabled in deferred way. + * + * @param string $plugin_file + * + * @return bool + */ + public static function is_wp_plugin_installed( $plugin_file ) { + $plugins_data = self::retrieve_plugins_data_in_transient(); + + return array_key_exists( $plugin_file, (array) $plugins_data ); + } - /** - * @param array $notices - * - * @return array - */ - private function append_module_require_notices( $notices ) { - if ( count( $this->module_require ) > 0 ) { - foreach ( $this->module_require as $module_name => $nice_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.', - $this->get_text_domain() ), esc_html( $this->plugin_name ), - esc_html( basename( $nice_module_name ) ), esc_html( basename( $nice_module_name ) ) ) ); + /** + * @param array $notices + * + * @return array + */ + private function append_module_require_notices( $notices ) { + if ( count( $this->module_require ) > 0 ) { + foreach ( $this->module_require as $module_name => $nice_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.', + $this->get_text_domain() ), esc_html( $this->plugin_name ), + esc_html( basename( $nice_module_name ) ), esc_html( basename( $nice_module_name ) ) ) ); + } } } - } - return $notices; - } + return $notices; + } - /** - * @param string $name - * - * @return bool - */ - public static function is_module_active( $name ) { - return extension_loaded( $name ); - } + /** + * @param string $name + * + * @return bool + */ + public static function is_module_active( $name ) { + return extension_loaded( $name ); + } - /** - * @param array $notices - * - * @return array - */ - private function append_settings_require_notices( $notices ) { - if ( count( $this->setting_require ) > 0 ) { - foreach ( $this->setting_require as $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.', - $this->get_text_domain() ), esc_html( $this->plugin_name ), - esc_html( basename( $setting ) ), - esc_html( basename( $value ) ), esc_html( basename( $setting ) ) ) ); + /** + * @param array $notices + * + * @return array + */ + private function append_settings_require_notices( $notices ) { + if ( count( $this->setting_require ) > 0 ) { + foreach ( $this->setting_require as $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.', + $this->get_text_domain() ), esc_html( $this->plugin_name ), + esc_html( basename( $setting ) ), + esc_html( basename( $value ) ), esc_html( basename( $setting ) ) ) ); + } } } - } - return $notices; - } + return $notices; + } - /** - * @param string $name - * @param mixed $value - * - * @return bool - */ - public static function is_setting_set( $name, $value ) { - return ini_get( $name ) === (string) $value; - } + /** + * @param string $name + * @param mixed $value + * + * @return bool + */ + public static function is_setting_set( $name, $value ) { + return ini_get( $name ) === (string) $value; + } - /** - * @return void - * - * @deprecated use render_notices or disable_plugin - */ - public function disable_plugin_render_notice() { - add_action( self::HOOK_ADMIN_NOTICES_ACTION, array( $this, 'handle_render_notices_action' ) ); - } + /** + * @return void + * + * @deprecated use render_notices or disable_plugin + */ + public function disable_plugin_render_notice() { + add_action( self::HOOK_ADMIN_NOTICES_ACTION, array( $this, 'handle_render_notices_action' ) ); + } - /** - * Renders requirement notices in admin panel - * - * @return void - */ - public function render_notices() { - add_action( self::HOOK_ADMIN_NOTICES_ACTION, array( $this, 'handle_render_notices_action' ) ); - } + /** + * Renders requirement notices in admin panel + * + * @return void + */ + public function render_notices() { + add_action( self::HOOK_ADMIN_NOTICES_ACTION, array( $this, 'handle_render_notices_action' ) ); + } - /** - * Renders requirement notices in admin panel - * - * @return void - */ - public function disable_plugin() { - add_action( self::HOOK_ADMIN_NOTICES_ACTION, array( $this, 'handle_deactivate_action' ) ); - } + /** + * Renders requirement notices in admin panel + * + * @return void + */ + public function disable_plugin() { + add_action( self::HOOK_ADMIN_NOTICES_ACTION, array( $this, 'handle_deactivate_action' ) ); + } - /** - * @return void - * @internal Do not use as public. Public only for wp action. - * - */ - public function handle_deactivate_action() { - if ( isset( $this->plugin_file ) ) { - deactivate_plugins( plugin_basename( $this->plugin_file ) ); + /** + * @return void + * @internal Do not use as public. Public only for wp action. + * + */ + public function handle_deactivate_action() { + if ( isset( $this->plugin_file ) ) { + deactivate_plugins( plugin_basename( $this->plugin_file ) ); - delete_transient( self::PLUGIN_INFO_TRANSIENT_NAME ); + delete_transient( self::PLUGIN_INFO_TRANSIENT_NAME ); + } } - } - /** - * Triggers the transient delete after plugin deactivated - * - * @return void - */ - public function transient_delete_on_plugin_version_changed() { - add_action( self::HOOK_PLUGIN_DEACTIVATED_ACTION, array( $this, 'handle_transient_delete_action' ) ); - add_action( self::HOOK_PLUGIN_ACTIVATED_ACTION, array( $this, 'handle_transient_delete_action' ) ); - } + /** + * Triggers the transient delete after plugin deactivated + * + * @return void + */ + public function transient_delete_on_plugin_version_changed() { + add_action( self::HOOK_PLUGIN_DEACTIVATED_ACTION, array( $this, 'handle_transient_delete_action' ) ); + add_action( self::HOOK_PLUGIN_ACTIVATED_ACTION, array( $this, 'handle_transient_delete_action' ) ); + } - /** - * Handles the transient delete - * - * @return void - */ - public function handle_transient_delete_action() { - delete_transient( self::PLUGIN_INFO_TRANSIENT_NAME ); - } + /** + * Handles the transient delete + * + * @return void + */ + public function handle_transient_delete_action() { + delete_transient( self::PLUGIN_INFO_TRANSIENT_NAME ); + } - /** - * Should be called as WordPress action - * - * @return void - * @internal Do not use as public. Public only for wp action. - * - */ - public function handle_render_notices_action() { - foreach ( $this->notices as $notice ) { - echo $notice; + /** + * Should be called as WordPress action + * + * @return void + * @internal Do not use as public. Public only for wp action. + * + */ + public function handle_render_notices_action() { + foreach ( $this->notices as $notice ) { + echo $notice; + } } } -} +} \ No newline at end of file diff --git a/src/Basic_Requirement_Checker_Factory.php b/src/Basic_Requirement_Checker_Factory.php index ba3361fa0f1b8637d2ef8e6b1abb259912b67abc..e0755db9fcc679afbfb714602a56bccf2f451550 100644 --- a/src/Basic_Requirement_Checker_Factory.php +++ b/src/Basic_Requirement_Checker_Factory.php @@ -1,66 +1,74 @@ <?php -/** - * Falicitates createion of requirement checker - */ -class WPDesk_Basic_Requirement_Checker_Factory { - const LIBRARY_TEXT_DOMAIN = 'wp-basic-requirements'; + if ( ! class_exists( 'Basic_Requirement_Checker' ) ) { + require_once __DIR__ . '/Basic_Requirement_Checker.php'; + } - /** - * Creates a simplest possible version of requirement checker. - * - * @param string $plugin_file - * @param string $plugin_name - * @param string|null $text_domain Text domain to use. If null try to use library text domain. - * - * @return WPDesk_Requirement_Checker - */ - public function create_requirement_checker( $plugin_file, $plugin_name, $text_domain = null ) { - return new WPDesk_Basic_Requirement_Checker( $plugin_file, $plugin_name, - $text_domain, null, null ); + if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker_With_Update_Disable' ) ) { + require_once __DIR__ . '/Basic_Requirement_Checker_With_Update_Disable.php'; } /** - * Creates a requirement checker according to given requirements array info. - * - * @param string $plugin_file - * @param string $plugin_name - * @param string $text_domain Text domain to use. If null try to use library text domain. - * @param array $requirements Requirements array as given by plugin. - * - * @return WPDesk_Requirement_Checker + * Falicitates createion of requirement checker */ - public function create_from_requirement_array( $plugin_file, $plugin_name, $requirements, $text_domain = null ) { - $requirements_checker = new WPDesk_Basic_Requirement_Checker_With_Update_Disable( - $plugin_file, - $plugin_name, - $text_domain, - $requirements['php'], - $requirements['wp'] - ); + class WPDesk_Basic_Requirement_Checker_Factory { + const LIBRARY_TEXT_DOMAIN = 'wp-basic-requirements'; - if ( isset( $requirements['plugins'] ) ) { - foreach ( $requirements['plugins'] as $requirement ) { - $version = isset( $requirement['version'] ) ? $requirement['version'] : null; - $requirements_checker->add_plugin_require( $requirement['name'], $requirement['nice_name'], $version ); - } - - $requirements_checker->transient_delete_on_plugin_version_changed(); + /** + * Creates a simplest possible version of requirement checker. + * + * @param string $plugin_file + * @param string $plugin_name + * @param string|null $text_domain Text domain to use. If null try to use library text domain. + * + * @return WPDesk_Requirement_Checker + */ + public function create_requirement_checker( $plugin_file, $plugin_name, $text_domain = null ) { + return new WPDesk_Basic_Requirement_Checker( $plugin_file, $plugin_name, + $text_domain, null, null ); } - if ( isset( $requirements['repo_plugins'] ) ) { - foreach ( $requirements['repo_plugins'] as $requirement ) { - $requirements_checker->add_plugin_repository_require( $requirement['name'], $requirement['version'], - $requirement['nice_name'] ); + /** + * Creates a requirement checker according to given requirements array info. + * + * @param string $plugin_file + * @param string $plugin_name + * @param string $text_domain Text domain to use. If null try to use library text domain. + * @param array $requirements Requirements array as given by plugin. + * + * @return WPDesk_Requirement_Checker + */ + public function create_from_requirement_array( $plugin_file, $plugin_name, $requirements, $text_domain = null ) { + $requirements_checker = new WPDesk_Basic_Requirement_Checker_With_Update_Disable( + $plugin_file, + $plugin_name, + $text_domain, + $requirements['php'], + $requirements['wp'] + ); + + if ( isset( $requirements['plugins'] ) ) { + foreach ( $requirements['plugins'] as $requirement ) { + $version = isset( $requirement['version'] ) ? $requirement['version'] : null; + $requirements_checker->add_plugin_require( $requirement['name'], $requirement['nice_name'], $version ); + } + + $requirements_checker->transient_delete_on_plugin_version_changed(); } - } - if ( isset( $requirements['modules'] ) ) { - foreach ( $requirements['modules'] as $requirement ) { - $requirements_checker->add_php_module_require( $requirement['name'], $requirement['nice_name'] ); + if ( isset( $requirements['repo_plugins'] ) ) { + foreach ( $requirements['repo_plugins'] as $requirement ) { + $requirements_checker->add_plugin_repository_require( $requirement['name'], $requirement['version'], + $requirement['nice_name'] ); + } } - } - return $requirements_checker; - } -} \ No newline at end of file + if ( isset( $requirements['modules'] ) ) { + foreach ( $requirements['modules'] as $requirement ) { + $requirements_checker->add_php_module_require( $requirement['name'], $requirement['nice_name'] ); + } + } + + return $requirements_checker; + } + } \ No newline at end of file diff --git a/src/Basic_Requirement_Checker_With_Update_Disable.php b/src/Basic_Requirement_Checker_With_Update_Disable.php index cc8bf946130adf6ca79ee7fab919f05e1b11583f..cb668311612ffc5b2d614beb811c1f4d602b7927 100644 --- a/src/Basic_Requirement_Checker_With_Update_Disable.php +++ b/src/Basic_Requirement_Checker_With_Update_Disable.php @@ -1,37 +1,47 @@ <?php -class WPDesk_Basic_Requirement_Checker_With_Update_Disable extends WPDesk_Basic_Requirement_Checker { +if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { + require_once __DIR__ . '/Basic_Requirement_Checker.php'; +} +if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker_With_Update_Disable' ) ) { /** - * Returns true if are requirements are met. - * - * @return bool + * Checks requirements for plugin. When required plugin is updated right now, then say that requirements are not met temporary. + * have to be compatible with PHP 5.2.x */ - public function are_requirements_met() { - $has_been_met = parent::are_requirements_met(); - if ( ! $has_been_met ) { - return $has_been_met; - } - foreach ( $this->plugin_require as $name => $plugin_info ) { - if ( $this->is_currently_updated( $name ) ) { - $nice_name = $plugin_info[ self::PLUGIN_INFO_KEY_NICE_NAME ]; - $this->notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin disables temporarily as required %s plugin is being upgraded.', - $this->get_text_domain() ), - $this->plugin_name, $nice_name, $nice_name ) ); + class WPDesk_Basic_Requirement_Checker_With_Update_Disable extends WPDesk_Basic_Requirement_Checker { + + /** + * Returns true if are requirements are met. + * + * @return bool + */ + public function are_requirements_met() { + $has_been_met = parent::are_requirements_met(); + if ( ! $has_been_met ) { + return $has_been_met; + } + foreach ( $this->plugin_require as $name => $plugin_info ) { + if ( $this->is_currently_updated( $name ) ) { + $nice_name = $plugin_info[ self::PLUGIN_INFO_KEY_NICE_NAME ]; + $this->notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin disables temporarily as required %s plugin is being upgraded.', + $this->get_text_domain() ), + $this->plugin_name, $nice_name, $nice_name ) ); + } } - } - return count( $this->notices ) === 0; - } + return count( $this->notices ) === 0; + } - /** - * Is plugin upgrading right now? - * - * @param string $name - * - * @return bool - */ - private function is_currently_updated( $name ) { - return isset( $_GET['action'] ) && $_GET['action'] === 'upgrade-plugin' && $_GET['plugin'] === $name; + /** + * Is plugin upgrading right now? + * + * @param string $name + * + * @return bool + */ + private function is_currently_updated( $name ) { + return isset( $_GET['action'] ) && $_GET['action'] === 'upgrade-plugin' && $_GET['plugin'] === $name; + } } -} +} \ No newline at end of file diff --git a/src/Requirement_Checker.php b/src/Requirement_Checker.php index 48e14527d12428c0dd1e2e40280a271c01a4a9ec..033501926396359baa457b0b02229792a59077bd 100644 --- a/src/Requirement_Checker.php +++ b/src/Requirement_Checker.php @@ -1,81 +1,81 @@ <?php - -/** - * Checks requirements for plugin - * have to be compatible with PHP 5.2.x - */ -interface WPDesk_Requirement_Checker { /** - * @param string $version - * - * @return $this + * Checks requirements for plugin + * have to be compatible with PHP 5.2.x */ - public function set_min_php_require( $version ); - - /** - * @param string $version - * - * @return $this - */ - public function set_min_wp_require( $version ); - - /** - * @param string $version - * - * @return $this - */ - public function set_min_wc_require( $version ); - - /** - * @param $version - * - * @return $this - */ - public function set_min_openssl_require( $version ); - - /** - * @param string $plugin_name - * @param string $nice_plugin_name Nice plugin name for better looks in notice - * - * @return $this - */ - public function add_plugin_require( $plugin_name, $nice_plugin_name = null ); - - /** - * @param string $module_name - * @param string $nice_name Nice module name for better looks in notice - * - * @return $this - */ - public function add_php_module_require( $module_name, $nice_name = null ); - - /** - * @param string $setting - * @param mixed $value - * - * @return $this - */ - public function add_php_setting_require( $setting, $value ); - - /** - * @return bool - */ - public function are_requirements_met(); - - /** - * @return void - */ - public function disable_plugin_render_notice(); - - /** - * @return void - */ - public function render_notices(); - - /** - * Renders requirement notices in admin panel - * - * @return void - */ - public function disable_plugin(); -} \ No newline at end of file + interface WPDesk_Requirement_Checker + { + /** + * @param string $version + * + * @return $this + */ + public function set_min_php_require($version); + + /** + * @param string $version + * + * @return $this + */ + public function set_min_wp_require($version); + + /** + * @param string $version + * + * @return $this + */ + public function set_min_wc_require($version); + + /** + * @param $version + * + * @return $this + */ + public function set_min_openssl_require($version); + + /** + * @param string $plugin_name + * @param string $nice_plugin_name Nice plugin name for better looks in notice + * + * @return $this + */ + public function add_plugin_require($plugin_name, $nice_plugin_name = null); + + /** + * @param string $module_name + * @param string $nice_name Nice module name for better looks in notice + * + * @return $this + */ + public function add_php_module_require($module_name, $nice_name = null); + + /** + * @param string $setting + * @param mixed $value + * + * @return $this + */ + public function add_php_setting_require($setting, $value); + + /** + * @return bool + */ + public function are_requirements_met(); + + /** + * @return void + */ + public function disable_plugin_render_notice(); + + /** + * @return void + */ + public function render_notices(); + + /** + * Renders requirement notices in admin panel + * + * @return void + */ + public function disable_plugin(); + } \ No newline at end of file diff --git a/src/Requirement_Checker_Factory.php b/src/Requirement_Checker_Factory.php index f44e219577c58e2de376c4eaa8be5e0494fbdc30..803eb810781ebd5fa6c49eb5e77c2c64d32532fb 100644 --- a/src/Requirement_Checker_Factory.php +++ b/src/Requirement_Checker_Factory.php @@ -1,14 +1,15 @@ <?php -interface WPDesk_Requirement_Checker_Factory { - /** - * @param $plugin_file - * @param $plugin_name - * @param $text_domain - * @param $php_version - * @param $wp_version - * - * @return WPDesk_Requirement_Checker - */ - public function create_requirement_checker( $plugin_file, $plugin_name, $text_domain ); +interface WPDesk_Requirement_Checker_Factory +{ + /** + * @param $plugin_file + * @param $plugin_name + * @param $text_domain + * @param $php_version + * @param $wp_version + * + * @return WPDesk_Requirement_Checker + */ + public function create_requirement_checker($plugin_file, $plugin_name, $text_domain); }