Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.31% covered (success)
92.31%
24 / 26
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
CallToAction
92.31% covered (success)
92.31%
24 / 26
66.67% covered (warning)
66.67%
2 / 3
3.00
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
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
1
 render
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * Setting: Call to action
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\CallToAction;
14
15use Beyondwords\Wordpress\Component\Settings\Sync;
16
17/**
18 * CallToAction
19 *
20 * @since 5.0.0
21 */
22class CallToAction
23{
24    /**
25     * Option name.
26     *
27     * @since 5.0.0
28     */
29    public const OPTION_NAME = 'beyondwords_player_call_to_action';
30
31    /**
32     * Init.
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     * Init 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_player_settings',
58            self::OPTION_NAME,
59            [
60                'default' => '',
61            ]
62        );
63
64        add_settings_field(
65            'beyondwords-player-call-to-action',
66            __('Call-to-action', 'speechkit'),
67            [self::class, 'render'],
68            'beyondwords_player',
69            'styling'
70        );
71    }
72
73    /**
74     * Render setting field.
75     *
76     * @since 5.0.0
77     * @since 6.0.0 Make static.
78     *
79     * @return void
80     **/
81    public static function render()
82    {
83        $option = get_option(self::OPTION_NAME);
84        ?>
85        <div class="beyondwords-setting__player beyondwords-setting__player--call-to-action">
86            <input
87                type="text"
88                name="<?php echo esc_attr(self::OPTION_NAME) ?>"
89                placeholder="<?php esc_attr_e('Listen to this article', 'speechkit'); ?>"
90                value="<?php echo esc_attr($option); ?>"
91                size="50"
92            />
93        </div>
94        <?php
95    }
96}