2013-07-24 16:01:36 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Display notices in admin.
|
|
|
|
*
|
2014-11-30 06:52:32 +00:00
|
|
|
* @author WooThemes
|
|
|
|
* @category Admin
|
|
|
|
* @package WooCommerce/Admin
|
2013-07-24 16:01:36 +00:00
|
|
|
* @version 2.1.0
|
|
|
|
*/
|
|
|
|
|
2014-09-20 19:52:30 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit; // Exit if accessed directly
|
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
|
|
|
|
if ( ! class_exists( 'WC_Admin_Notices' ) ) :
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WC_Admin_Notices Class
|
|
|
|
*/
|
|
|
|
class WC_Admin_Notices {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook in tabs.
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
2014-02-11 13:33:56 +00:00
|
|
|
add_action( 'switch_theme', array( $this, 'reset_admin_notices' ) );
|
|
|
|
add_action( 'woocommerce_updated', array( $this, 'reset_admin_notices' ) );
|
2013-07-24 16:01:36 +00:00
|
|
|
add_action( 'admin_print_styles', array( $this, 'add_notices' ) );
|
|
|
|
}
|
|
|
|
|
2014-02-11 13:33:56 +00:00
|
|
|
/**
|
|
|
|
* Reset notices for themes when switched or a new version of WC is installed
|
|
|
|
*/
|
|
|
|
public function reset_admin_notices() {
|
|
|
|
update_option( 'woocommerce_admin_notices', array( 'template_files', 'theme_support' ) );
|
|
|
|
}
|
|
|
|
|
2013-07-24 16:01:36 +00:00
|
|
|
/**
|
|
|
|
* Add notices + styles if needed.
|
|
|
|
*/
|
|
|
|
public function add_notices() {
|
|
|
|
if ( get_option( '_wc_needs_update' ) == 1 || get_option( '_wc_needs_pages' ) == 1 ) {
|
2013-10-24 18:36:22 +00:00
|
|
|
wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) );
|
2013-07-24 16:01:36 +00:00
|
|
|
add_action( 'admin_notices', array( $this, 'install_notice' ) );
|
|
|
|
}
|
|
|
|
|
2014-02-11 13:33:56 +00:00
|
|
|
$notices = get_option( 'woocommerce_admin_notices', array() );
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2014-02-11 13:33:56 +00:00
|
|
|
if ( ! empty( $_GET['hide_theme_support_notice'] ) ) {
|
|
|
|
$notices = array_diff( $notices, array( 'theme_support' ) );
|
|
|
|
update_option( 'woocommerce_admin_notices', $notices );
|
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2014-02-11 13:33:56 +00:00
|
|
|
if ( ! empty( $_GET['hide_template_files_notice'] ) ) {
|
|
|
|
$notices = array_diff( $notices, array( 'template_files' ) );
|
|
|
|
update_option( 'woocommerce_admin_notices', $notices );
|
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2015-01-14 12:17:03 +00:00
|
|
|
if ( ! empty( $_GET['hide_frontend_colors_notice'] ) ) {
|
|
|
|
delete_option( 'woocommerce_frontend_css_colors' );
|
|
|
|
}
|
|
|
|
|
2014-02-11 13:33:56 +00:00
|
|
|
if ( in_array( 'theme_support', $notices ) && ! current_theme_supports( 'woocommerce' ) ) {
|
|
|
|
$template = get_option( 'template' );
|
|
|
|
|
2014-06-27 19:42:23 +00:00
|
|
|
if ( ! in_array( $template, wc_get_core_supported_themes() ) ) {
|
2013-10-24 18:36:22 +00:00
|
|
|
wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) );
|
2013-07-24 16:01:36 +00:00
|
|
|
add_action( 'admin_notices', array( $this, 'theme_check_notice' ) );
|
|
|
|
}
|
|
|
|
}
|
2014-02-11 13:33:56 +00:00
|
|
|
|
|
|
|
if ( in_array( 'template_files', $notices ) ) {
|
|
|
|
wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) );
|
|
|
|
add_action( 'admin_notices', array( $this, 'template_file_check_notice' ) );
|
|
|
|
}
|
2014-06-04 16:01:38 +00:00
|
|
|
|
|
|
|
if ( in_array( 'translation_upgrade', $notices ) ) {
|
2014-08-28 22:18:26 +00:00
|
|
|
wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) );
|
2014-06-04 16:01:38 +00:00
|
|
|
add_action( 'admin_notices', array( $this, 'translation_upgrade_notice' ) );
|
|
|
|
}
|
2015-01-14 12:17:03 +00:00
|
|
|
|
|
|
|
if ( $this->has_frontend_colors() ) {
|
|
|
|
add_action( 'admin_notices', array( $this, 'frontend_colors_notice' ) );
|
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the install notices
|
|
|
|
*/
|
2014-02-11 13:33:56 +00:00
|
|
|
public function install_notice() {
|
2013-07-24 16:01:36 +00:00
|
|
|
// If we need to update, include a message with the update button
|
|
|
|
if ( get_option( '_wc_needs_update' ) == 1 ) {
|
|
|
|
include( 'views/html-notice-update.php' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have just installed, show a message with the install pages button
|
|
|
|
elseif ( get_option( '_wc_needs_pages' ) == 1 ) {
|
|
|
|
include( 'views/html-notice-install.php' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the Theme Check notice
|
|
|
|
*/
|
2014-02-11 13:33:56 +00:00
|
|
|
public function theme_check_notice() {
|
2013-07-24 16:01:36 +00:00
|
|
|
include( 'views/html-notice-theme-support.php' );
|
|
|
|
}
|
2014-02-11 13:33:56 +00:00
|
|
|
|
2014-06-04 16:01:38 +00:00
|
|
|
/**
|
|
|
|
* Show the translation upgrade notice
|
|
|
|
*/
|
|
|
|
public function translation_upgrade_notice() {
|
|
|
|
$screen = get_current_screen();
|
|
|
|
|
|
|
|
if ( 'update-core' !== $screen->id ) {
|
|
|
|
include( 'views/html-notice-translation-upgrade.php' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-11 13:33:56 +00:00
|
|
|
/**
|
|
|
|
* Show a notice highlighting bad template files
|
|
|
|
*/
|
|
|
|
public function template_file_check_notice() {
|
|
|
|
if ( isset( $_GET['page'] ) && 'wc-status' == $_GET['page'] ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-04 10:16:19 +00:00
|
|
|
$core_templates = WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates' );
|
2014-02-11 13:33:56 +00:00
|
|
|
$outdated = false;
|
|
|
|
|
|
|
|
foreach ( $core_templates as $file ) {
|
|
|
|
$theme_file = false;
|
|
|
|
if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
|
|
|
|
$theme_file = get_stylesheet_directory() . '/' . $file;
|
|
|
|
} elseif ( file_exists( get_stylesheet_directory() . '/woocommerce/' . $file ) ) {
|
|
|
|
$theme_file = get_stylesheet_directory() . '/woocommerce/' . $file;
|
|
|
|
} elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
|
|
|
|
$theme_file = get_template_directory() . '/' . $file;
|
|
|
|
} elseif( file_exists( get_template_directory() . '/woocommerce/' . $file ) ) {
|
|
|
|
$theme_file = get_template_directory() . '/woocommerce/' . $file;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $theme_file ) {
|
2014-06-13 15:17:23 +00:00
|
|
|
$core_version = WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $file );
|
|
|
|
$theme_version = WC_Admin_Status::get_file_version( $theme_file );
|
2014-02-11 13:33:56 +00:00
|
|
|
|
|
|
|
if ( $core_version && $theme_version && version_compare( $theme_version, $core_version, '<' ) ) {
|
|
|
|
$outdated = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-11 15:13:47 +00:00
|
|
|
if ( $outdated ) {
|
|
|
|
include( 'views/html-notice-template-check.php' );
|
|
|
|
}
|
2014-02-11 13:33:56 +00:00
|
|
|
}
|
2015-01-14 12:17:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if there is any change in woocommerce_frontend_css_colors
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function has_frontend_colors() {
|
|
|
|
$styles = WC_Frontend_Scripts::get_styles();
|
|
|
|
|
|
|
|
if ( ! array_key_exists( 'woocommerce-general', $styles ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$colors = get_option( 'woocommerce_frontend_css_colors' );
|
|
|
|
$default = array(
|
|
|
|
'primary' => '#ad74a2',
|
|
|
|
'secondary' => '#f7f6f7',
|
|
|
|
'highlight' => '#85ad74',
|
|
|
|
'content_bg' => '#ffffff',
|
|
|
|
'subtext' => '#777777'
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( ! $colors || $colors === $default ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notice to say Frontend Colors options has been deprecated in 2.3
|
|
|
|
*/
|
|
|
|
public function frontend_colors_notice() {
|
|
|
|
include( 'views/html-notice-frontend-colors.php' );
|
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
endif;
|
|
|
|
|
2014-06-04 16:01:38 +00:00
|
|
|
return new WC_Admin_Notices();
|