ameliabooking
/
vendor
/
melograno
/
usage-tracker
/
src
/
Collectors
/
Common
/
ActivationCollector.php
ActivationCollector.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AmeliaVendor\Melograno\UsageTracker\Collectors\Common; |
| 6 | |
| 7 | class ActivationCollector |
| 8 | { |
| 9 | /** |
| 10 | * @return array<string, mixed> |
| 11 | */ |
| 12 | public function collect(): array |
| 13 | { |
| 14 | $data = [ |
| 15 | 'active_plugin_count' => null, |
| 16 | 'theme' => null, |
| 17 | ]; |
| 18 | |
| 19 | if (function_exists('get_plugins') && function_exists('is_plugin_active')) { |
| 20 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 21 | $plugins = get_plugins(); |
| 22 | $active = 0; |
| 23 | |
| 24 | foreach (array_keys($plugins) as $plugin) { |
| 25 | if (is_plugin_active($plugin)) { |
| 26 | $active++; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | $data['active_plugin_count'] = $active; |
| 31 | } |
| 32 | |
| 33 | if (function_exists('wp_get_theme')) { |
| 34 | $theme = wp_get_theme(); |
| 35 | $data['theme'] = $theme->get('Name'); |
| 36 | } |
| 37 | |
| 38 | return array_filter($data, static function ($value) { |
| 39 | return $value !== null; |
| 40 | }); |
| 41 | } |
| 42 | } |
| 43 |