ActiveDonationFormsData.php
4 years ago
DonationData.php
4 years ago
DonationFormsData.php
2 years ago
DonationMetricsData.php
4 years ago
EditedDonationFormsData.php
4 years ago
GivePluginSettingsData.php
4 years ago
PluginsData.php
4 years ago
ServerData.php
4 years ago
ThemeData.php
4 years ago
WebsiteData.php
4 years ago
WebsiteInfoData.php
4 years ago
ThemeData.php
68 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Tracking\TrackingData; |
| 4 | |
| 5 | use Give\Tracking\Contracts\TrackData; |
| 6 | use Give\Traits\HasWpTheme; |
| 7 | use WP_Theme; |
| 8 | |
| 9 | /** |
| 10 | * Class ThemeData |
| 11 | * |
| 12 | * Represents the theme data. |
| 13 | * |
| 14 | * @package Give\Tracking\TrackingData |
| 15 | * @since 2.10.0 |
| 16 | */ |
| 17 | class ThemeData implements TrackData |
| 18 | { |
| 19 | use HasWpTheme; |
| 20 | |
| 21 | /** |
| 22 | * Returns the collection data. |
| 23 | * |
| 24 | * @since 2.10.0 |
| 25 | * |
| 26 | * @return array The collection data. |
| 27 | */ |
| 28 | public function get() |
| 29 | { |
| 30 | $theme = wp_get_theme(); |
| 31 | $data = $this->formatData($theme); |
| 32 | |
| 33 | if ($this->isChildTheme($theme)) { |
| 34 | $parentTheme = wp_get_theme($theme->offsetGet('Template')); |
| 35 | $data = array_merge($data, $this->formatData($parentTheme, true)); |
| 36 | } |
| 37 | |
| 38 | return $data; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Format theme data. |
| 43 | * |
| 44 | * @since 2.10.0 |
| 45 | * |
| 46 | * @param WP_Theme $theme |
| 47 | * @param bool $parentTheme |
| 48 | * |
| 49 | * @return array |
| 50 | */ |
| 51 | private function formatData($theme, $parentTheme = false) |
| 52 | { |
| 53 | $slugKey = 'theme_slug'; |
| 54 | $versionKey = 'theme_version'; |
| 55 | |
| 56 | if ($parentTheme) { |
| 57 | $slugKey = 'parent_theme_slug'; |
| 58 | $versionKey = 'parent_theme_version'; |
| 59 | } |
| 60 | |
| 61 | return [ |
| 62 | $slugKey => $theme->offsetGet('Stylesheet'), |
| 63 | $versionKey => $theme->get('Version'), |
| 64 | ]; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 |