PluginProbe
BeyondWords – AI audio for publishers / 6.0.3
BeyondWords – AI audio for publishers v6.0.3
7.1.0 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.7.0 All 43 releases
speechkit / src / Component / Settings / Fields / PlayerUI / PlayerUI.php

PlayerUI.php in BeyondWords – AI audio for publishers 6.0.3, at src/Component/Settings/Fields/PlayerUI/PlayerUI.php

137 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 /**
6 * Setting: Player UI
7 *
8 * @package Beyondwords\Wordpress
9 * @author Stuart McAlpine <stu@beyondwords.io>
10 * @since 4.0.0
11 */
12
13 namespace Beyondwords\Wordpress\Component\Settings\Fields\PlayerUI;
14
15 use Beyondwords\Wordpress\Component\Settings\Sync;
16
17 /**
18 * PlayerUI
19 *
20 * @since 4.0.0
21 */
22 class PlayerUI
23 {
24 /**
25 * Option name.
26 */
27 public const OPTION_NAME = 'beyondwords_player_ui';
28
29 public const ENABLED = 'enabled';
30
31 public const HEADLESS = 'headless';
32
33 public const DISABLED = 'disabled';
34
35 /**
36 * Init.
37 *
38 * @since 4.0.0
39 * @since 6.0.0 Make static.
40 */
41 public static function init()
42 {
43 add_action('admin_init', [self::class, 'addSetting']);
44 add_action('pre_update_option_' . self::OPTION_NAME, function ($value) {
45 Sync::syncOptionToDashboard(self::OPTION_NAME);
46 return $value;
47 });
48 }
49
50 /**
51 * Add setting.
52 *
53 * @since 4.0.0
54 * @since 6.0.0 Make static.
55 *
56 * @return void
57 */
58 public static function addSetting()
59 {
60 register_setting(
61 'beyondwords_player_settings',
62 self::OPTION_NAME,
63 [
64 'default' => PlayerUI::ENABLED,
65 ]
66 );
67
68 add_settings_field(
69 'beyondwords-player-ui',
70 __('Player UI', 'speechkit'),
71 [self::class, 'render'],
72 'beyondwords_player',
73 'player'
74 );
75 }
76
77 /**
78 * Render setting field.
79 *
80 * @since 4.0.0
81 * @since 6.0.0 Make static.
82 *
83 * @return void
84 **/
85 public static function render()
86 {
87 $currentUi = get_option(self::OPTION_NAME, PlayerUI::ENABLED);
88 $playerUIs = PlayerUI::getAllPlayerUIs();
89 ?>
90 <div class="beyondwords-setting__player--player-ui">
91 <select name="<?php echo esc_attr(self::OPTION_NAME) ?>">
92 <?php
93 foreach ($playerUIs as $value => $label) {
94 printf(
95 '<option value="%s" %s>%s</option>',
96 esc_attr($value),
97 selected($value, $currentUi),
98 esc_html($label)
99 );
100 }
101 ?>
102 </select>
103 </div>
104 <p class="description">
105 <?php
106 printf(
107 /* translators: %s is replaced with the "headless mode" link */
108 esc_html__('Enable or disable the player, or set it to %s.', 'speechkit'),
109 sprintf(
110 '<a href="https://github.com/beyondwords-io/player/blob/gh-pages/doc/building-your-own-ui.md" target="_blank" rel="nofollow">%s</a>', // phpcs:ignore Generic.Files.LineLength.TooLong
111 esc_html__('headless mode', 'speechkit')
112 )
113 );
114 ?>
115 </p>
116 <?php
117 }
118
119 /**
120 * Get all Player UIs.
121 *
122 * @since 4.0.0
123 *
124 * @static
125 *
126 * @return string[] Associative array of Player UIs and labels.
127 **/
128 public static function getAllPlayerUIs()
129 {
130 return [
131 PlayerUI::ENABLED => __('Enabled', 'speechkit'),
132 PlayerUI::HEADLESS => __('Headless', 'speechkit'),
133 PlayerUI::DISABLED => __('Disabled', 'speechkit'),
134 ];
135 }
136 }
137