暫無描述

class-dependencies.php 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. namespace um;
  3. if ( ! defined( 'ABSPATH' ) ) exit;
  4. /**
  5. * Ultimate Member Dependency Checker
  6. *
  7. * Checks if Ultimate Member plugin is enabled
  8. */
  9. if ( ! class_exists( 'um\Dependencies' ) ) {
  10. /**
  11. * Class Dependencies
  12. *
  13. * @package um
  14. */
  15. class Dependencies {
  16. /**
  17. * @var
  18. */
  19. private static $active_plugins;
  20. /**
  21. * For backward compatibility checking
  22. *
  23. * @var array
  24. */
  25. public $ext_required_version = array(
  26. 'bbpress' => '2.0.7',
  27. 'followers' => '2.1.6',
  28. 'forumwp' => '2.0.4',
  29. 'friends' => '2.1.4',
  30. 'frontend-posting' => '1.0.0',
  31. 'google-authenticator' => '1.0.0',
  32. 'groups' => '2.1.7',
  33. 'instagram' => '2.0.5',
  34. 'jobboardwp' => '1.0.0',
  35. 'mailchimp' => '2.2.0',
  36. 'messaging' => '2.2.5',
  37. 'mycred' => '2.1.6',
  38. 'notices' => '2.0.5',
  39. 'notifications' => '2.1.3',
  40. 'online' => '2.1.1',
  41. 'private-content' => '2.0.5',
  42. 'profile-completeness' => '2.1.2',
  43. 'profile-tabs' => '1.0.0',
  44. 'recaptcha' => '2.1.2',
  45. 'reviews' => '2.1.5',
  46. 'social-activity' => '2.2.0',
  47. 'social-login' => '2.2.0',
  48. 'terms-conditions' => '2.1.1',
  49. 'unsplash' => '2.0.2',
  50. 'user-bookmarks' => '2.0.2',
  51. 'user-locations' => '1.0.0',
  52. 'user-notes' => '1.0.0',
  53. 'user-photos' => '2.0.4',
  54. 'user-tags' => '2.1.0',
  55. 'verified-users' => '2.0.5',
  56. 'woocommerce' => '2.1.9',
  57. /*????*/
  58. 'restrict-content' => '2.0',
  59. /*alpha*/
  60. 'user-exporter' => '1.0.0',
  61. /*in development*/
  62. 'filesharing' => '1.0.0',
  63. 'beaver-builder' => '2.0',
  64. 'user-events' => '1.0.0',
  65. );
  66. /**
  67. * Get all active plugins
  68. */
  69. public static function init() {
  70. self::$active_plugins = (array) get_option( 'active_plugins', array() );
  71. if ( is_multisite() )
  72. self::$active_plugins = array_merge( self::$active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
  73. }
  74. /**
  75. * @return mixed
  76. */
  77. public function get_active_plugins() {
  78. if ( ! self::$active_plugins ) self::init();
  79. return self::$active_plugins;
  80. }
  81. /**
  82. * Check if UltimateMember core plugin is active
  83. *
  84. * @return bool
  85. */
  86. public static function ultimatemember_active_check() {
  87. if ( ! self::$active_plugins ) self::init();
  88. return in_array( 'ultimate-member/ultimate-member.php', self::$active_plugins ) || array_key_exists( 'ultimate-member/ultimate-member.php', self::$active_plugins );
  89. }
  90. /**
  91. * Check if bbPress plugin is active
  92. *
  93. * @return bool
  94. */
  95. public static function bbpress_active_check() {
  96. if ( ! self::$active_plugins ) self::init();
  97. return in_array( 'bbpress/bbpress.php', self::$active_plugins ) || array_key_exists( 'bbpress/bbpress.php', self::$active_plugins );
  98. }
  99. /**
  100. * Check if ForumWP plugin is active
  101. *
  102. * @return bool
  103. */
  104. public static function forumwp_active_check() {
  105. if ( ! self::$active_plugins ) self::init();
  106. return in_array( 'forumwp/forumwp.php', self::$active_plugins ) || array_key_exists( 'forumwp/forumwp.php', self::$active_plugins );
  107. }
  108. /**
  109. * Check if JobBoardWP plugin is active
  110. *
  111. * @return bool
  112. */
  113. public static function jobboardwp_active_check() {
  114. if ( ! self::$active_plugins ) self::init();
  115. return in_array( 'jobboardwp/jobboardwp.php', self::$active_plugins ) || array_key_exists( 'jobboardwp/jobboardwp.php', self::$active_plugins );
  116. }
  117. /**
  118. * Check if myCRED plugin is active
  119. *
  120. * @return bool
  121. */
  122. public static function mycred_active_check() {
  123. if ( ! self::$active_plugins ) self::init();
  124. return in_array( 'mycred/mycred.php', self::$active_plugins ) || array_key_exists( 'mycred/mycred.php', self::$active_plugins );
  125. }
  126. /**
  127. * Check if Woocommerce plugin is active
  128. *
  129. * @return bool
  130. */
  131. public static function woocommerce_active_check() {
  132. if ( ! self::$active_plugins ) self::init();
  133. return in_array( 'woocommerce/woocommerce.php', self::$active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', self::$active_plugins );
  134. }
  135. /**
  136. * Compare UM core and extension versions
  137. *
  138. * @param string $um_required_ver
  139. * @param string $ext_ver
  140. * @param string $ext_key
  141. * @param string $ext_title
  142. * @return bool
  143. */
  144. public function compare_versions( $um_required_ver, $ext_ver, $ext_key, $ext_title ) {
  145. if ( version_compare( ultimatemember_version, $um_required_ver, '<' )
  146. || empty( $this->ext_required_version[$ext_key] )
  147. || version_compare( $this->ext_required_version[$ext_key], $ext_ver, '>' ) ) {
  148. $message = '';
  149. if ( version_compare( ultimatemember_version, $um_required_ver, '<' ) ) {
  150. $message = sprintf( __( 'This version of <strong>"%s"</strong> requires the core <strong>%s</strong> plugin to be <strong>%s</strong> or higher.', 'ultimate-member' ), $ext_title, ultimatemember_plugin_name, $um_required_ver ) .
  151. '<br />' .
  152. sprintf( __( 'Please update <strong>%s</strong> to the latest version.', 'ultimate-member' ), ultimatemember_plugin_name );
  153. } elseif ( empty( $this->ext_required_version[$ext_key] ) || version_compare( $this->ext_required_version[$ext_key], $ext_ver, '>' ) ) {
  154. $message = sprintf( __( 'Sorry, but this version of <strong>%s</strong> does not work with extension <strong>"%s" %s</strong> version.', 'ultimate-member' ), ultimatemember_plugin_name, $ext_title, $ext_ver ) .
  155. '<br />' .
  156. sprintf( __( 'Please update extension <strong>"%s"</strong> to the latest version.', 'ultimate-member' ), $ext_title );
  157. }
  158. return $message;
  159. } else {
  160. //check correct folder name for extensions
  161. if ( ! self::$active_plugins ) self::init();
  162. if ( ! in_array( "um-{$ext_key}/um-{$ext_key}.php", self::$active_plugins ) && ! array_key_exists( "um-{$ext_key}/um-{$ext_key}.php", self::$active_plugins ) ) {
  163. $message = sprintf( __( 'Please check <strong>"%s" %s</strong> extension\'s folder name.', 'ultimate-member' ), $ext_title, $ext_ver ) .
  164. '<br />' .
  165. sprintf( __( 'Correct folder name is <strong>"%s"</strong>', 'ultimate-member' ), "um-{$ext_key}" );
  166. return $message;
  167. }
  168. }
  169. return true;
  170. }
  171. /**
  172. * @param string $extension_version Extension version
  173. * @return mixed
  174. */
  175. public static function php_version_check( $extension_version ) {
  176. return version_compare( phpversion(), $extension_version, '>=' );
  177. }
  178. }
  179. }
  180. if ( ! function_exists( 'is_um_active' ) ) {
  181. /**
  182. * Check UltimateMember core is active
  183. *
  184. * @return bool active - true | inactive - false
  185. */
  186. function is_um_active() {
  187. return Dependencies::ultimatemember_active_check();
  188. }
  189. }