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 / WidgetPosition / WidgetPosition.php

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

135 lines 3.0 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 position
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\WidgetPosition;
14
15 use Beyondwords\Wordpress\Component\Settings\Sync;
16
17 /**
18 * WidgetPosition
19 *
20 * @since 5.0.0
21 */
22 defined('ABSPATH') || exit;
23
24 class WidgetPosition
25 {
26 /**
27 * Option name.
28 *
29 * @since 5.0.0
30 */
31 public const OPTION_NAME = 'beyondwords_player_widget_position';
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' => 'auto',
63 ]
64 );
65
66 add_settings_field(
67 'beyondwords-widget-position',
68 __('Widget position', '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-position">
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 </div>
102 <?php
103 }
104
105 /**
106 * Get all options for the current component.
107 *
108 * @since 5.0.0
109 * @since 6.0.0 Make static.
110 *
111 * @return string[] Associative array of options.
112 **/
113 public static function getOptions()
114 {
115 return [
116 [
117 'value' => 'auto',
118 'label' => __('Auto (default)', 'speechkit'),
119 ],
120 [
121 'value' => 'center',
122 'label' => __('Center', 'speechkit'),
123 ],
124 [
125 'value' => 'left',
126 'label' => __('Left', 'speechkit'),
127 ],
128 [
129 'value' => 'right',
130 'label' => __('Right', 'speechkit'),
131 ],
132 ];
133 }
134 }
135