inc/library/theme-support/class-args-theme-feature.php
<?php
/**
* Super_Awesome_Theme_Args_Theme_Feature class
*
* @package Super_Awesome_Theme
* @license GPL-2.0-or-later
* @link https://super-awesome-author.org/themes/super-awesome-theme/
*/
/**
* Class representing a theme feature with arbitrary arguments.
*
* @since 1.0.0
*/
class Super_Awesome_Theme_Args_Theme_Feature extends Super_Awesome_Theme_Theme_Feature {
/**
* String identifier for the theme feature.
*
* @since 1.0.0
* @var string
*/
protected $id;
/**
* Arbitrary arguments for the theme feature.
*
* @since 1.0.0
* @var array
*/
protected $args;
/**
* Constructor.
*
* @since 1.0.0
*
* @param string $id String identifier for the theme feature.
* @param array $args Optional. Arbitrary arguments for the theme feature.
*/
public function __construct( $id, array $args = array() ) {
parent::__construct( $id );
$this->args = $args;
}
/**
* Gets the value registered as theme support.
*
* @since 1.0.0
*
* @return array Theme support arguments, or empty array if not supported.
*/
public function get_support() {
$args = parent::get_support();
if ( is_array( $args ) && isset( $args[0] ) ) {
return $args[0];
}
return array();
}
/**
* Adds support for this feature to core.
*
* @since 1.0.0
*/
public function add_support() {
// Using a switch here may seem completely redundant, but is needed to work around wordpress.org theme check issues.
switch ( $this->id ) {
case 'custom-background':
add_theme_support( 'custom-background', $this->args );
break;
case 'custom-header':
add_theme_support( 'custom-header', $this->args );
break;
case 'custom-logo':
add_theme_support( 'custom-logo', $this->args );
break;
default:
add_theme_support( $this->id, $this->args );
}
}
}