$scanned_files = WC_Admin_Status::scan_template_files($template_path); foreach ($scanned_files as $file) { 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; } else { $theme_file = false; } if (!empty($theme_file)) { $core_version = WC_Admin_Status::get_file_version($template_path . $file); $theme_version = WC_Admin_Status::get_file_version($theme_file); if ($core_version && (empty($theme_version) || version_compare($theme_version, $core_version, '<'))) { if (!$outdated_templates) { $outdated_templates = true; } $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'), str_replace(WP_CONTENT_DIR . '/themes/', '', $theme_file), $theme_version ? $theme_version : '-', $core_version); } else { $found_files[$plugin_name][] = sprintf('<code>%s</code>', str_replace(WP_CONTENT_DIR . '/themes/', '', $theme_file)); } } } } if (!empty($found_files)) { foreach ($found_files as $plugin_name => $found_plugin_files) { ?> <tr>
/** * Show a notice highlighting bad template files */ public function template_file_check_notice() { if (isset($_GET['page']) && 'wc-status' == $_GET['page']) { return; } $core_templates = WC_Admin_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 = WC_Admin_Status::get_file_version(WC()->plugin_path() . '/templates/' . $file); $theme_version = WC_Admin_Status::get_file_version($theme_file); if ($core_version && $theme_version && version_compare($theme_version, $core_version, '<')) { $outdated = true; break; } } } if ($outdated) { include 'views/html-notice-template-check.php'; } }
public function get_OverRided() { $template_files = WC_QD_INSTALL::get_template_list(); $overrided = array(); if (is_array($template_files)) { foreach ($template_files as $file) { $theme_file = false; if (file_exists(get_stylesheet_directory() . '/' . $file)) { $theme_file = get_stylesheet_directory() . '/' . $file; } elseif (file_exists(get_stylesheet_directory() . WC_QD_THEME_TEMPLATE . $file)) { $theme_file = get_stylesheet_directory() . WC_QD_THEME_TEMPLATE . $file; } elseif (file_exists(get_template_directory() . '/' . $file)) { $theme_file = get_template_directory() . '/' . $file; } elseif (file_exists(get_template_directory() . WC_QD_THEME_TEMPLATE . $file)) { $theme_file = get_template_directory() . WC_QD_THEME_TEMPLATE . $file; } if ($theme_file !== false) { $core_version = WC_Admin_Status::get_file_version(WC_QD_TEMPLATE . $file); $theme_version = WC_Admin_Status::get_file_version($theme_file); if ($core_version && $theme_version && version_compare($theme_version, $core_version, '<')) { $overrided[] = array('file' => $file, 'corev' => $core_version, 'themev' => $theme_version, 'is_old' => true); } else { $overrided[] = array('file' => $file, 'corev' => $core_version, 'themev' => $theme_version, 'is_old' => false); } } } } return $overrided; }
/** * Get info on the current active theme, info on parent theme (if presnet) * and a list of template overrides. * * @return array */ public function get_theme_info() { $active_theme = wp_get_theme(); // Get parent theme info if this theme is a child theme, otherwise // pass empty info in the response. if (is_child_theme()) { $parent_theme = wp_get_theme($active_theme->Template); $parent_theme_info = array('parent_name' => $parent_theme->Name, 'parent_version' => $parent_theme->Version, 'parent_version_latest' => WC_Admin_Status::get_latest_theme_version($parent_theme), 'parent_author_url' => $parent_theme->{'Author URI'}); } else { $parent_theme_info = array('parent_name' => '', 'parent_version' => '', 'parent_version_latest' => '', 'parent_author_url' => ''); } /** * Scan the theme directory for all WC templates to see if our theme * overrides any of them. */ $override_files = array(); $outdated_templates = false; $scan_files = WC_Admin_Status::scan_template_files(WC()->plugin_path() . '/templates/'); foreach ($scan_files as $file) { if (file_exists(get_stylesheet_directory() . '/' . $file)) { $theme_file = get_stylesheet_directory() . '/' . $file; } elseif (file_exists(get_stylesheet_directory() . '/' . WC()->template_path() . $file)) { $theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file; } elseif (file_exists(get_template_directory() . '/' . $file)) { $theme_file = get_template_directory() . '/' . $file; } elseif (file_exists(get_template_directory() . '/' . WC()->template_path() . $file)) { $theme_file = get_template_directory() . '/' . WC()->template_path() . $file; } else { $theme_file = false; } if (!empty($theme_file)) { $core_version = WC_Admin_Status::get_file_version(WC()->plugin_path() . '/templates/' . $file); $theme_version = WC_Admin_Status::get_file_version($theme_file); if ($core_version && (empty($theme_version) || version_compare($theme_version, $core_version, '<'))) { if (!$outdated_templates) { $outdated_templates = true; } } $override_files[] = array('file' => str_replace(WP_CONTENT_DIR . '/themes/', '', $theme_file), 'version' => $theme_version, 'core_version' => $core_version); } } $active_theme_info = array('name' => $active_theme->Name, 'version' => $active_theme->Version, 'version_latest' => WC_Admin_Status::get_latest_theme_version($active_theme), 'author_url' => esc_url_raw($active_theme->{'Author URI'}), 'is_child_theme' => is_child_theme(), 'has_woocommerce_support' => current_theme_supports('woocommerce') || in_array($active_theme->template, wc_get_core_supported_themes()), 'has_woocommerce_file' => file_exists(get_stylesheet_directory() . '/woocommerce.php') || file_exists(get_template_directory() . '/woocommerce.php'), 'has_outdated_templates' => $outdated_templates, 'overrides' => $override_files); return array_merge($active_theme_info, $parent_theme_info); }
/** * Checks For Template Version */ public static function check_template_files() { $template_files = self::get_template_list(); $outdated = false; if (is_array($template_files)) { foreach ($template_files as $file) { $theme_file = false; if (file_exists(get_stylesheet_directory() . '/' . $file)) { $theme_file = get_stylesheet_directory() . '/' . $file; } elseif (file_exists(get_stylesheet_directory() . WC_QD_THEME_TEMPLATE . $file)) { $theme_file = get_stylesheet_directory() . WC_QD_THEME_TEMPLATE . $file; } elseif (file_exists(get_template_directory() . '/' . $file)) { $theme_file = get_template_directory() . '/' . $file; } elseif (file_exists(get_template_directory() . WC_QD_THEME_TEMPLATE . $file)) { $theme_file = get_template_directory() . WC_QD_THEME_TEMPLATE . $file; } if ($theme_file !== false) { $core_version = WC_Admin_Status::get_file_version(WC_QD_TEMPLATE . $file); $theme_version = WC_Admin_Status::get_file_version($theme_file); if ($core_version && $theme_version && version_compare($theme_version, $core_version, '<')) { $outdated = true; break; } } } if ($outdated) { $theme = wp_get_theme(); $message = sprintf(__('<p> <strong>Your theme (%s) contains outdated copies of some WooCommerce Quick Donation template files.</strong> These files may need updating to ensure they are compatible with the current version of WooCommerce Quick Donation. You can see which files are affected from the %ssystem status page%s. If in doubt, check with the author of the theme. </p> <p class="submit">%sLear More About Templates%s %s</p>', WC_QD_TXT), esc_html($theme['Name']), '<a href="' . admin_url('admin.php?page=wc-status') . '">', '</a>', '<a target="_blank" href="" class="button-primary" href="">', '</a>', wc_qd_remove_link('class="button" ')); wc_qd_notice($message, 'error', array('times' => 0, 'wraper' => false)); } } }