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