2017-07-26 14:57:52 +03:00
< ? php
namespace um ;
2023-03-28 13:14:53 +03:00
if ( ! defined ( 'ABSPATH' ) ) {
exit ;
}
2019-10-04 15:02:37 +03:00
2017-07-26 14:57:52 +03:00
/**
* Ultimate Member Dependency Checker
*
* Checks if Ultimate Member plugin is enabled
*/
if ( ! class_exists ( 'um\Dependencies' ) ) {
2018-03-19 16:31:49 +02:00
/**
* Class Dependencies
*
* @package um
*/
class Dependencies {
2017-07-26 14:57:52 +03:00
2018-03-19 16:31:49 +02:00
/**
* @var
*/
private static $active_plugins ;
2017-09-06 17:11:14 +03:00
2018-03-19 16:31:49 +02:00
/**
* For backward compatibility checking
*
* @var array
*/
public $ext_required_version = array (
2023-03-28 13:14:53 +03:00
'bbpress' => '2.0.7' ,
'followers' => '2.1.6' ,
2023-09-25 21:08:35 +03:00
'forumwp' => '2.1.5' ,
2023-03-28 13:14:53 +03:00
'friends' => '2.1.4' ,
2023-10-10 11:47:30 +03:00
'groups' => '2.4.2' ,
2023-09-25 21:08:35 +03:00
'jobboardwp' => '1.0.7' ,
2025-11-04 15:51:43 +02:00
'mailchimp' => '2.6.2' ,
2023-03-28 13:14:53 +03:00
'messaging' => '2.2.5' ,
2023-09-25 21:14:36 +03:00
'mycred' => '2.2.4' ,
2023-03-28 13:14:53 +03:00
'notices' => '2.0.5' ,
'notifications' => '2.1.3' ,
'online' => '2.1.1' ,
'private-content' => '2.0.5' ,
2023-10-10 11:47:30 +03:00
'profile-completeness' => '2.2.7' ,
2023-03-28 13:14:53 +03:00
'profile-tabs' => '1.0.0' ,
2023-09-25 21:14:36 +03:00
'recaptcha' => '2.3.4' ,
2023-03-28 13:14:53 +03:00
'reviews' => '2.1.5' ,
'social-activity' => '2.2.0' ,
'social-login' => '2.2.0' ,
'stripe' => '1.0.0' ,
2024-05-06 17:55:17 +03:00
'zapier' => '1.0.0' ,
2023-10-10 11:47:30 +03:00
'terms-conditions' => '2.1.6' ,
2023-03-28 13:14:53 +03:00
'unsplash' => '2.0.2' ,
2023-09-25 21:14:36 +03:00
'user-bookmarks' => '2.1.4' ,
2023-03-28 13:14:53 +03:00
'user-locations' => '1.0.0' ,
2023-09-25 21:14:36 +03:00
'user-notes' => '1.1.0' ,
2023-03-28 13:14:53 +03:00
'user-photos' => '2.0.4' ,
2023-10-10 11:47:30 +03:00
'user-tags' => '2.2.6' ,
2023-03-28 13:14:53 +03:00
'verified-users' => '2.0.5' ,
2023-10-10 11:47:30 +03:00
'woocommerce' => '2.3.7' ,
2019-10-04 15:02:37 +03:00
/*????*/
2023-03-28 13:14:53 +03:00
'restrict-content' => '2.0' ,
2019-10-04 15:02:37 +03:00
/*alpha*/
2023-03-28 13:14:53 +03:00
'user-exporter' => '1.0.0' ,
'google-authenticator' => '1.0.0' ,
'frontend-posting' => '1.0.0' ,
2019-10-04 15:02:37 +03:00
/*in development*/
2023-03-28 13:14:53 +03:00
'filesharing' => '1.0.0' ,
'beaver-builder' => '2.0' ,
'user-events' => '1.0.0' ,
2025-09-25 17:54:25 +03:00
'ai-assistant' => '1.0.0' ,
'ai-moderation' => '1.0.0' ,
2017-09-06 17:11:14 +03:00
2023-03-28 13:14:53 +03:00
// deprecated
'instagram' => '2.0.5' ,
);
2017-10-18 15:45:59 +03:00
2018-03-19 16:31:49 +02:00
/**
* Get all active plugins
*/
public static function init () {
self :: $active_plugins = ( array ) get_option ( 'active_plugins' , array () );
2023-03-28 13:14:53 +03:00
if ( is_multisite () ) {
2018-03-19 16:31:49 +02:00
self :: $active_plugins = array_merge ( self :: $active_plugins , get_site_option ( 'active_sitewide_plugins' , array () ) );
2023-03-28 13:14:53 +03:00
}
2018-03-19 16:31:49 +02:00
}
/**
* @return mixed
*/
public function get_active_plugins () {
2023-03-28 13:14:53 +03:00
if ( ! self :: $active_plugins ) {
self :: init ();
}
2018-03-19 16:31:49 +02:00
return self :: $active_plugins ;
}
2017-09-06 17:11:14 +03:00
2018-03-19 16:31:49 +02:00
/**
* Check if UltimateMember core plugin is active
*
* @return bool
*/
public static function ultimatemember_active_check () {
2023-03-28 13:14:53 +03:00
if ( ! self :: $active_plugins ) {
self :: init ();
}
2017-07-26 14:57:52 +03:00
2018-03-19 16:31:49 +02:00
return in_array ( 'ultimate-member/ultimate-member.php' , self :: $active_plugins ) || array_key_exists ( 'ultimate-member/ultimate-member.php' , self :: $active_plugins );
}
2017-07-26 14:57:52 +03:00
2018-03-19 16:31:49 +02:00
/**
* Check if bbPress plugin is active
*
* @return bool
*/
public static function bbpress_active_check () {
2023-03-28 13:14:53 +03:00
if ( ! self :: $active_plugins ) {
self :: init ();
}
2018-03-19 16:31:49 +02:00
return in_array ( 'bbpress/bbpress.php' , self :: $active_plugins ) || array_key_exists ( 'bbpress/bbpress.php' , self :: $active_plugins );
}
2019-07-12 12:16:50 +03:00
/**
* Check if ForumWP plugin is active
*
* @return bool
*/
public static function forumwp_active_check () {
2023-03-28 13:14:53 +03:00
if ( ! self :: $active_plugins ) {
self :: init ();
}
2019-07-12 12:16:50 +03:00
return in_array ( 'forumwp/forumwp.php' , self :: $active_plugins ) || array_key_exists ( 'forumwp/forumwp.php' , self :: $active_plugins );
}
2020-07-31 00:35:13 +03:00
/**
* Check if JobBoardWP plugin is active
*
* @return bool
*/
public static function jobboardwp_active_check () {
2023-03-28 13:14:53 +03:00
if ( ! self :: $active_plugins ) {
self :: init ();
}
2020-07-31 00:35:13 +03:00
return in_array ( 'jobboardwp/jobboardwp.php' , self :: $active_plugins ) || array_key_exists ( 'jobboardwp/jobboardwp.php' , self :: $active_plugins );
}
2018-03-19 16:31:49 +02:00
/**
* Check if myCRED plugin is active
*
* @return bool
*/
public static function mycred_active_check () {
2023-03-28 13:14:53 +03:00
if ( ! self :: $active_plugins ) {
self :: init ();
}
2018-03-19 16:31:49 +02:00
return in_array ( 'mycred/mycred.php' , self :: $active_plugins ) || array_key_exists ( 'mycred/mycred.php' , self :: $active_plugins );
}
/**
* Check if Woocommerce plugin is active
*
* @return bool
*/
public static function woocommerce_active_check () {
2023-03-28 13:14:53 +03:00
if ( ! self :: $active_plugins ) {
self :: init ();
}
2018-03-19 16:31:49 +02:00
return in_array ( 'woocommerce/woocommerce.php' , self :: $active_plugins ) || array_key_exists ( 'woocommerce/woocommerce.php' , self :: $active_plugins );
}
/**
* Compare UM core and extension versions
*
2025-04-21 23:30:03 +03:00
* @param string $um_required_ver UM core required version.
2018-03-19 16:31:49 +02:00
* @param string $ext_ver
* @param string $ext_key
* @param string $ext_title
2025-04-21 23:30:03 +03:00
* @param bool $raw False by default. Then return message. Use `true` in conditions inside `plugins_loaded` hook
2018-03-19 16:31:49 +02:00
* @return bool
*/
2025-04-21 23:30:03 +03:00
public function compare_versions ( $um_required_ver , $ext_ver , $ext_key , $ext_title , $raw = false ) {
if ( empty ( $this -> ext_required_version [ $ext_key ] ) ||
version_compare ( UM_VERSION , $um_required_ver , '<' ) ||
version_compare ( $this -> ext_required_version [ $ext_key ], $ext_ver , '>' ) ) {
2018-03-19 16:31:49 +02:00
$message = '' ;
2023-09-13 22:56:32 +03:00
if ( version_compare ( UM_VERSION , $um_required_ver , '<' ) ) {
2025-04-21 23:30:03 +03:00
if ( $raw ) {
return false ;
}
if ( UM () -> is_new_ui () ) {
// translators: %1$s is an extension name; %2$s is a plugin name; %3$s is a required version.
$message = sprintf ( __ ( 'When new UI is enabled this version of <strong>"%1$s"</strong> requires the core <strong>%2$s</strong> plugin to be <strong>%3$s</strong> or higher.' , 'ultimate-member' ), $ext_title , UM_PLUGIN_NAME , $um_required_ver ) .
'<br />' .
// translators: %s: plugin name.
sprintf ( __ ( 'Please update <strong>%s</strong> to the latest version or disable new UI.' , 'ultimate-member' ), UM_PLUGIN_NAME );
} else {
// translators: %1$s is an extension name; %2$s is a plugin name; %3$s is a required version.
$message = sprintf ( __ ( 'This version of <strong>"%1$s"</strong> requires the core <strong>%2$s</strong> plugin to be <strong>%3$s</strong> or higher.' , 'ultimate-member' ), $ext_title , UM_PLUGIN_NAME , $um_required_ver ) .
'<br />' .
// translators: %s: plugin name.
sprintf ( __ ( 'Please update <strong>%s</strong> to the latest version.' , 'ultimate-member' ), UM_PLUGIN_NAME );
}
2023-07-13 11:36:29 +03:00
} elseif ( empty ( $this -> ext_required_version [ $ext_key ] ) || version_compare ( $this -> ext_required_version [ $ext_key ], $ext_ver , '>' ) ) {
2025-04-21 23:30:03 +03:00
if ( $raw ) {
return false ;
}
// translators: %1$s is a plugin name; %2$s is an extension name; %3$s is an extension version.
2023-09-13 22:56:32 +03:00
$message = sprintf ( __ ( 'Sorry, but this version of <strong>%1$s</strong> does not work with extension <strong>"%2$s" %3$s</strong> version.' , 'ultimate-member' ), UM_PLUGIN_NAME , $ext_title , $ext_ver ) .
2023-10-09 21:32:12 +08:00
'<br /> ' .
2023-07-13 11:36:29 +03:00
// translators: %s: extension name.
sprintf ( __ ( 'Please update extension <strong>"%s"</strong> to the latest version.' , 'ultimate-member' ), $ext_title );
2018-03-19 16:31:49 +02:00
}
return $message ;
2025-04-21 23:30:03 +03:00
}
// Check correct folder name for extensions.
if ( ! self :: $active_plugins ) {
self :: init ();
}
2018-03-19 16:31:49 +02:00
2025-04-21 23:30:03 +03:00
if ( ! array_key_exists ( " um- { $ext_key } /um- { $ext_key } .php " , self :: $active_plugins ) &&
! in_array ( " um- { $ext_key } /um- { $ext_key } .php " , self :: $active_plugins , true ) ) {
if ( $raw ) {
return false ;
2018-03-19 16:31:49 +02:00
}
2025-04-21 23:30:03 +03:00
// translators: %1$s is an extension name; %2$s is an extension version.
return sprintf ( __ ( 'Please check <strong>"%1$s" %2$s</strong> extension\'s folder name.' , 'ultimate-member' ), $ext_title , $ext_ver ) .
'<br />' .
// translators: %s: extension name.
sprintf ( __ ( 'Correct folder name is <strong>"%s"</strong>' , 'ultimate-member' ), " um- { $ext_key } " );
2018-03-19 16:31:49 +02:00
}
return true ;
}
/**
* @param string $extension_version Extension version
* @return mixed
*/
public static function php_version_check ( $extension_version ) {
return version_compare ( phpversion (), $extension_version , '>=' );
}
}
2017-07-26 14:57:52 +03:00
}
if ( ! function_exists ( 'is_um_active' ) ) {
2018-03-19 16:31:49 +02:00
/**
* Check UltimateMember core is active
*
* @return bool active - true | inactive - false
*/
function is_um_active () {
return Dependencies :: ultimatemember_active_check ();
}
2023-03-28 13:14:53 +03:00
}