Skip to content
Snippets Groups Projects

Minimum required plugin version demo1

Closed Krzysztof Dyszczyk requested to merge feature/minimum-plugin-version-check-demo1 into master
8 unresolved threads
5 files
+ 970
906
Compare changes
  • Side-by-side
  • Inline

Files

+ 542
487
@@ -15,6 +15,8 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
@@ -15,6 +15,8 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
const PLUGIN_INFO_KEY_NICE_NAME = 'nice_name';
const PLUGIN_INFO_KEY_NICE_NAME = 'nice_name';
const PLUGIN_INFO_KEY_NAME = 'name';
const PLUGIN_INFO_KEY_NAME = 'name';
 
const PLUGIN_INFO_VERSION = 'version';
 
const PLUGIN_INFO_REQUIRED_VERSION = 'required_version';
/** @var string */
/** @var string */
protected $plugin_name;
protected $plugin_name;
@@ -107,13 +109,15 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
@@ -107,13 +109,15 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
/**
/**
* @param string $plugin_name Name in wp format dir/file.php
* @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 $nice_plugin_name Nice plugin name for better looks in notice
 
* @param string $plugin_require_version required plugin minimum version
*
*
* @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, $plugin_require_version = null ) {
$this->plugin_require[ $plugin_name ] = array(
$this->plugin_require[ $plugin_name ] = array(
self::PLUGIN_INFO_KEY_NAME => $plugin_name,
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_KEY_NICE_NAME => $nice_plugin_name === null ? $plugin_name : $nice_plugin_name,
 
self::PLUGIN_INFO_VERSION => $plugin_require_version === null ? '0.0' : $plugin_require_version,
);
);
return $this;
return $this;
@@ -204,6 +208,7 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
@@ -204,6 +208,7 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
$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 );
 
$notices = $this->check_minimum_require_plugins_version_and_display_notices( $notices );
return $notices;
return $notices;
}
}
@@ -275,6 +280,56 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
@@ -275,6 +280,56 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
return defined( 'OPENSSL_VERSION_NUMBER' ) && OPENSSL_VERSION_NUMBER > (int) $required_version;
return defined( 'OPENSSL_VERSION_NUMBER' ) && OPENSSL_VERSION_NUMBER > (int) $required_version;
}
}
 
/**
 
* @param $notices
 
*
 
* @return array
 
*/
 
private function check_minimum_require_plugins_version_and_display_notices( $notices ) {
 
 
if ( $this->require_plugins() > 0 ) {
 
foreach ( $this->require_plugins() as $plugin ) {
 
if ( $plugin[ ucfirst( self::PLUGIN_INFO_VERSION ) ] < $plugin[ self::PLUGIN_INFO_REQUIRED_VERSION ] ) {
 
$notices[] = $this->prepare_notice_message( sprintf( __( 'The &#8220;%s&#8221; plugin requires at least %s version of %s to work correctly. Please update it', $this->get_text_domain() ),
 
esc_html( $this->plugin_name ), $plugin[ self::PLUGIN_INFO_REQUIRED_VERSION ], $plugin[ ucfirst( self::PLUGIN_INFO_KEY_NAME ) ] ) );
 
}
 
}
 
}
 
 
return $notices;
 
}
 
 
/**
 
* Check the plugins directory and retrieve all required plugin files with plugin data.
 
*
 
* @return array
 
*/
 
public function require_plugins() {
 
$require_plugins = array();
 
 
if ( file_exists( ABSPATH . '/wp-admin/includes/plugin.php' ) ) {
 
if ( ! function_exists( 'get_plugins' ) ) {
 
require_once ABSPATH . '/wp-admin/includes/plugin.php';
 
}
 
$get_existing_plugins = ( get_plugins() ? get_plugins() : array() );
 
 
if ( ! empty( $this->plugin_require ) ) {
 
foreach ( $this->plugin_require as $plugin ) {
 
if ( ! isset( $plugin[ self::PLUGIN_INFO_VERSION ] ) ) {
 
unset( $this->plugin_require[ $plugin[ self::PLUGIN_INFO_KEY_NAME ] ] );
 
} else {
 
if ( self::is_wp_plugin_active( $plugin[ self::PLUGIN_INFO_KEY_NAME ] ) ) {
 
$require_plugins[ $plugin[ self::PLUGIN_INFO_KEY_NAME ] ] = $get_existing_plugins[ $plugin[ self::PLUGIN_INFO_KEY_NAME ] ];
 
$require_plugins[ $plugin[ self::PLUGIN_INFO_KEY_NAME ] ][ self::PLUGIN_INFO_REQUIRED_VERSION ] = $plugin[ self::PLUGIN_INFO_VERSION ];
 
}
 
}
 
}
 
}
 
}
 
 
return $require_plugins;
 
}
 
/**
/**
* @param array $notices
* @param array $notices
*
*
Loading