Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
7.14% covered (danger)
7.14%
3 / 42
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PlaybackControls
7.14% covered (danger)
7.14%
3 / 42
0.00% covered (danger)
0.00%
0 / 3
10.21
0.00% covered (danger)
0.00%
0 / 1
 init
60.00% covered (danger)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 1
1.06
 addSetting
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
 render
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(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
13namespace Beyondwords\Wordpress\Component\Settings\Fields\PlaybackControls;
14
15use Beyondwords\Wordpress\Component\Settings\Sync;
16
17/**
18 * PlaybackControls
19 *
20 * @since 5.0.0
21 */
22class 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     */
41    public function init()
42    {
43        add_action('admin_init', array($this, 'addSetting'));
44        add_action('pre_update_option_' . self::OPTION_NAME, function ($value) {
45            Sync::syncOptionToDashboard(self::OPTION_NAME);
46            return $value;
47        });
48    }
49
50    /**
51     * Init setting.
52     *
53     * @since 5.0.0
54     *
55     * @return void
56     */
57    public function addSetting()
58    {
59        register_setting(
60            'beyondwords_player_settings',
61            self::OPTION_NAME,
62            [
63                'default' => '',
64            ]
65        );
66
67        add_settings_field(
68            'beyondwords-player-skip-button-style',
69            __('Skip button style', 'speechkit'),
70            array($this, 'render'),
71            'beyondwords_player',
72            'playback-controls'
73        );
74    }
75
76    /**
77     * Render setting field.
78     *
79     * @since 5.0.0
80     *
81     * @return void
82     **/
83    public function render()
84    {
85        $current = get_option(self::OPTION_NAME);
86        ?>
87        <div class="beyondwords-setting__player-skip-button-style">
88            <input
89                type="text"
90                name="<?php echo esc_attr(self::OPTION_NAME) ?>"
91                placeholder="auto"
92                value="<?php echo esc_attr($current); ?>"
93                size="20"
94            />
95            <p class="description" style="max-width: 740px;">
96                <?php
97                echo wp_kses_post(__('The style of skip buttons to show in the player.', 'speechkit')) . " ";
98                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
99                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
100                ?>
101            </p>
102            <p class="description" style="max-width: 740px;">
103                <?php
104                printf(
105                    /* translators: %s is replaced with the link to the Player Settings docs */
106                    esc_html__('Refer to the %s docs for more details.', 'speechkit'),
107                    sprintf(
108                        '<a href="%s" target="_blank" rel="nofollow">%s</a>',
109                        esc_url(PlaybackControls::PLAYER_SETTINGS_DOCS_URL),
110                        esc_html__('Player Settings', 'speechkit')
111                    )
112                );
113                ?>
114            </p>
115        </div>
116        <?php
117    }
118}