* @since 4.1.0
*/
namespace Beyondwords\Wordpress\Component\Settings\PlayerStyle;
use Beyondwords\Wordpress\Component\Settings\SettingsUtils;
/**
* PlayerStyle setup
*
* @since 4.1.0
*/
class PlayerStyle
{
public const STANDARD = 'standard';
public const SMALL = 'small';
public const LARGE = 'large';
public const VIDEO = 'video';
/**
* API Client
*/
private $apiClient;
/**
* Constructor
*/
public function __construct($apiClient)
{
$this->apiClient = $apiClient;
add_action('admin_init', array($this, 'init'));
add_action('admin_enqueue_scripts', array($this, 'adminEnqueueScripts'));
}
/**
* Init setting.
*
* @since 4.1.0
*
* @return void
*/
public function init()
{
if (! SettingsUtils::hasApiSettings()) {
return;
}
register_setting(
'beyondwords',
'beyondwords_player_style',
[
'default' => PlayerStyle::STANDARD,
]
);
add_settings_field(
'beyondwords-player-style',
__('Player style', 'speechkit'),
array($this, 'render'),
'beyondwords',
'player'
);
}
/**
* Render setting field.
*
* @since 4.1.0
*
* @return void
**/
public function render()
{
$currentStyle = get_option('beyondwords_player_style', PlayerStyle::STANDARD);
$playerStyles = $this->getPlayerStyles();
?>
%s', // phpcs:ignore Generic.Files.LineLength.TooLong
esc_html__('playerStyle setting', 'speechkit')
)
);
?>
[
'value' => PlayerStyle::STANDARD,
'label' => __('Standard', 'speechkit'),
],
PlayerStyle::SMALL => [
'value' => PlayerStyle::SMALL,
'label' => __('Small', 'speechkit'),
],
PlayerStyle::LARGE => [
'value' => PlayerStyle::LARGE,
'label' => __('Large', 'speechkit'),
],
PlayerStyle::VIDEO => [
'value' => PlayerStyle::VIDEO,
'label' => __('Video', 'speechkit'),
'disabled' => true,
],
];
/**
* Which player style is the default?
* This is used to preselect the default option.
*/
$defaultPlayerStyle = get_option('beyondwords_player_style', PlayerStyle::STANDARD);
if (isset($styles[$defaultPlayerStyle])) {
$styles[$defaultPlayerStyle]['default'] = true;
}
/**
* Is video enabled for this project?
* If not, the video