2013-07-24 16:01:36 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Display notices in admin.
|
|
|
|
*
|
|
|
|
* @author WooThemes
|
|
|
|
* @category Admin
|
|
|
|
* @package WooCommerce/Admin
|
|
|
|
* @version 2.1.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
|
|
|
|
|
|
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
|
|
|
|
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 ) ) {
|
|
|
|
add_action( 'admin_notices', array( $this, 'translation_upgrade_notice' ) );
|
|
|
|
}
|
2014-08-15 09:28:23 +00:00
|
|
|
|
|
|
|
if ( ! class_exists( 'WC_Mijireh_Checkout' ) && ( $mijireh = get_option( 'woocommerce_mijireh_checkout_settings', false ) ) && ! empty( $mijireh['enabled'] ) && $mijireh['enabled'] === 'yes' && empty( $_GET['action'] ) ) {
|
|
|
|
add_action( 'admin_notices', array( $this, 'mijireh_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
|
|
|
}
|
2014-08-15 09:28:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notice to say Mijireh has been deprecated in 2.2
|
|
|
|
*/
|
|
|
|
public function mijireh_notice() {
|
|
|
|
include( 'views/html-notice-mijireh.php' );
|
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
endif;
|
|
|
|
|
2014-06-04 16:01:38 +00:00
|
|
|
return new WC_Admin_Notices();
|