Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
6.82% |
3 / 44 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
BodyVoice | |
6.82% |
3 / 44 |
|
0.00% |
0 / 3 |
16.95 | |
0.00% |
0 / 1 |
init | |
60.00% |
3 / 5 |
|
0.00% |
0 / 1 |
1.06 | |||
addSetting | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 | |||
render | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | /** |
6 | * Setting: BodyVoice |
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\Voice; |
14 | |
15 | use Beyondwords\Wordpress\Component\Settings\Fields\Voice\Voice; |
16 | use Beyondwords\Wordpress\Component\Settings\Sync; |
17 | |
18 | /** |
19 | * BodyVoice |
20 | * |
21 | * @since 5.0.0 |
22 | */ |
23 | class BodyVoice extends Voice |
24 | { |
25 | /** |
26 | * Option name. |
27 | * |
28 | * @since 5.0.0 |
29 | */ |
30 | public const OPTION_NAME = 'beyondwords_project_body_voice_id'; |
31 | |
32 | /** |
33 | * Init. |
34 | * |
35 | * @since 5.0.0 |
36 | */ |
37 | public function init() |
38 | { |
39 | add_action('admin_init', array($this, 'addSetting')); |
40 | add_action('pre_update_option_' . self::OPTION_NAME, function ($value) { |
41 | Sync::syncOptionToDashboard(self::OPTION_NAME); |
42 | return $value; |
43 | }); |
44 | } |
45 | |
46 | /** |
47 | * Add setting. |
48 | * |
49 | * @since 4.5.0 |
50 | * |
51 | * @return void |
52 | */ |
53 | public function addSetting() |
54 | { |
55 | register_setting( |
56 | 'beyondwords_voices_settings', |
57 | self::OPTION_NAME, |
58 | [ |
59 | 'sanitize_callback' => 'absint', |
60 | ] |
61 | ); |
62 | |
63 | add_settings_field( |
64 | 'beyondwords-body-voice', |
65 | __('Body voice', 'speechkit'), |
66 | array($this, 'render'), |
67 | 'beyondwords_voices', |
68 | 'voices' |
69 | ); |
70 | } |
71 | |
72 | /** |
73 | * Render setting field. |
74 | * |
75 | * @since 5.0.0 |
76 | * |
77 | * @return void |
78 | **/ |
79 | public function render() |
80 | { |
81 | $current = get_option(self::OPTION_NAME); |
82 | $options = $this->getOptions(); |
83 | // phpcs:disable PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage |
84 | ?> |
85 | <div class="beyondwords-setting__body-voice"> |
86 | <select |
87 | id="<?php echo esc_attr(self::OPTION_NAME) ?>" |
88 | name="<?php echo esc_attr(self::OPTION_NAME) ?>" |
89 | class="beyondwords_project_voice" |
90 | style="width: 300px;" |
91 | > |
92 | <?php |
93 | foreach ($options as $option) { |
94 | printf( |
95 | '<option value="%s" data-language-code="%s" %s>%s</option>', |
96 | esc_attr($option['value']), |
97 | esc_attr($option['language_code']), |
98 | selected($option['value'], $current), |
99 | esc_html($option['label']) |
100 | ); |
101 | } |
102 | ?> |
103 | </select> |
104 | <img src="/wp-admin/images/spinner.gif" class="beyondwords-settings__loader" style="display:none;" /> |
105 | </div> |
106 | <p class="description"> |
107 | <?php |
108 | esc_html_e( |
109 | 'Choose the default voice for your article body sections.', |
110 | 'speechkit' |
111 | ); |
112 | ?> |
113 | </p> |
114 | <?php |
115 | // phpcs:enable PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage |
116 | } |
117 | } |