WC_GZD_Admin_Notices

Adds Notices after Install / Update to Admin.

Defined (1)

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

/includes/admin/class-wc-gzd-admin-notices.php  
  1. class WC_GZD_Admin_Notices { 
  2.  
  3. /** 
  4. * Single instance current class 
  5. * @var object 
  6. */ 
  7. protected static $_instance = null; 
  8.  
  9. /** 
  10. * Ensures that only one instance of this class is loaded or can be loaded. 
  11. * @static 
  12. */ 
  13. public static function instance() { 
  14. if ( is_null( self::$_instance ) ) { 
  15. self::$_instance = new self(); 
  16. return self::$_instance; 
  17.  
  18. protected function __construct() { 
  19. add_action( 'admin_init', array( $this, 'check_notice_hide' ) ); 
  20. add_action( 'after_switch_theme', array( $this, 'remove_theme_notice_hide' ) ); 
  21. add_action( 'admin_print_styles', array( $this, 'add_notices' ), 1 ); 
  22.  
  23. /** 
  24. * Add notices + styles if needed. 
  25. */ 
  26. public function add_notices() { 
  27.  
  28. if ( get_option( '_wc_gzd_needs_update' ) == 1 || get_option( '_wc_gzd_needs_pages' ) == 1 || get_option( '_wc_gzd_import_available' ) == 1 ) { 
  29.  
  30. wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) ); 
  31. wp_enqueue_style( 'woocommerce-gzd-activation', plugins_url( '/assets/css/woocommerce-gzd-activation.css', WC_GERMANIZED_PLUGIN_FILE ) ); 
  32. add_action( 'admin_notices', array( $this, 'install_notice' ) ); 
  33.  
  34.  
  35. if ( ! get_option( '_wc_gzd_hide_theme_notice' ) ) { 
  36.  
  37. if ( ! WC_germanized()->is_pro() ) { 
  38.  
  39. if ( ! $this->is_theme_compatible() ) 
  40. add_action( 'admin_notices', array( $this, 'theme_incompatibility_notice' ) ); 
  41. else if ( $this->is_theme_supported_by_pro() ) 
  42. add_action( 'admin_notices', array( $this, 'theme_supported_notice' ) ); 
  43. else if ( ! $this->is_theme_ready() ) 
  44. add_action( 'admin_notices', array( $this, 'theme_not_ready_notice' ) ); 
  45.  
  46.  
  47.  
  48. if ( ! get_option( '_wc_gzd_hide_review_notice' ) ) 
  49. add_action( 'admin_notices', array( $this, 'add_review_notice' ) ); 
  50.  
  51. if ( ! get_option( '_wc_gzd_hide_pro_notice' ) && ! WC_germanized()->is_pro() ) 
  52. add_action( 'admin_notices', array( $this, 'add_pro_notice' ) ); 
  53.  
  54. if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wc-gzd-about' || get_option( '_wc_gzd_needs_pages' ) ) { 
  55. remove_action( 'admin_notices', array( $this, 'theme_incompatibility_notice' ) ); 
  56. remove_action( 'admin_notices', array( $this, 'theme_not_ready_notice' ) ); 
  57. remove_action( 'admin_notices', array( $this, 'theme_supported_notice' ) ); 
  58.  
  59. public function remove_theme_notice_hide() { 
  60. delete_option( '_wc_gzd_hide_theme_notice' ); 
  61.  
  62. /** 
  63. * Show the install notices 
  64. */ 
  65. public function install_notice() { 
  66. // If we need to update, include a message with the update button 
  67. if ( get_option( '_wc_gzd_needs_update' ) == 1 ) { 
  68. include( 'views/html-notice-update.php' ); 
  69. // Check if other german market plugin was installed 
  70. elseif ( get_option( '_wc_gzd_import_available' ) == 1 ) { 
  71. include( 'views/html-notice-import.php' ); 
  72. // If we have just installed, show a message with the install pages button 
  73. elseif ( get_option( '_wc_gzd_needs_pages' ) == 1 ) { 
  74. include( 'views/html-notice-install.php' ); 
  75.  
  76. public function check_notice_hide() { 
  77.  
  78. $notices = array(  
  79. 'wc-gzd-hide-theme-notice',  
  80. 'wc-gzd-hide-review-notice',  
  81. 'wc-gzd-hide-pro-notice' 
  82. ); 
  83.  
  84. if ( ! empty( $notices ) ) { 
  85.  
  86. foreach ( $notices as $notice ) { 
  87.  
  88. if ( isset( $_GET[ 'notice' ] ) && $_GET[ 'notice' ] == $notice && isset( $_GET['nonce'] ) && check_admin_referer( $notice, 'nonce' ) ) { 
  89.  
  90. update_option( '_' . str_replace( '-', '_', $notice ) , true ); 
  91. $redirect_url = remove_query_arg( 'notice', remove_query_arg( 'nonce', $_SERVER['REQUEST_URI'] ) ); 
  92. wp_safe_redirect( $redirect_url ); 
  93. exit(); 
  94.  
  95.  
  96.  
  97.  
  98.  
  99. public function theme_incompatibility_notice() { 
  100. include( 'views/html-notice-theme-incompatibility.php' ); 
  101.  
  102. public function theme_not_ready_notice() { 
  103. $current_theme = wp_get_theme(); 
  104. include( 'views/html-notice-theme-not-ready.php' ); 
  105.  
  106. public function theme_supported_notice() { 
  107. $current_theme = wp_get_theme(); 
  108. include( 'views/html-notice-theme-supported.php' ); 
  109.  
  110. public function is_theme_ready() { 
  111. $stylesheet = get_stylesheet_directory() . '/style.css'; 
  112. $data = get_file_data( $stylesheet, array( 'wc_gzd_compatible' => 'wc_gzd_compatible' ) ); 
  113. if ( ! $data[ 'wc_gzd_compatible' ] && ! current_theme_supports( 'woocommerce-germanized' ) ) 
  114. return false; 
  115. return true; 
  116.  
  117. public function is_theme_supported_by_pro() { 
  118.  
  119. $supporting = array( 
  120. 'enfold',  
  121. 'flatsome',  
  122. 'storefront',  
  123. 'virtue',  
  124. ); 
  125.  
  126. $current = wp_get_theme(); 
  127. if ( in_array( $current->get_template(), $supporting ) ) 
  128. return true; 
  129.  
  130. return false; 
  131.  
  132. public function add_review_notice() { 
  133.  
  134. if ( get_option( 'woocommerce_gzd_activation_date' ) ) 
  135. $this->queue_notice( 7, 'html-notice-review.php' ); 
  136.  
  137.  
  138. public function add_pro_notice() { 
  139.  
  140. if ( get_option( 'woocommerce_gzd_activation_date' ) ) 
  141. $this->queue_notice( 4, 'html-notice-pro.php' ); 
  142.  
  143. public function queue_notice( $days, $view ) { 
  144.  
  145. if ( get_option( 'woocommerce_gzd_activation_date' ) ) { 
  146.  
  147. $activation_date = ( get_option( 'woocommerce_gzd_activation_date' ) ? get_option( 'woocommerce_gzd_activation_date' ) : date( 'Y-m-d' ) ); 
  148. $diff = WC_germanized()->get_date_diff( $activation_date, date( 'Y-m-d' ) ); 
  149.  
  150. if ( $diff[ 'd' ] >= absint( $days ) ) 
  151. include( 'views/' . $view ); 
  152.  
  153.  
  154.  
  155. /** 
  156. * Checks if current theme is woocommerce germanized compatible 
  157. *  
  158. * @return boolean 
  159. */ 
  160. public function is_theme_compatible() { 
  161.  
  162. $templates_to_check = WC_germanized()->get_critical_templates(); 
  163.  
  164. if ( ! empty( $templates_to_check ) ) { 
  165.  
  166. foreach ( $templates_to_check as $template ) { 
  167.  
  168. $template_path = trailingslashit( 'woocommerce' ) . $template; 
  169.  
  170. $theme_template = locate_template( array( 
  171. $template_path,  
  172. $template 
  173. ) ); 
  174.  
  175. if ( $theme_template ) 
  176. return false; 
  177.  
  178. return true;