1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Theme information for status report. |
4
|
|
|
* |
5
|
|
|
* @package WooCommerce/Utilities |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace WooCommerce\RestApi\Controllers\Version4\Utilities; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* ThemeInformation class. |
12
|
|
|
*/ |
13
|
|
|
class ThemeInformation { |
14
|
|
|
/** |
15
|
|
|
* Get info on the current active theme, info on parent theme (if presnet) |
16
|
|
|
* and a list of template overrides. |
17
|
|
|
* |
18
|
|
|
* @return array |
19
|
|
|
*/ |
20
|
|
|
public function get_theme_info() { |
21
|
|
|
$active_theme = wp_get_theme(); |
22
|
|
|
|
23
|
|
|
// Get parent theme info if this theme is a child theme, otherwise |
24
|
|
|
// pass empty info in the response. |
25
|
|
|
if ( is_child_theme() ) { |
26
|
|
|
$parent_theme = wp_get_theme( $active_theme->template ); |
27
|
|
|
$parent_theme_info = array( |
28
|
|
|
'parent_name' => $parent_theme->name, |
29
|
|
|
'parent_version' => $parent_theme->version, |
30
|
|
|
'parent_version_latest' => \WC_Admin_Status::get_latest_theme_version( $parent_theme ), |
31
|
|
|
'parent_author_url' => $parent_theme->{'Author URI'}, |
32
|
|
|
); |
33
|
|
|
} else { |
34
|
|
|
$parent_theme_info = array( |
35
|
|
|
'parent_name' => '', |
36
|
|
|
'parent_version' => '', |
37
|
|
|
'parent_version_latest' => '', |
38
|
|
|
'parent_author_url' => '', |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Scan the theme directory for all WC templates to see if our theme |
44
|
|
|
* overrides any of them. |
45
|
|
|
*/ |
46
|
|
|
$override_files = array(); |
47
|
|
|
$outdated_templates = false; |
48
|
|
|
$scan_files = \WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates/' ); |
49
|
|
|
foreach ( $scan_files as $file ) { |
50
|
|
|
$located = apply_filters( 'wc_get_template', $file, $file, array(), WC()->template_path(), WC()->plugin_path() . '/templates/' ); |
51
|
|
|
|
52
|
|
|
if ( file_exists( $located ) ) { |
53
|
|
|
$theme_file = $located; |
54
|
|
|
} elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { |
55
|
|
|
$theme_file = get_stylesheet_directory() . '/' . $file; |
56
|
|
|
} elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) { |
57
|
|
|
$theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file; |
58
|
|
|
} elseif ( file_exists( get_template_directory() . '/' . $file ) ) { |
59
|
|
|
$theme_file = get_template_directory() . '/' . $file; |
60
|
|
|
} elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . $file ) ) { |
61
|
|
|
$theme_file = get_template_directory() . '/' . WC()->template_path() . $file; |
62
|
|
|
} else { |
63
|
|
|
$theme_file = false; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if ( ! empty( $theme_file ) ) { |
67
|
|
|
$core_version = \WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $file ); |
68
|
|
|
$theme_version = \WC_Admin_Status::get_file_version( $theme_file ); |
69
|
|
|
if ( $core_version && ( empty( $theme_version ) || version_compare( $theme_version, $core_version, '<' ) ) ) { |
70
|
|
|
if ( ! $outdated_templates ) { |
71
|
|
|
$outdated_templates = true; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
$override_files[] = array( |
75
|
|
|
'file' => str_replace( WP_CONTENT_DIR . '/themes/', '', $theme_file ), |
76
|
|
|
'version' => $theme_version, |
77
|
|
|
'core_version' => $core_version, |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$active_theme_info = array( |
83
|
|
|
'name' => $active_theme->name, |
84
|
|
|
'version' => $active_theme->version, |
85
|
|
|
'version_latest' => \WC_Admin_Status::get_latest_theme_version( $active_theme ), |
86
|
|
|
'author_url' => esc_url_raw( $active_theme->{'Author URI'} ), |
87
|
|
|
'is_child_theme' => is_child_theme(), |
88
|
|
|
'has_woocommerce_support' => current_theme_supports( 'woocommerce' ), |
89
|
|
|
'has_woocommerce_file' => ( file_exists( get_stylesheet_directory() . '/woocommerce.php' ) || file_exists( get_template_directory() . '/woocommerce.php' ) ), |
90
|
|
|
'has_outdated_templates' => $outdated_templates, |
91
|
|
|
'overrides' => $override_files, |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
return array_merge( $active_theme_info, $parent_theme_info ); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|