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