Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
8.82% |
3 / 34 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
TitleVoiceSpeakingRate | |
8.82% |
3 / 34 |
|
0.00% |
0 / 3 |
9.82 | |
0.00% |
0 / 1 |
init | |
60.00% |
3 / 5 |
|
0.00% |
0 / 1 |
1.06 | |||
addSetting | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
2 | |||
render | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | /** |
6 | * Setting: Title voice speaking rate |
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\SpeakingRate; |
14 | |
15 | use Beyondwords\Wordpress\Component\Settings\Sync; |
16 | |
17 | /** |
18 | * TitleVoiceSpeakingRate |
19 | * |
20 | * @since 5.0.0 |
21 | */ |
22 | class TitleVoiceSpeakingRate |
23 | { |
24 | /** |
25 | * Option name. |
26 | * |
27 | * @since 5.0.0 |
28 | */ |
29 | public const OPTION_NAME = 'beyondwords_project_title_voice_speaking_rate'; |
30 | |
31 | /** |
32 | * Constructor |
33 | * |
34 | * @since 5.0.0 |
35 | */ |
36 | public function init() |
37 | { |
38 | add_action('admin_init', array($this, 'addSetting')); |
39 | add_action('pre_update_option_' . self::OPTION_NAME, function ($value) { |
40 | Sync::syncOptionToDashboard(self::OPTION_NAME); |
41 | return $value; |
42 | }); |
43 | } |
44 | |
45 | /** |
46 | * Add setting. |
47 | * |
48 | * @since 5.0.0 |
49 | * |
50 | * @return void |
51 | */ |
52 | public function addSetting() |
53 | { |
54 | register_setting( |
55 | 'beyondwords_voices_settings', |
56 | self::OPTION_NAME, |
57 | [ |
58 | 'type' => 'integer', |
59 | 'default' => 100, |
60 | ] |
61 | ); |
62 | |
63 | add_settings_field( |
64 | 'beyondwords-title-speaking-rate', |
65 | __('Title voice speaking rate', '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 | ?> |
83 | <div class="beyondwords-setting__title-speaking-rate"> |
84 | <input |
85 | type="range" |
86 | id="<?php echo esc_attr(self::OPTION_NAME) ?>" |
87 | name="<?php echo esc_attr(self::OPTION_NAME) ?>" |
88 | class="beyondwords_speaking_rate" |
89 | min="50" |
90 | max="200" |
91 | step="1" |
92 | value="<?php echo esc_attr($current); ?>" |
93 | oninput="this.nextElementSibling.value = `${this.value}%`" |
94 | onload="this.nextElementSibling.value = `${this.value}%`" |
95 | /> |
96 | <output><?php echo esc_html($current); ?>%</output> |
97 | </div> |
98 | <p class="description"> |
99 | <?php |
100 | esc_html_e( |
101 | 'Choose the default speaking rate for your title voice.', |
102 | 'speechkit' |
103 | ); |
104 | ?> |
105 | </p> |
106 | <?php |
107 | } |
108 | } |