PluginProbe
BeyondWords – AI audio for publishers / 6.3.0
BeyondWords – AI audio for publishers v6.3.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 4.7.0 All 43 releases
speechkit / src / Component / Settings / Fields / WidgetStyle / WidgetStyle.php

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

151 lines 3.8 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: Widget style
7 *
8 * @package Beyondwords\Wordpress
9 * @author Stuart McAlpine <stu@beyondwords.io>
10 * @since 5.0.0
11 */
12
13 namespace Beyondwords\Wordpress\Component\Settings\Fields\WidgetStyle;
14
15 use Beyondwords\Wordpress\Component\Settings\Sync;
16
17 /**
18 * WidgetStyle
19 *
20 * @since 5.0.0
21 */
22 defined('ABSPATH') || exit;
23
24 class WidgetStyle
25 {
26 /**
27 * Option name.
28 *
29 * @since 5.0.0
30 */
31 public const OPTION_NAME = 'beyondwords_player_widget_style';
32
33 /**
34 * Constructor
35 *
36 * @since 5.0.0
37 * @since 6.0.0 Make static.
38 */
39 public static function init()
40 {
41 add_action('admin_init', [self::class, 'addSetting']);
42 add_action('pre_update_option_' . self::OPTION_NAME, function ($value) {
43 Sync::syncOptionToDashboard(self::OPTION_NAME);
44 return $value;
45 });
46 }
47
48 /**
49 * Add setting.
50 *
51 * @since 4.5.0
52 * @since 6.0.0 Make static.
53 *
54 * @return void
55 */
56 public static function addSetting()
57 {
58 register_setting(
59 'beyondwords_player_settings',
60 self::OPTION_NAME,
61 [
62 'default' => '',
63 ]
64 );
65
66 add_settings_field(
67 'beyondwords-widget-style',
68 __('Widget style', 'speechkit'),
69 [self::class, 'render'],
70 'beyondwords_player',
71 'widget'
72 );
73 }
74
75 /**
76 * Render setting field.
77 *
78 * @since 5.0.0
79 * @since 6.0.0 Make static.
80 *
81 * @return void
82 **/
83 public static function render()
84 {
85 $current = get_option(self::OPTION_NAME);
86 $options = self::getOptions();
87 ?>
88 <div class="beyondwords-setting__player beyondwords-setting__widget-style">
89 <select name="<?php echo esc_attr(self::OPTION_NAME) ?>">
90 <?php
91 foreach ($options as $option) {
92 printf(
93 '<option value="%s" %s>%s</option>',
94 esc_attr($option['value']),
95 selected($option['value'], $current),
96 esc_html($option['label'])
97 );
98 }
99 ?>
100 </select>
101 <p class="description">
102 <?php
103 printf(
104 /* translators: %s is replaced with the "widgetStyle setting" link */
105 esc_html__('The style of widget to display at the bottom of the page once the user scrolls past the inline player. See %s.', 'speechkit'), // phpcs:ignore Generic.Files.LineLength.TooLong
106 sprintf(
107 '<a href="https://github.com/beyondwords-io/player/blob/main/doc/player-settings.md" target="_blank" rel="nofollow">%s</a>', // phpcs:ignore Generic.Files.LineLength.TooLong
108 esc_html__('widgetStyle setting', 'speechkit')
109 )
110 );
111 ?>
112 </p>
113 </div>
114 <?php
115 }
116
117 /**
118 * Get all options for the current component.
119 *
120 * @since 5.0.0
121 * @since 6.0.0 Make static.
122 *
123 * @return string[] Associative array of options.
124 **/
125 public static function getOptions()
126 {
127 return [
128 [
129 'value' => 'standard',
130 'label' => __('Standard', 'speechkit'),
131 ],
132 [
133 'value' => 'none',
134 'label' => __('None', 'speechkit'),
135 ],
136 [
137 'value' => 'small',
138 'label' => __('Small', 'speechkit'),
139 ],
140 [
141 'value' => 'large',
142 'label' => __('Large', 'speechkit'),
143 ],
144 [
145 'value' => 'video',
146 'label' => __('Video', 'speechkit'),
147 ],
148 ];
149 }
150 }
151