* @since 4.1.0 */ namespace Beyondwords\Wordpress\Component\Settings\Fields\PlayerStyle; use Beyondwords\Wordpress\Component\Settings\Sync; /** * PlayerStyle * * @since 4.1.0 */ defined('ABSPATH') || exit; class PlayerStyle { /** * Option name. */ public const OPTION_NAME = 'beyondwords_player_style'; public const STANDARD = 'standard'; public const SMALL = 'small'; public const LARGE = 'large'; public const VIDEO = 'video'; /** * Constructor * * @since 6.0.0 Make static. */ public static function init() { add_action('admin_init', [self::class, 'addSetting']); add_action('pre_update_option_' . self::OPTION_NAME, function ($value) { Sync::syncOptionToDashboard(self::OPTION_NAME); return $value; }); } /** * Add setting. * * @since 4.5.0 * @since 6.0.0 Make static. * * @return void */ public static function addSetting() { register_setting( 'beyondwords_player_settings', self::OPTION_NAME, [ 'default' => PlayerStyle::STANDARD, ] ); add_settings_field( 'beyondwords-player-style', __('Player style', 'speechkit'), [self::class, 'render'], 'beyondwords_player', 'styling' ); } /** * Render setting field. * * @since 4.1.0 * @since 6.0.0 Make static. * * @return void **/ public static function render() { $value = get_option(self::OPTION_NAME); $selected = PlayerStyle::STANDARD; $options = self::getOptions(); foreach ($options as $option) { if ($option['value'] === $value) { $selected = $option['value']; } } ?>
%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(self::OPTION_NAME, PlayerStyle::STANDARD); if (isset($styles[$defaultPlayerStyle])) { $styles[$defaultPlayerStyle]['default'] = true; } /** * Filters the player styles – the "Player style" `