| 1 |
<?php |
| 2 |
/** |
| 3 |
* Theme Checker class |
| 4 |
* |
| 5 |
* @package micropackage/requirements |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Micropackage\Requirements\Checker; |
| 9 |
|
| 10 |
use Micropackage\Requirements\Abstracts; |
| 11 |
use Micropackage\Requirements\Requirements; |
| 12 |
|
| 13 |
/** |
| 14 |
* Theme Checker class |
| 15 |
*/ |
| 16 |
class Theme extends Abstracts\Checker { |
| 17 |
|
| 18 |
/** |
| 19 |
* Checker name |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
protected $name = 'theme'; |
| 24 |
|
| 25 |
/** |
| 26 |
* Checks if the requirement is met |
| 27 |
* |
| 28 |
* @since 1.0.0 |
| 29 |
* @throws \Exception When provided value is not an array with keys: slug, name. |
| 30 |
* @param mixed $value Value to check against. |
| 31 |
* @return void |
| 32 |
*/ |
| 33 |
public function check( $value ) { |
| 34 |
|
| 35 |
if ( ! is_array( $value ) ) { |
| 36 |
throw new \Exception( 'Theme Check requires array parameter with keys: slug, name' ); |
| 37 |
} |
| 38 |
|
| 39 |
if ( ! array_key_exists( 'slug', $value ) || ! array_key_exists( 'name', $value ) ) { |
| 40 |
throw new \Exception( 'Theme Check requires array parameter with keys: slug, name' ); |
| 41 |
} |
| 42 |
|
| 43 |
$theme = wp_get_theme(); |
| 44 |
|
| 45 |
if ( $theme->get_template() !== $value['slug'] ) { |
| 46 |
// Translators: theme name. |
| 47 |
$this->add_error( sprintf( __( 'Required theme: %s', Requirements::$textdomain ), $value['name'] ) ); |
| 48 |
} |
| 49 |
|
| 50 |
} |
| 51 |
|
| 52 |
} |
| 53 |
|