| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) die('Access denied.'); |
| 4 |
|
| 5 |
if (!class_exists('WP_Optimize_Dashboard_Cache')) : |
| 6 |
|
| 7 |
/** |
| 8 |
* Collects all data needed to render the Page Cache dashboard card. |
| 9 |
*/ |
| 10 |
class WP_Optimize_Dashboard_Cache implements WP_Optimize_Dashboard_Interface { |
| 11 |
|
| 12 |
/** |
| 13 |
* @return WpoDashboardCacheData |
| 14 |
*/ |
| 15 |
public function collect(): array { |
| 16 |
$cache_manager = WP_Optimize()->get_page_cache(); |
| 17 |
$config = $cache_manager->config->get(); |
| 18 |
$active = !empty($config['enable_page_caching']); |
| 19 |
|
| 20 |
$size_info = $cache_manager->get_cache_size(); |
| 21 |
|
| 22 |
$preloader_status = WP_Optimize_Page_Cache_Preloader::instance()->get_status_info(); |
| 23 |
$file_count = is_array($preloader_status) ? ($preloader_status['file_count'] ?? 0) : 0; |
| 24 |
$files_cached = is_scalar($file_count) ? (int) $file_count : 0; |
| 25 |
$last_cleared = (int) ($config['last_cleared'] ?? 0); |
| 26 |
|
| 27 |
$cache_size_bytes = isset($size_info['size']) ? (int) $size_info['size'] : 0; |
| 28 |
|
| 29 |
$cache_size_human = size_format($cache_size_bytes, 1) ?: '0 B'; |
| 30 |
|
| 31 |
return array( |
| 32 |
'active' => $active, |
| 33 |
'label' => __('Page cache', 'wp-optimize'), |
| 34 |
'files_cached' => $files_cached, |
| 35 |
'cache_size_bytes' => $cache_size_bytes, |
| 36 |
'cache_size_human' => $cache_size_bytes > 0 ? $cache_size_human : '0 B', |
| 37 |
'last_cleared_human' => WP_Optimize_Utils::human_time_diff_or_never($last_cleared), |
| 38 |
'gzip_active' => (bool) WP_Optimize()->get_options()->get_option('is_gzip_compression_enabled', false), |
| 39 |
'country_caching' => (bool) ($config['enable_cache_per_country'] ?? false), // Premium — always false in free. |
| 40 |
'is_premium' => WP_Optimize::is_premium(), |
| 41 |
); |
| 42 |
} |
| 43 |
} |
| 44 |
endif; |
| 45 |
|