Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
35 / 35
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
TitleVoiceSpeakingRate
100.00% covered (success)
100.00%
34 / 34
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 init
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 addSetting
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
1
 render
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(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
13namespace Beyondwords\Wordpress\Component\Settings\Fields\SpeakingRate;
14
15use Beyondwords\Wordpress\Component\Settings\Sync;
16
17/**
18 * TitleVoiceSpeakingRate
19 *
20 * @since 5.0.0
21 */
22defined('ABSPATH') || exit;
23
24class TitleVoiceSpeakingRate
25{
26    /**
27     * Option name.
28     *
29     * @since 5.0.0
30     */
31    public const OPTION_NAME = 'beyondwords_project_title_voice_speaking_rate';
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 5.0.0
52     * @since 6.0.0 Make static.
53     *
54     * @return void
55     */
56    public static function addSetting()
57    {
58        register_setting(
59            'beyondwords_voices_settings',
60            self::OPTION_NAME,
61            [
62                'type'    => 'integer',
63                'default' => 100,
64            ]
65        );
66
67        add_settings_field(
68            'beyondwords-title-speaking-rate',
69            __('Title voice speaking rate', 'speechkit'),
70            [self::class, 'render'],
71            'beyondwords_voices',
72            'voices'
73        );
74    }
75
76    /**
77     * Render setting field.
78     *
79     * @since 5.0.0
80     * @since 6.0.0 Make static.
81     *
82     * @return void
83     **/
84    public static function render()
85    {
86        $current = get_option(self::OPTION_NAME);
87        ?>
88        <div class="beyondwords-setting__title-speaking-rate">
89            <input
90                type="range"
91                id="<?php echo esc_attr(self::OPTION_NAME) ?>"
92                name="<?php echo esc_attr(self::OPTION_NAME) ?>"
93                class="beyondwords_speaking_rate"
94                min="50"
95                max="200"
96                step="1"
97                value="<?php echo esc_attr($current); ?>"
98                oninput="this.nextElementSibling.value = `${this.value}%`"
99                onload="this.nextElementSibling.value = `${this.value}%`"
100            />
101            <output><?php echo esc_html($current); ?>%</output>
102        </div>
103        <p class="description">
104            <?php
105            esc_html_e(
106                'Choose the default speaking rate for your title voice.',
107                'speechkit'
108            );
109            ?>
110        </p>
111        <?php
112    }
113}