theme-info.php
54 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Classes\Theme; |
| 5 | |
| 6 | class Theme_Info { |
| 7 | |
| 8 | /** @var \WP_Theme */ |
| 9 | private $theme; |
| 10 | private $slug = ''; |
| 11 | private $author_slug = ''; |
| 12 | |
| 13 | public function __construct( $stylesheet = '', $theme_root = '' ) { |
| 14 | if ( ! $stylesheet ) { |
| 15 | $stylesheet = get_template(); |
| 16 | } |
| 17 | |
| 18 | $this->theme = wp_get_theme( $stylesheet, $theme_root ); |
| 19 | } |
| 20 | |
| 21 | public function slug(): string { |
| 22 | if ( ! $this->slug ) { |
| 23 | $this->slug = strtolower( preg_replace( '/\s+/', '', $this->name() ) ); |
| 24 | } |
| 25 | |
| 26 | return $this->slug; |
| 27 | } |
| 28 | |
| 29 | public function author_slug(): string { |
| 30 | if ( ! $this->author_slug ) { |
| 31 | $this->author_slug = strtolower( preg_replace( '/\s+/', '', $this->author() ) ); |
| 32 | } |
| 33 | |
| 34 | return $this->author_slug; |
| 35 | } |
| 36 | |
| 37 | public function name(): string { |
| 38 | return $this->theme->get( 'Name' ); |
| 39 | } |
| 40 | |
| 41 | public function author(): string { |
| 42 | return $this->theme->get( 'Author' ); |
| 43 | } |
| 44 | |
| 45 | public function version(): string { |
| 46 | return $this->theme->get( 'Version' ); |
| 47 | } |
| 48 | |
| 49 | public function core(): \WP_Theme { |
| 50 | return $this->theme; |
| 51 | } |
| 52 | |
| 53 | } |
| 54 |