Abstract_WJECF_Plugin

The WooCommerce Extended Coupon Features Abstract WJECF Plugin class.

Defined (1)

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

/includes/abstract-wjecf-plugin.php  
  1. abstract class Abstract_WJECF_Plugin { 
  2.  
  3. //Override these functions in the WJECF plugin 
  4.  
  5. public function init_hook() {} 
  6. public function init_admin_hook() {} 
  7.  
  8. /** 
  9. * Asserts that all dependencies are respected. If not an Exception is thrown. Override this function for extra assertions (e.g. minimum plugin versions) 
  10. * @return void 
  11. */ 
  12. public function assert_dependencies() { 
  13. foreach( $this->get_plugin_dependencies() as $dependency ) { 
  14. if ( ! isset( $this->plugins[ $dependency ] ) ) { 
  15. throw new Exception( sprintf( 'Missing dependency %s', $dependency) ); 
  16.  
  17. if ( ! empty ( $this->plugin_data['required_version_wjecf'] ) ) { 
  18. $this->assert_wjecf_version( $this->plugin_data['required_version_wjecf'] ); 
  19.  
  20. /** 
  21. * Assert minimum WJECF version number 
  22. * @param string $required_version  
  23. * @return void 
  24. */ 
  25. protected function assert_wjecf_version( $required_version ) { 
  26. if ( version_compare( WJECF()->version, $required_version, '<' ) ) { 
  27. throw new Exception( sprintf( __( 'WooCommerce Extended Coupon Features version %s is required. You have version %s', 'woocommerce-jos-autocoupon' ), $required_version, WJECF()->version ) ); 
  28. }  
  29.  
  30. // 
  31.   
  32. /** 
  33. * Log a message (for debugging) 
  34. * @param string $message The message to log 
  35. */ 
  36. protected function log ( $message ) { 
  37. WJECF()->log( $message, 1 ); 
  38.  
  39. private $plugin_data = array(); 
  40.  
  41. /** 
  42. * Information about the WJECF plugin 
  43. * @param string|null $key The data to look up. Will return an array with all data when omitted 
  44. * @return mixed 
  45. */ 
  46. protected function get_plugin_data( $key = null ) { 
  47. $default_data = array( 
  48. 'description' => '',  
  49. 'can_be_disabled' => false,  
  50. 'dependencies' => array(),  
  51. 'minimal_wjecf_version' => '' 
  52. ); 
  53. $plugin_data = array_merge( $default_data, $this->plugin_data ); 
  54. if ( $key === null ) {  
  55. return $plugin_data; 
  56. return $plugin_data[$key]; 
  57.  
  58. /** 
  59. * Set information about the WJECF plugin 
  60. * @param array $plugin_data The data for this plugin 
  61. * @return void 
  62. */ 
  63. protected function set_plugin_data( $plugin_data ) { 
  64. $this->plugin_data = $plugin_data; 
  65.  
  66. /** 
  67. * Get the description if this WJECF plugin. 
  68. * @return string 
  69. */ 
  70. public function get_plugin_description() { 
  71. return $this->get_plugin_data( 'description' ); 
  72.  
  73. /** 
  74. * Get the class name of this WJECF plugin. 
  75. * @return string 
  76. */ 
  77. public function get_plugin_class_name() { 
  78. return get_class( $this ); 
  79.  
  80. public function get_plugin_dependencies() { 
  81. return $this->get_plugin_data( 'dependencies' ); 
  82.  
  83. public function plugin_is_enabled() { 
  84. return true; 
  85.