New notice aimed at identifying out of date template files in a theme. Also improves the status page.
@coenjacobs
This commit is contained in:
parent
3d22552559
commit
8362bfe1b7
|
@ -21,9 +21,18 @@ class WC_Admin_Notices {
|
|||
* Hook in tabs.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'switch_theme', array( $this, 'reset_admin_notices' ) );
|
||||
add_action( 'woocommerce_updated', array( $this, 'reset_admin_notices' ) );
|
||||
add_action( 'admin_print_styles', array( $this, 'add_notices' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add notices + styles if needed.
|
||||
*/
|
||||
|
@ -33,27 +42,37 @@ class WC_Admin_Notices {
|
|||
add_action( 'admin_notices', array( $this, 'install_notice' ) );
|
||||
}
|
||||
|
||||
$template = get_option( 'template' );
|
||||
$notices = get_option( 'woocommerce_admin_notices', array() );
|
||||
|
||||
if ( ! current_theme_supports( 'woocommerce' ) && ! in_array( $template, array( 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' ) ) ) {
|
||||
if ( ! empty( $_GET['hide_theme_support_notice'] ) ) {
|
||||
$notices = array_diff( $notices, array( 'theme_support' ) );
|
||||
update_option( 'woocommerce_admin_notices', $notices );
|
||||
}
|
||||
|
||||
if ( ! empty( $_GET['hide_woocommerce_theme_support_check'] ) ) {
|
||||
update_option( 'woocommerce_theme_support_check', $template );
|
||||
return;
|
||||
}
|
||||
if ( ! empty( $_GET['hide_template_files_notice'] ) ) {
|
||||
$notices = array_diff( $notices, array( 'template_files' ) );
|
||||
update_option( 'woocommerce_admin_notices', $notices );
|
||||
}
|
||||
|
||||
if ( get_option( 'woocommerce_theme_support_check' ) !== $template ) {
|
||||
if ( in_array( 'theme_support', $notices ) && ! current_theme_supports( 'woocommerce' ) ) {
|
||||
$template = get_option( 'template' );
|
||||
|
||||
if ( ! in_array( $template, array( 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' ) ) ) {
|
||||
wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) );
|
||||
add_action( 'admin_notices', array( $this, 'theme_check_notice' ) );
|
||||
}
|
||||
}
|
||||
|
||||
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' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the install notices
|
||||
*/
|
||||
function install_notice() {
|
||||
|
||||
public function install_notice() {
|
||||
// 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' );
|
||||
|
@ -68,9 +87,47 @@ class WC_Admin_Notices {
|
|||
/**
|
||||
* Show the Theme Check notice
|
||||
*/
|
||||
function theme_check_notice() {
|
||||
public function theme_check_notice() {
|
||||
include( 'views/html-notice-theme-support.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a notice highlighting bad template files
|
||||
*/
|
||||
public function template_file_check_notice() {
|
||||
if ( isset( $_GET['page'] ) && 'wc-status' == $_GET['page'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$status = include( 'class-wc-admin-status.php' );
|
||||
$core_templates = $status->scan_template_files( WC()->plugin_path() . '/templates' );
|
||||
$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 ) {
|
||||
$core_version = $status->get_file_version( WC()->plugin_path() . '/templates/' . $file );
|
||||
$theme_version = $status->get_file_version( $theme_file );
|
||||
|
||||
if ( $core_version && $theme_version && version_compare( $theme_version, $core_version, '<' ) ) {
|
||||
$outdated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
include( 'views/html-notice-template-check.php' );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
|
@ -207,6 +207,33 @@ class WC_Admin_Status {
|
|||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve metadata from a file. Based on WP Core's get_file_data function
|
||||
*
|
||||
* @since 2.1.1
|
||||
* @param string $file Path to the file
|
||||
* @param array $all_headers List of headers, in the format array('HeaderKey' => 'Header Name')
|
||||
*/
|
||||
public function get_file_version( $file ) {
|
||||
// We don't need to write to the file, so just open for reading.
|
||||
$fp = fopen( $file, 'r' );
|
||||
|
||||
// Pull only the first 8kiB of the file in.
|
||||
$file_data = fread( $fp, 8192 );
|
||||
|
||||
// PHP will close file handle, but we are good citizens.
|
||||
fclose( $fp );
|
||||
|
||||
// Make sure we catch CR-only line endings.
|
||||
$file_data = str_replace( "\r", "\n", $file_data );
|
||||
$version = '';
|
||||
|
||||
if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] )
|
||||
$version = _cleanup_header_comment( $match[1] );
|
||||
|
||||
return $version ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan the template files
|
||||
*
|
||||
|
|
|
@ -448,8 +448,7 @@
|
|||
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><?php _e( 'Template Overrides', 'woocommerce' ); ?>:</td>
|
||||
<td><?php
|
||||
<?php
|
||||
|
||||
$template_paths = apply_filters( 'woocommerce_template_overrides_scan_paths', array( 'WooCommerce' => WC()->plugin_path() . '/templates/' ) );
|
||||
$found_files = array();
|
||||
|
@ -460,30 +459,44 @@
|
|||
foreach ( $scanned_files as $plugin_name => $files ) {
|
||||
foreach ( $files as $file ) {
|
||||
if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
|
||||
$found_files[ $plugin_name ][] = '/' . $file;
|
||||
$theme_file = get_stylesheet_directory() . '/' . $file;
|
||||
} elseif ( file_exists( get_stylesheet_directory() . '/woocommerce/' . $file ) ) {
|
||||
$found_files[ $plugin_name ][] = '/woocommerce/' . $file;
|
||||
$theme_file = get_stylesheet_directory() . '/woocommerce/' . $file;
|
||||
} elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
|
||||
$found_files[ $plugin_name ][] = '/' . $file;
|
||||
$theme_file = get_template_directory() . '/' . $file;
|
||||
} elseif( file_exists( get_template_directory() . '/woocommerce/' . $file ) ) {
|
||||
$found_files[ $plugin_name ][] = '/woocommerce/' . $file;
|
||||
$theme_file = get_template_directory() . '/woocommerce/' . $file;
|
||||
} else {
|
||||
$theme_file = false;
|
||||
}
|
||||
|
||||
if ( $theme_file ) {
|
||||
$core_version = $this->get_file_version( WC()->plugin_path() . '/templates/' . $file );
|
||||
$theme_version = $this->get_file_version( $theme_file );
|
||||
|
||||
if ( $core_version && ( empty( $theme_version ) || version_compare( $theme_version, $core_version, '<' ) ) ) {
|
||||
$found_files[ $plugin_name ][] = sprintf( __( '<code>%s</code> version <strong style="color:red">%s</strong> is out of date. The core version is %s', 'woocommerce' ), basename( $theme_file ), $theme_version ? $theme_version : '-', $core_version );
|
||||
} else {
|
||||
$found_files[ $plugin_name ][] = sprintf( '<code>%s</code>', basename( $theme_file ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $found_files ) {
|
||||
$loop = 0;
|
||||
foreach ( $found_files as $plugin_name => $found_plugin_files ) {
|
||||
echo $loop > 0 ? '<br/><br/>' : '';
|
||||
echo $plugin_name . ': <br/>';
|
||||
echo implode( ', <br/>', $found_plugin_files );
|
||||
$loop++;
|
||||
?>
|
||||
<td><?php _e( 'Template Overrides', 'woocommerce' ); ?> (<?php echo $plugin_name; ?>):</td>
|
||||
<td><?php echo implode( ', <br/>', $found_plugin_files ); ?></td>
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
_e( 'No overrides present in theme.', 'woocommerce' );
|
||||
?>
|
||||
<td><?php _e( 'Template Overrides', 'woocommerce' ); ?>:</td>
|
||||
<td><?php _e( 'No overrides present in theme.', 'woocommerce' ); ?></td>
|
||||
<?php
|
||||
}
|
||||
|
||||
?></td>
|
||||
?>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
?>
|
||||
<div id="message" class="updated woocommerce-message wc-connect">
|
||||
<p><?php _e( '<strong>Your theme has bundled outdated copies of WooCommerce template files</strong> – if you encounter functionality issues on the frontend this could the reason. Ensure you update or remove them (in general we recommend only bundling the template files you actually need to customize). See the system report for full details.', 'woocommerce' ); ?></p>
|
||||
<p class="submit"><a class="button-primary" href="<?php echo esc_url( admin_url( 'admin.php?page=wc-status' ) ); ?>"><?php _e( 'System Status', 'woocommerce' ); ?></a> <a class="skip button-primary" href="<?php echo esc_url( add_query_arg( 'hide_template_files_notice', 'true' ) ); ?>"><?php _e( 'Hide this notice', 'woocommerce' ); ?></a></p>
|
||||
</div>
|
|
@ -3,5 +3,5 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|||
?>
|
||||
<div id="message" class="updated woocommerce-message wc-connect">
|
||||
<p><?php _e( '<strong>Your theme does not declare WooCommerce support</strong> – if you encounter layout issues please read our integration guide or choose a WooCommerce theme :)', 'woocommerce' ); ?></p>
|
||||
<p class="submit"><a href="<?php echo esc_url( apply_filters( 'woocommerce_docs_url', 'http://docs.woothemes.com/document/third-party-custom-theme-compatibility/', 'theme-compatibility' ) ); ?>" class="button-primary"><?php _e( 'Theme Integration Guide', 'woocommerce' ); ?></a> <a class="skip button-primary" href="<?php echo esc_url( add_query_arg( 'hide_woocommerce_theme_support_check', 'true' ) ); ?>"><?php _e( 'Hide this notice', 'woocommerce' ); ?></a></p>
|
||||
<p class="submit"><a href="<?php echo esc_url( apply_filters( 'woocommerce_docs_url', 'http://docs.woothemes.com/document/third-party-custom-theme-compatibility/', 'theme-compatibility' ) ); ?>" class="button-primary"><?php _e( 'Theme Integration Guide', 'woocommerce' ); ?></a> <a class="skip button-primary" href="<?php echo esc_url( add_query_arg( 'hide_theme_support_notice', 'true' ) ); ?>"><?php _e( 'Hide this notice', 'woocommerce' ); ?></a></p>
|
||||
</div>
|
|
@ -37,6 +37,8 @@ class WC_Install {
|
|||
public function check_version() {
|
||||
if ( ! defined( 'IFRAME_REQUEST' ) && ( get_option( 'woocommerce_version' ) != WC()->version || get_option( 'woocommerce_db_version' ) != WC()->version ) ) {
|
||||
$this->install();
|
||||
|
||||
do_action( 'woocommerce_updated' );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue