YITH_Woocompare

YITH Woocommerce Compare.

Defined (1)

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

/includes/class.yith-woocompare.php  
  1. class YITH_Woocompare { 
  2.  
  3. /** 
  4. * Plugin object 
  5. * @var string 
  6. * @since 1.0.0 
  7. */ 
  8. public $obj = null; 
  9.  
  10. /** 
  11. * AJAX Helper 
  12. * @var string 
  13. * @since 1.0.0 
  14. */ 
  15. public $ajax = null; 
  16.  
  17. /** 
  18. * Constructor 
  19. * @return mixed|YITH_Woocompare_Admin|YITH_Woocompare_Frontend 
  20. * @since 1.0.0 
  21. */ 
  22. public function __construct() { 
  23.  
  24. add_action( 'widgets_init', array( $this, 'registerWidgets' ) ); 
  25.  
  26. // Load Plugin Framework 
  27. add_action( 'after_setup_theme', array( $this, 'plugin_fw_loader' ), 1 ); 
  28.  
  29. if( $this->is_frontend() ) { 
  30.  
  31. // require frontend class 
  32. require_once('class.yith-woocompare-frontend.php'); 
  33.  
  34. $this->obj = new YITH_Woocompare_Frontend(); 
  35. elseif( $this->is_admin() ) { 
  36.  
  37. // requires admin classes 
  38. require_once('class.yith-woocompare-admin.php'); 
  39.  
  40. $this->obj = new YITH_Woocompare_Admin(); 
  41.  
  42. // add image size 
  43. YITH_Woocompare_Helper::set_image_size(); 
  44.  
  45. return $this->obj; 
  46.  
  47. /** 
  48. * Detect if is frontend 
  49. * @return bool 
  50. */ 
  51. public function is_frontend() { 
  52. $is_ajax = ( defined( 'DOING_AJAX' ) && DOING_AJAX ); 
  53. $context_check = isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'frontend'; 
  54. $actions_to_check = apply_filters( 'yith_woocompare_actions_to_check_frontend', array( 'woof_draw_products' ) ); 
  55. $action_check = isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $actions_to_check ); 
  56.  
  57. return (bool) ( ! is_admin() || ( $is_ajax && ( $context_check || $action_check ) ) ); 
  58.  
  59. /** 
  60. * Detect if is admin 
  61. * @return bool 
  62. */ 
  63. public function is_admin() { 
  64. $is_ajax = ( defined( 'DOING_AJAX' ) && DOING_AJAX ); 
  65. $is_admin = ( is_admin() || $is_ajax && isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'admin' ); 
  66. return apply_filters( 'yith_woocompare_check_is_admin', (bool) $is_admin ); 
  67.  
  68. /** 
  69. * Load Plugin Framework 
  70. * @since 1.0 
  71. * @access public 
  72. * @return void 
  73. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  74. */ 
  75. public function plugin_fw_loader() { 
  76.  
  77. if ( ! defined( 'YIT_CORE_PLUGIN' ) ) { 
  78. global $plugin_fw_data; 
  79. if( ! empty( $plugin_fw_data ) ) { 
  80. $plugin_fw_file = array_shift( $plugin_fw_data ); 
  81. require_once( $plugin_fw_file ); 
  82.  
  83. /** 
  84. * Load and register widgets 
  85. * @access public 
  86. * @since 1.0.0 
  87. */ 
  88. public function registerWidgets() { 
  89. register_widget( 'YITH_Woocompare_Widget' ); 
  90.