Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
95.24% |
40 / 42 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| PlaybackControls | |
95.24% |
40 / 42 |
|
66.67% |
2 / 3 |
3 | |
0.00% |
0 / 1 |
| init | |
60.00% |
3 / 5 |
|
0.00% |
0 / 1 |
1.06 | |||
| addSetting | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
| render | |
100.00% |
23 / 23 |
|
100.00% |
1 / 1 |
1 | |||
| 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\PlaybackControls; |
| 14 | |
| 15 | use Beyondwords\Wordpress\Component\Settings\Sync; |
| 16 | |
| 17 | /** |
| 18 | * PlaybackControls |
| 19 | * |
| 20 | * @since 5.0.0 |
| 21 | */ |
| 22 | class PlaybackControls |
| 23 | { |
| 24 | /** |
| 25 | * Option name. |
| 26 | */ |
| 27 | public const OPTION_NAME = 'beyondwords_player_skip_button_style'; |
| 28 | |
| 29 | /** |
| 30 | * Player Settings docs URL. |
| 31 | * |
| 32 | * @var string |
| 33 | */ |
| 34 | public const PLAYER_SETTINGS_DOCS_URL = 'https://github.com/beyondwords-io/player/blob/main/doc/player-settings.md'; |
| 35 | |
| 36 | /** |
| 37 | * Init. |
| 38 | * |
| 39 | * @since 5.0.0 |
| 40 | * @since 6.0.0 Make static. |
| 41 | */ |
| 42 | public static function init() |
| 43 | { |
| 44 | add_action('admin_init', [self::class, 'addSetting']); |
| 45 | add_action('pre_update_option_' . self::OPTION_NAME, function ($value) { |
| 46 | Sync::syncOptionToDashboard(self::OPTION_NAME); |
| 47 | return $value; |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Init setting. |
| 53 | * |
| 54 | * @since 5.0.0 |
| 55 | * @since 6.0.0 Make static. |
| 56 | * |
| 57 | * @return void |
| 58 | */ |
| 59 | public static function addSetting() |
| 60 | { |
| 61 | register_setting( |
| 62 | 'beyondwords_player_settings', |
| 63 | self::OPTION_NAME, |
| 64 | [ |
| 65 | 'default' => '', |
| 66 | ] |
| 67 | ); |
| 68 | |
| 69 | add_settings_field( |
| 70 | 'beyondwords-player-skip-button-style', |
| 71 | __('Skip button style', 'speechkit'), |
| 72 | [self::class, 'render'], |
| 73 | 'beyondwords_player', |
| 74 | 'playback-controls' |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Render setting field. |
| 80 | * |
| 81 | * @since 5.0.0 |
| 82 | * @since 6.0.0 Make static. |
| 83 | * |
| 84 | * @return void |
| 85 | **/ |
| 86 | public static function render() |
| 87 | { |
| 88 | $current = get_option(self::OPTION_NAME); |
| 89 | ?> |
| 90 | <div class="beyondwords-setting__player-skip-button-style"> |
| 91 | <input |
| 92 | type="text" |
| 93 | name="<?php echo esc_attr(self::OPTION_NAME) ?>" |
| 94 | placeholder="auto" |
| 95 | value="<?php echo esc_attr($current); ?>" |
| 96 | size="20" |
| 97 | /> |
| 98 | <p class="description" style="max-width: 740px;"> |
| 99 | <?php |
| 100 | echo wp_kses_post(__('The style of skip buttons to show in the player.', 'speechkit')) . " "; |
| 101 | echo wp_kses_post(__('Possible values are <code>auto</code>, <code>segments</code>, <code>seconds</code> or <code>audios</code>.', 'speechkit')) . " "; // phpcs:ignore Generic.Files.LineLength.TooLong |
| 102 | echo wp_kses_post(__('You can specify the number of seconds to skip, e.g. <code>seconds-15</code> or <code>seconds-15-30</code>.', 'speechkit')) . " "; // phpcs:ignore Generic.Files.LineLength.TooLong |
| 103 | ?> |
| 104 | </p> |
| 105 | <p class="description" style="max-width: 740px;"> |
| 106 | <?php |
| 107 | printf( |
| 108 | /* translators: %s is replaced with the link to the Player Settings docs */ |
| 109 | esc_html__('Refer to the %s docs for more details.', 'speechkit'), |
| 110 | sprintf( |
| 111 | '<a href="%s" target="_blank" rel="nofollow">%s</a>', |
| 112 | esc_url(PlaybackControls::PLAYER_SETTINGS_DOCS_URL), |
| 113 | esc_html__('Player Settings', 'speechkit') |
| 114 | ) |
| 115 | ); |
| 116 | ?> |
| 117 | </p> |
| 118 | </div> |
| 119 | <?php |
| 120 | } |
| 121 | } |