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
|
2015-01-20 15:23:34 +00:00
|
|
|
* @version 2.3.0
|
2013-07-24 16:01:36 +00:00
|
|
|
*/
|
|
|
|
|
2014-09-20 19:52:30 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
2015-01-20 15:23:34 +00:00
|
|
|
exit;
|
2014-09-20 19:52:30 +00:00
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* WC_Admin_Notices Class
|
|
|
|
*/
|
|
|
|
class WC_Admin_Notices {
|
|
|
|
|
|
|
|
/**
|
2015-01-20 15:23:34 +00:00
|
|
|
* Array of notices - name => callback
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $notices = array(
|
|
|
|
'install' => 'install_notice',
|
|
|
|
'update' => 'update_notice',
|
|
|
|
'template_files' => 'template_file_check_notice',
|
|
|
|
'frontend_colors' => 'frontend_colors_notice',
|
|
|
|
'theme_support' => 'theme_check_notice',
|
2015-01-23 16:36:52 +00:00
|
|
|
'translation_upgrade' => 'translation_upgrade_notice',
|
|
|
|
'tracking' => 'tracking_notice'
|
2015-01-20 15:23:34 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
2013-07-24 16:01:36 +00:00
|
|
|
*/
|
|
|
|
public function __construct() {
|
2014-02-11 13:33:56 +00:00
|
|
|
add_action( 'switch_theme', array( $this, 'reset_admin_notices' ) );
|
2015-01-23 16:36:52 +00:00
|
|
|
add_action( 'woocommerce_installed', array( $this, 'reset_admin_notices' ) );
|
2015-01-20 15:23:34 +00:00
|
|
|
add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
|
|
|
|
add_action( 'woocommerce_hide_frontend_colors_notice', array( $this, 'hide_frontend_colors_notice' ) );
|
|
|
|
add_action( 'woocommerce_hide_install_notice', array( $this, 'hide_install_notice' ) );
|
|
|
|
add_action( 'woocommerce_hide_translation_upgrade_notice', array( $this, 'hide_translation_upgrade_notice' ) );
|
2015-01-23 17:20:09 +00:00
|
|
|
add_action( 'woocommerce_hide_tracking_notice', array( $this, 'hide_tracking_notice' ) );
|
2013-07-24 16:01:36 +00:00
|
|
|
add_action( 'admin_print_styles', array( $this, 'add_notices' ) );
|
2015-01-23 16:36:52 +00:00
|
|
|
add_action( 'admin_init', array( $this, 'check_optin_action' ) );
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
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() {
|
2015-01-20 15:23:34 +00:00
|
|
|
if ( $this->has_frontend_colors() ) {
|
2015-02-02 14:40:08 +00:00
|
|
|
self::add_notice( 'frontend_colors' );
|
2015-01-20 15:23:34 +00:00
|
|
|
}
|
|
|
|
|
2015-01-23 16:36:52 +00:00
|
|
|
if ( $this->has_not_confirmed_tracking() ) {
|
2015-02-02 14:40:08 +00:00
|
|
|
self::add_notice( 'tracking' );
|
2015-01-23 16:36:52 +00:00
|
|
|
}
|
|
|
|
|
2015-01-20 15:23:34 +00:00
|
|
|
if ( ! current_theme_supports( 'woocommerce' ) && ! in_array( get_option( 'template' ), wc_get_core_supported_themes() ) ) {
|
2015-02-02 14:40:08 +00:00
|
|
|
self::add_notice( 'theme_support' );
|
2015-01-20 15:23:34 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 14:40:08 +00:00
|
|
|
self::add_notice( 'template_files' );
|
2014-02-11 13:33:56 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 16:01:36 +00:00
|
|
|
/**
|
2015-01-20 15:23:34 +00:00
|
|
|
* Show a notice
|
|
|
|
* @param string $name
|
2013-07-24 16:01:36 +00:00
|
|
|
*/
|
2015-01-20 15:23:34 +00:00
|
|
|
public static function add_notice( $name ) {
|
|
|
|
$notices = array_unique( array_merge( get_option( 'woocommerce_admin_notices', array() ), array( $name ) ) );
|
|
|
|
update_option( 'woocommerce_admin_notices', $notices );
|
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2015-01-20 15:23:34 +00:00
|
|
|
/**
|
|
|
|
* Remove a notice from being displayed
|
|
|
|
* @param string $name
|
|
|
|
*/
|
|
|
|
public static function remove_notice( $name ) {
|
|
|
|
$notices = array_diff( get_option( 'woocommerce_admin_notices', array() ), array( $name ) );
|
|
|
|
update_option( 'woocommerce_admin_notices', $notices );
|
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2015-01-20 15:23:34 +00:00
|
|
|
/**
|
|
|
|
* See if a notice is being shown
|
|
|
|
* @param string $name
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function has_notice( $name ) {
|
|
|
|
return in_array( $name, get_option( 'woocommerce_admin_notices', array() ) );
|
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2015-01-20 15:23:34 +00:00
|
|
|
/**
|
|
|
|
* Hide a notice if the GET variable is set.
|
|
|
|
*/
|
|
|
|
public function hide_notices() {
|
|
|
|
if ( isset( $_GET['wc-hide-notice'] ) ) {
|
|
|
|
$hide_notice = sanitize_text_field( $_GET['wc-hide-notice'] );
|
|
|
|
self::remove_notice( $hide_notice );
|
|
|
|
do_action( 'woocommerce_hide_' . $hide_notice . '_notice' );
|
2014-02-11 13:33:56 +00:00
|
|
|
}
|
2015-01-20 15:23:34 +00:00
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2015-01-20 15:23:34 +00:00
|
|
|
/**
|
|
|
|
* When install is hidden, trigger a redirect
|
|
|
|
*/
|
|
|
|
public function hide_install_notice() {
|
|
|
|
// What's new redirect
|
|
|
|
if ( ! self::has_notice( 'update' ) ) {
|
|
|
|
delete_transient( '_wc_activation_redirect' );
|
|
|
|
wp_redirect( admin_url( 'index.php?page=wc-about&wc-updated=true' ) );
|
|
|
|
exit;
|
2015-01-14 12:17:03 +00:00
|
|
|
}
|
2015-01-20 15:23:34 +00:00
|
|
|
}
|
2015-01-14 12:17:03 +00:00
|
|
|
|
2015-01-20 15:23:34 +00:00
|
|
|
/**
|
|
|
|
* Delete colors option
|
|
|
|
*/
|
|
|
|
public function hide_frontend_colors_notice() {
|
|
|
|
delete_option( 'woocommerce_frontend_css_colors' );
|
|
|
|
}
|
2014-02-11 13:33:56 +00:00
|
|
|
|
2015-01-20 15:23:34 +00:00
|
|
|
/**
|
|
|
|
* Hide translation upgrade message
|
|
|
|
*/
|
|
|
|
public function hide_translation_upgrade_notice() {
|
|
|
|
update_option( 'woocommerce_language_pack_version', array( WC_VERSION , get_locale() ) );
|
|
|
|
}
|
2014-02-11 13:33:56 +00:00
|
|
|
|
2015-01-23 17:20:09 +00:00
|
|
|
/**
|
|
|
|
* Hide tracking notice
|
|
|
|
*/
|
|
|
|
public function hide_tracking_notice() {
|
|
|
|
update_option( 'woocommerce_allow_tracking', 'no' );
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:23:34 +00:00
|
|
|
/**
|
|
|
|
* Add notices + styles if needed.
|
|
|
|
*/
|
|
|
|
public function add_notices() {
|
|
|
|
$notices = get_option( 'woocommerce_admin_notices', array() );
|
2014-06-04 16:01:38 +00:00
|
|
|
|
2015-01-20 15:23:34 +00:00
|
|
|
foreach ( $notices as $notice ) {
|
2014-08-28 22:18:26 +00:00
|
|
|
wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) );
|
2015-02-12 11:35:12 +00:00
|
|
|
wp_enqueue_script( 'wc-admin-notices' );
|
2015-01-20 15:23:34 +00:00
|
|
|
add_action( 'admin_notices', array( $this, $this->notices[ $notice ] ) );
|
2014-06-04 16:01:38 +00:00
|
|
|
}
|
2015-01-20 15:23:34 +00:00
|
|
|
}
|
2015-01-14 12:17:03 +00:00
|
|
|
|
2015-01-20 15:23:34 +00:00
|
|
|
/**
|
|
|
|
* If we need to update, include a message with the update button
|
|
|
|
*/
|
|
|
|
public function update_notice() {
|
|
|
|
include( 'views/html-notice-update.php' );
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-01-20 15:23:34 +00:00
|
|
|
* If we have just installed, show a message with the install pages button
|
2013-07-24 16:01:36 +00:00
|
|
|
*/
|
2014-02-11 13:33:56 +00:00
|
|
|
public function install_notice() {
|
2015-01-20 15:23:34 +00:00
|
|
|
include( 'views/html-notice-install.php' );
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the Theme Check notice
|
|
|
|
*/
|
2014-02-11 13:33:56 +00:00
|
|
|
public function theme_check_notice() {
|
2015-05-22 16:52:18 +00:00
|
|
|
if ( ! current_theme_supports( 'woocommerce' ) && ! in_array( get_option( 'template' ), wc_get_core_supported_themes() ) ) {
|
2015-01-23 16:15:31 +00:00
|
|
|
include( 'views/html-notice-theme-support.php' );
|
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
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() {
|
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 ) {
|
2015-04-01 13:33:56 +00:00
|
|
|
|
2014-02-11 13:33:56 +00:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2015-04-01 13:33:56 +00:00
|
|
|
if ( $theme_file !== false ) {
|
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' );
|
2015-01-20 15:23:34 +00:00
|
|
|
} else {
|
|
|
|
self::remove_notice( 'template_files' );
|
2014-02-11 15:13:47 +00:00
|
|
|
}
|
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() {
|
2015-01-14 14:32:34 +00:00
|
|
|
$styles = (array) WC_Frontend_Scripts::get_styles();
|
2015-01-14 12:17:03 +00:00
|
|
|
|
|
|
|
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' );
|
|
|
|
}
|
2015-01-23 16:36:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* See if the user has explicitly opted out fro tracking
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function has_not_confirmed_tracking() {
|
|
|
|
return 'unknown' === get_option( 'woocommerce_allow_tracking', 'unknown' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notice to opt-in into tracking
|
|
|
|
*/
|
|
|
|
public function tracking_notice() {
|
|
|
|
if ( current_user_can( 'manage_woocommerce' ) ) {
|
|
|
|
include( 'views/html-notice-tracking.php' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle opt in or out actions based on notice selection
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function check_optin_action() {
|
|
|
|
if ( ! isset( $_GET['wc_tracker_optin'] ) || ! isset( $_GET['wc_tracker_nonce'] ) || ! wp_verify_nonce( $_GET['wc_tracker_nonce'], 'wc_tracker_optin' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Enable tracking
|
2015-01-23 17:20:09 +00:00
|
|
|
update_option( 'woocommerce_allow_tracking', 'yes' );
|
2015-01-23 16:36:52 +00:00
|
|
|
|
|
|
|
// Remove notice
|
|
|
|
self::remove_notice( 'tracking' );
|
|
|
|
|
|
|
|
// Trigger the first track
|
|
|
|
WC_Tracker::send_tracking_data( true );
|
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
2015-01-20 15:23:34 +00:00
|
|
|
new WC_Admin_Notices();
|