1 <?php
  2 /**
  3  * Display notices in admin.
  4  *
  5  * @author      WooThemes
  6  * @category    Admin
  7  * @package     WooCommerce/Admin
  8  * @version     2.1.0
  9  */
 10 
 11 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
 12 
 13 if ( ! class_exists( 'WC_Admin_Notices' ) ) :
 14 
 15 /**
 16  * WC_Admin_Notices Class
 17  */
 18 class WC_Admin_Notices {
 19 
 20     /**
 21      * Hook in tabs.
 22      */
 23     public function __construct() {
 24         add_action( 'switch_theme', array( $this, 'reset_admin_notices' ) );
 25         add_action( 'woocommerce_updated', array( $this, 'reset_admin_notices' ) );
 26         add_action( 'admin_print_styles', array( $this, 'add_notices' ) );
 27     }
 28 
 29     /**
 30      * Reset notices for themes when switched or a new version of WC is installed
 31      */
 32     public function reset_admin_notices() {
 33         update_option( 'woocommerce_admin_notices', array( 'template_files', 'theme_support' ) );
 34     }
 35 
 36     /**
 37      * Add notices + styles if needed.
 38      */
 39     public function add_notices() {
 40         if ( get_option( '_wc_needs_update' ) == 1 || get_option( '_wc_needs_pages' ) == 1 ) {
 41             wp_enqueue_style( 'woocommerce-activation', plugins_url(  '/assets/css/activation.css', WC_PLUGIN_FILE ) );
 42             add_action( 'admin_notices', array( $this, 'install_notice' ) );
 43         }
 44 
 45         $notices = get_option( 'woocommerce_admin_notices', array() );
 46 
 47         if ( ! empty( $_GET['hide_theme_support_notice'] ) ) {
 48             $notices = array_diff( $notices, array( 'theme_support' ) );
 49             update_option( 'woocommerce_admin_notices', $notices );
 50         }
 51 
 52         if ( ! empty( $_GET['hide_template_files_notice'] ) ) {
 53             $notices = array_diff( $notices, array( 'template_files' ) );
 54             update_option( 'woocommerce_admin_notices', $notices );
 55         }
 56 
 57         if ( in_array( 'theme_support', $notices ) && ! current_theme_supports( 'woocommerce' ) ) {
 58             $template = get_option( 'template' );
 59 
 60             if ( ! in_array( $template, array( 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' ) ) ) {
 61                 wp_enqueue_style( 'woocommerce-activation', plugins_url(  '/assets/css/activation.css', WC_PLUGIN_FILE ) );
 62                 add_action( 'admin_notices', array( $this, 'theme_check_notice' ) );
 63             }
 64         }
 65 
 66         if ( in_array( 'template_files', $notices ) ) {
 67             wp_enqueue_style( 'woocommerce-activation', plugins_url(  '/assets/css/activation.css', WC_PLUGIN_FILE ) );
 68             add_action( 'admin_notices', array( $this, 'template_file_check_notice' ) );
 69         }
 70     }
 71 
 72     /**
 73      * Show the install notices
 74      */
 75     public function install_notice() {
 76         // If we need to update, include a message with the update button
 77         if ( get_option( '_wc_needs_update' ) == 1 ) {
 78             include( 'views/html-notice-update.php' );
 79         }
 80 
 81         // If we have just installed, show a message with the install pages button
 82         elseif ( get_option( '_wc_needs_pages' ) == 1 ) {
 83             include( 'views/html-notice-install.php' );
 84         }
 85     }
 86 
 87     /**
 88      * Show the Theme Check notice
 89      */
 90     public function theme_check_notice() {
 91         include( 'views/html-notice-theme-support.php' );
 92     }
 93 
 94     /**
 95      * Show a notice highlighting bad template files
 96      */
 97     public function template_file_check_notice() {
 98         if ( isset( $_GET['page'] ) && 'wc-status' == $_GET['page'] ) {
 99             return;
100         }
101 
102         $status         = include( 'class-wc-admin-status.php' );
103         $core_templates = $status->scan_template_files( WC()->plugin_path() . '/templates' );
104         $outdated       = false;
105 
106         foreach ( $core_templates as $file ) {
107             $theme_file = false;
108             if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
109                 $theme_file = get_stylesheet_directory() . '/' . $file;
110             } elseif ( file_exists( get_stylesheet_directory() . '/woocommerce/' . $file ) ) {
111                 $theme_file = get_stylesheet_directory() . '/woocommerce/' . $file;
112             } elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
113                 $theme_file = get_template_directory() . '/' . $file;
114             } elseif( file_exists( get_template_directory() . '/woocommerce/' . $file ) ) {
115                 $theme_file = get_template_directory() . '/woocommerce/' . $file;
116             }
117 
118             if ( $theme_file ) {
119                 $core_version  = $status->get_file_version( WC()->plugin_path() . '/templates/' . $file );
120                 $theme_version = $status->get_file_version( $theme_file );
121 
122                 if ( $core_version && $theme_version && version_compare( $theme_version, $core_version, '<' ) ) {
123                     $outdated = true;
124                     break;
125                 }
126             }
127         }
128 
129         if ( $outdated ) {
130             include( 'views/html-notice-template-check.php' );
131         }
132     }
133 }
134 
135 endif;
136 
137 return new WC_Admin_Notices();
WooCommerce API documentation generated by ApiGen 2.8.0