PluginProbe
BeyondWords – AI audio for publishers / 4.2.4
BeyondWords – AI audio for publishers v4.2.4
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 / PlayerUI / PlayerUI.php

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

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