Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
11.76% |
4 / 34 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
PlaybackFromSegments | |
11.76% |
4 / 34 |
|
0.00% |
0 / 3 |
9.18 | |
0.00% |
0 / 1 |
init | |
66.67% |
4 / 6 |
|
0.00% |
0 / 1 |
1.04 | |||
addSetting | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
render | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | /** |
6 | * Setting: Text highlighting |
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\PlaybackFromSegments; |
14 | |
15 | use Beyondwords\Wordpress\Component\Settings\Sync; |
16 | |
17 | /** |
18 | * PlaybackFromSegments |
19 | * |
20 | * @since 5.0.0 |
21 | */ |
22 | class PlaybackFromSegments |
23 | { |
24 | /** |
25 | * Default value. |
26 | * |
27 | * @var string |
28 | */ |
29 | public const DEFAULT_VALUE = false; |
30 | |
31 | /** |
32 | * Option name. |
33 | * |
34 | * @var string |
35 | */ |
36 | public const OPTION_NAME = 'beyondwords_player_clickable_sections'; |
37 | |
38 | /** |
39 | * Init. |
40 | * |
41 | * @since 5.0.0 |
42 | */ |
43 | public function init() |
44 | { |
45 | add_action('admin_init', array($this, 'addSetting')); |
46 | add_action('pre_update_option_' . self::OPTION_NAME, function ($value) { |
47 | Sync::syncOptionToDashboard(self::OPTION_NAME); |
48 | return $value; |
49 | }); |
50 | add_filter('option_' . self::OPTION_NAME, 'rest_sanitize_boolean'); |
51 | } |
52 | |
53 | /** |
54 | * Init setting. |
55 | * |
56 | * @since 5.0.0 |
57 | * |
58 | * @return void |
59 | */ |
60 | public function addSetting() |
61 | { |
62 | register_setting( |
63 | 'beyondwords_player_settings', |
64 | self::OPTION_NAME, |
65 | [ |
66 | 'type' => 'boolean', |
67 | 'sanitize_callback' => 'rest_sanitize_boolean', |
68 | 'default' => self::DEFAULT_VALUE, |
69 | ] |
70 | ); |
71 | |
72 | add_settings_field( |
73 | 'beyondwords-playback-from-segments', |
74 | __('Playback from segments', 'speechkit'), |
75 | array($this, 'render'), |
76 | 'beyondwords_player', |
77 | 'styling' |
78 | ); |
79 | } |
80 | |
81 | /** |
82 | * Render setting field. |
83 | * |
84 | * @since 5.0.0 |
85 | * |
86 | * @return void |
87 | **/ |
88 | public function render() |
89 | { |
90 | $value = get_option(self::OPTION_NAME); |
91 | ?> |
92 | <div class="beyondwords-setting__player beyondwords-setting__player-playback-from-segments"> |
93 | <label> |
94 | <input type="hidden" name="<?php echo esc_attr(self::OPTION_NAME) ?>" value="" /> |
95 | <input |
96 | type="checkbox" |
97 | id="<?php echo esc_attr(self::OPTION_NAME) ?>" |
98 | name="<?php echo esc_attr(self::OPTION_NAME) ?>" |
99 | value="1" |
100 | <?php checked($value); ?> |
101 | /> |
102 | <?php esc_html_e('Allow readers to listen to a paragraph by clicking or tapping on it', 'speechkit'); ?> |
103 | </label> |
104 | </div> |
105 | <?php |
106 | } |
107 | } |