class-otgs-installer-wp-components-storage.php
2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
class OTGS_Installer_WP_Components_Storage {
const COMPONENTS_CACHE_OPTION_KEY = 'otgs_active_components';
public function refresh_cache() {
$active_theme = wp_get_theme();
$installed_plugins = $this->get_plugins();
$components = array();
foreach ( $installed_plugins as $file => $plugin ) {
if ( is_plugin_active( $file ) ) {
$components['plugin'][] = array(
'File' => $file,
'Name' => $plugin['Name'],
'Version' => $plugin['Version'],
);
}
}
$components['theme'][] = array(
'Template' => $active_theme->get_template(),
'Name' => $active_theme->get( 'Name' ),
'Version' => $active_theme->get( 'Version' ),
);
update_option( self::COMPONENTS_CACHE_OPTION_KEY, $components );
}
public function is_outdated() {
$components = $this->get();
if ( ! $components ) {
return true;
}
$current_theme = wp_get_theme();
$active_plugins = get_option( 'active_plugins' );
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$installed_plugins = $this->get_plugins();
if ( isset( $components['theme'] ) ) {
if ( $components['theme'][0]['Template'] !== $current_theme->get_template() ||
$components['theme'][0]['Version'] !== $current_theme->get( 'Version' )
) {
return true;
}
}
if ( array_key_exists( 'plugin', $components ) ) {
$cached_activated_plugins = wp_list_pluck( $components['plugin'], 'File' );
sort( $cached_activated_plugins );
sort( $active_plugins );
if ( $cached_activated_plugins !== $active_plugins ) {
return true;
}
foreach ( $components['plugin'] as $plugin ) {
if ( $plugin['Version'] !== $installed_plugins[ $plugin['File'] ]['Version'] ||
! is_plugin_active( $plugin['File'] )
) {
return true;
}
}
}
return false;
}
public function get() {
return get_option( self::COMPONENTS_CACHE_OPTION_KEY );
}
/**
* @return array
*/
public function get_plugins() {
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
return get_plugins();
}
}