PluginProbe
BeyondWords – AI audio for publishers / 4.6.1
BeyondWords – AI audio for publishers v4.6.1
7.2.0 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 All 44 releases
speechkit / src / Component / Settings / PlayerUI / PlayerUI.php

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

164 lines 3.9 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 <[email protected]>
10 * @since 4.0.0
11 */
12
13 namespace Beyondwords\Wordpress\Component\Settings\PlayerUI;
14
15 use Beyondwords\Wordpress\Component\Settings\SettingsUtils;
16
17 /**
18 * PlayerUI setup
19 *
20 * @since 4.0.0
21 */
22 class PlayerUI
23 {
24 public const ENABLED = 'enabled';
25
26 public const HEADLESS = 'headless';
27
28 public const DISABLED = 'disabled';
29
30 /**
31 * Init.
32 *
33 * @since 4.0.0
34 */
35 public function init()
36 {
37 add_action('admin_init', array($this, 'registerSetting'));
38 add_action('admin_init', array($this, 'addSettingsField'));
39 add_action('admin_enqueue_scripts', array($this, 'enqueueScripts'));
40 }
41
42 /**
43 * Register setting.
44 *
45 * @since 4.0.0
46 *
47 * @return void
48 */
49 public function registerSetting()
50 {
51 if (! SettingsUtils::hasApiSettings()) {
52 return;
53 }
54
55 register_setting(
56 'beyondwords',
57 'beyondwords_player_ui',
58 [
59 'default' => PlayerUI::ENABLED,
60 ]
61 );
62 }
63
64 /**
65 * Add settings field.
66 *
67 * @since 4.0.0
68 *
69 * @return void
70 */
71 public function addSettingsField()
72 {
73 add_settings_field(
74 'beyondwords-player-ui',
75 __('Player UI', 'speechkit'),
76 array($this, 'render'),
77 'beyondwords',
78 'player'
79 );
80 }
81
82 /**
83 * Render setting field.
84 *
85 * @since 4.0.0
86 *
87 * @return void
88 **/
89 public function render()
90 {
91 $currentUi = get_option('beyondwords_player_ui', PlayerUI::ENABLED);
92 $playerUIs = PlayerUI::getAllPlayerUIs();
93
94 ?>
95 <div class="beyondwords-setting--player--player-ui">
96 <select name="beyondwords_player_ui">
97 <?php
98 foreach ($playerUIs as $value => $label) {
99 printf(
100 '<option value="%s" %s>%s</option>',
101 esc_attr($value),
102 selected($value, $currentUi),
103 esc_html($label)
104 );
105 }
106 ?>
107 </select>
108 </div>
109 <p class="description">
110 <?php
111 printf(
112 /* translators: %s is replaced with the "headless mode" link */
113 esc_html__('Enable or disable the player, or set it to %s.', 'speechkit'),
114 sprintf(
115 '<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
116 esc_html__('headless mode', 'speechkit')
117 )
118 );
119 ?>
120 </p>
121 <?php
122 }
123
124 /**
125 * Get all Player UIs.
126 *
127 * @since 4.0.0
128 *
129 * @static
130 *
131 * @return string[] Associative array of Player UIs and labels.
132 **/
133 public static function getAllPlayerUIs()
134 {
135 return [
136 PlayerUI::ENABLED => __('Enabled', 'speechkit'),
137 PlayerUI::HEADLESS => __('Headless', 'speechkit'),
138 PlayerUI::DISABLED => __('Disabled', 'speechkit'),
139 ];
140 }
141
142 /**
143 * Register the component scripts.
144 *
145 * @since 3.0.0
146 *
147 * @param string $hook Page hook
148 *
149 * @return void
150 */
151 public function enqueueScripts($hook)
152 {
153 if ($hook === 'settings_page_beyondwords') {
154 wp_enqueue_script(
155 'beyondwords-settings--player-ui',
156 BEYONDWORDS__PLUGIN_URI . 'src/Component/Settings/PlayerUI/settings.js',
157 ['jquery', 'underscore'],
158 BEYONDWORDS__PLUGIN_VERSION,
159 true
160 );
161 }
162 }
163 }
164