WC_GZD_Dependencies

The WooCommerce Germanized WC GZD Dependencies class.

Defined (1)

The class is defined in the following location(s).

/includes/class-wc-gzd-dependencies.php  
  1. class WC_GZD_Dependencies { 
  2.  
  3. /** 
  4. * Single instance of WooCommerce Germanized Main Class 
  5. * @var object 
  6. */ 
  7. protected static $_instance = null; 
  8.  
  9. public $loadable = true; 
  10.  
  11. public $plugin = null; 
  12. public $prefix = 'gzd'; 
  13.  
  14. public $plugins = array(); 
  15.  
  16. public $plugins_header = array( 
  17. 'woocommerce' => array(  
  18. 'name' => 'WooCommerce',  
  19. 'tested' => '',  
  20. 'requires' => '',  
  21. 'version' => '',  
  22. 'version_prefix' => 'woocommerce',  
  23. ),  
  24. ); 
  25.  
  26. public $plugins_result = array( 
  27. 'outdated' => array(),  
  28. 'unactivated' => array(),  
  29. 'untested' => array(),  
  30. ); 
  31.  
  32. public static function instance( $plugin = null ) { 
  33. if ( is_null( self::$_instance ) ) { 
  34. self::$_instance = new self( $plugin ); 
  35. return self::$_instance; 
  36.  
  37. /** 
  38. * Cloning is forbidden. 
  39. * @since 1.0 
  40. */ 
  41. public function __clone() { 
  42. _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce-germanized-pro' ), '1.0' ); 
  43.  
  44. /** 
  45. * Unserializing instances of this class is forbidden. 
  46. * @since 1.0 
  47. */ 
  48. public function __wakeup() { 
  49. _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce-germanized-pro' ), '1.0' ); 
  50.  
  51. public function __construct( $plugin = null ) { 
  52.  
  53. if ( ! $plugin ) { 
  54. $plugin = WC_germanized(); 
  55.  
  56. $this->plugin = $plugin; 
  57.  
  58. if ( $plugin->version != get_option( 'woocommerce_' . $this->prefix . '_version' ) ) { 
  59. delete_option( 'woocommerce_' . $this->prefix . '_plugin_header_data' ); 
  60.  
  61. $this->plugins = (array) get_option( 'active_plugins', array() ); 
  62.  
  63. if ( is_multisite() ) 
  64. $this->plugins = array_merge( $this->plugins, get_site_option( 'active_sitewide_plugins', array() ) ); 
  65.  
  66. $this->parse_plugin_header_data(); 
  67.  
  68. // Set Plugin versions 
  69. foreach ( $this->plugins_header as $plugin => $data ) { 
  70. $this->plugins_header[ $plugin ][ 'version' ] = $this->get_plugin_version( $data[ 'version_prefix' ] ); 
  71.  
  72. foreach ( $this->plugins_header as $plugin => $data ) { 
  73.  
  74. if ( ! $this->is_plugin_activated( $plugin ) ) { 
  75. $this->plugins_result[ 'unactivated' ][ $plugin ] = $data; 
  76. } else if ( $this->is_plugin_outdated( $plugin ) ) { 
  77. $this->plugins_result[ 'outdated' ][ $plugin ] = $data; 
  78. } else if ( ! $this->is_plugin_tested( $plugin ) ) { 
  79. $this->plugins_result[ 'untested' ][ $plugin ] = $data; 
  80.  
  81.  
  82. if ( ! empty( $this->plugins_result[ 'unactivated' ] ) || ! empty( $this->plugins_result[ 'outdated' ] ) ) { 
  83. $this->loadable = false; 
  84. remove_all_actions( 'admin_notices' ); 
  85. add_action( 'admin_notices', array( $this, 'dependencies_notice' ) ); 
  86. } else if ( ! empty( $this->plugins_result[ 'untested' ] ) ) { 
  87. remove_all_actions( 'admin_notices' ); 
  88. add_action( 'admin_notices', array( $this, 'dependencies_notice' ) ); 
  89.  
  90.  
  91. protected function get_current_plugin_path() { 
  92. return $this->plugin->plugin_path() . '/woocommerce-germanized.php'; 
  93.  
  94. protected function parse_plugin_header_data() { 
  95.  
  96. $plugin_header_data = get_option( 'woocommerce_' . $this->prefix . '_plugin_header_data', array() ); 
  97.  
  98. if ( ! empty( $plugin_header_data ) ) { 
  99. $this->plugins_header = $plugin_header_data; 
  100. return; 
  101.  
  102. $plugin_header_check = array(); 
  103.  
  104. foreach ( $this->plugins_header as $plugin => $data ) { 
  105.  
  106. $plugin_header_check[ 'requires_' . $plugin ] = 'Requires at least ' . $data[ 'name' ]; 
  107. $plugin_header_check[ 'tested_' . $plugin ] = 'Tested up to ' . $data[ 'name' ]; 
  108.  
  109.  
  110. if ( ! empty( $plugin_header_check ) ) { 
  111.  
  112. $plugin_data = get_file_data( $this->get_current_plugin_path(), $plugin_header_check ); 
  113.  
  114. foreach ( $plugin_data as $key => $value ) { 
  115. if ( strpos( $key, 'requires' ) !== false ) { 
  116. $this->plugins_header[ str_replace( 'requires_', '', $key ) ][ 'requires' ] = $value; 
  117. } else if ( strpos( $key, 'tested' ) !== false ) { 
  118. $this->plugins_header[ str_replace( 'tested_', '', $key ) ][ 'tested' ] = $value; 
  119.  
  120. update_option( 'woocommerce_' . $this->prefix . '_plugin_header_data', $this->plugins_header ); 
  121.  
  122. public function get_plugin_version( $plugin_slug ) { 
  123. $version = preg_replace( '#(\.0+)+($|-)#', '', get_option( $plugin_slug . '_version', '1.0' ) ); 
  124. return $version; 
  125.  
  126. public function is_plugin_outdated( $plugin ) { 
  127.  
  128. $plugin_data = ( isset( $this->plugins_header[ $plugin ] ) ? $this->plugins_header[ $plugin ] : false ); 
  129.  
  130. if ( ! $plugin_data || ! isset( $plugin_data[ 'requires' ] ) || empty( $plugin_data[ 'requires' ] ) ) 
  131. return false; 
  132.  
  133. if ( $this->compare_versions( $plugin_data[ 'requires' ], $this->get_plugin_version( $plugin_data[ 'version_prefix' ] ), ">" ) ) 
  134. return true; 
  135.  
  136. return false; 
  137.  
  138. public function get_plugin_path( $plugin ) { 
  139.  
  140. if ( strpos( $plugin, '.php' ) === false ) { 
  141. $plugin = trailingslashit( $plugin ) . $plugin . '.php'; 
  142.  
  143. return $plugin; 
  144.  
  145. public function is_plugin_activated( $plugin ) { 
  146.  
  147. if ( isset( $this->plugins_header[ $plugin ][ 'constant' ] ) ) { 
  148.  
  149. if ( ! defined( $this->plugins_header[ $plugin ][ 'constant' ] ) ) 
  150. return false; 
  151.  
  152. if ( strpos( $plugin, '.php' ) === false ) { 
  153. $plugin = trailingslashit( $plugin ) . $plugin . '.php'; 
  154.  
  155. return ( in_array( $plugin, $this->plugins ) || array_key_exists( $plugin, $this->plugins ) ); 
  156.  
  157. public function is_plugin_tested( $plugin ) { 
  158.  
  159. $plugin_data = ( isset( $this->plugins_header[ $plugin ] ) ? $this->plugins_header[ $plugin ] : false ); 
  160.  
  161. if ( ! $plugin_data || ! isset( $plugin_data[ 'tested' ] ) || empty( $plugin_data[ 'tested' ] ) ) 
  162. return true; 
  163.  
  164. if ( $this->compare_versions( $plugin_data[ 'tested' ], $this->get_plugin_version( $plugin_data[ 'version_prefix' ] ), ">=" ) ) 
  165. return true; 
  166.  
  167. return false; 
  168.  
  169.  
  170. /** 
  171. * This method removes accuration from $ver2 if this version is more accurate than $main_ver 
  172. */ 
  173. public function compare_versions( $main_ver, $ver2, $operator ) { 
  174.  
  175. $expl_main_ver = explode( '.', $main_ver ); 
  176. $expl_ver2 = explode( '.', $ver2 ); 
  177.  
  178. // Check if ver2 string is more accurate than main_ver 
  179. if ( sizeof( $expl_main_ver ) == 2 && sizeof( $expl_ver2 ) > 2 ) { 
  180. $new_ver_2 = array_slice( $expl_ver2, 0, 2 ); 
  181. $ver2 = implode( '.', $new_ver_2 ); 
  182.  
  183. return version_compare( $main_ver, $ver2, $operator ); 
  184.  
  185. /** 
  186. * Checks if WooCommerce is activated 
  187. *  
  188. * @return boolean true if WooCommerce is activated 
  189. */ 
  190. public function is_woocommerce_activated() { 
  191. return $this->is_plugin_activated( 'woocommerce/woocommerce.php' ); 
  192.  
  193. public function is_loadable() { 
  194. return $this->loadable; 
  195.  
  196. public function dependencies_notice() { 
  197. global $dependencies; 
  198. $dependencies = $this; 
  199.  
  200. include_once( 'admin/views/html-notice-dependencies.php' ); 
  201.