Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.59% covered (success)
92.59%
25 / 27
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 */
22defined('ABSPATH') || exit;
23
24class CallToAction
25{
26    /**
27     * Option name.
28     *
29     * @since 5.0.0
30     */
31    public const OPTION_NAME = 'beyondwords_player_call_to_action';
32
33    /**
34     * Init.
35     *
36     * @since 5.0.0
37     * @since 6.0.0 Make static.
38     */
39    public static function init()
40    {
41        add_action('admin_init', [self::class, 'addSetting']);
42        add_action('pre_update_option_' . self::OPTION_NAME, function ($value) {
43            Sync::syncOptionToDashboard(self::OPTION_NAME);
44            return $value;
45        });
46    }
47
48    /**
49     * Init setting.
50     *
51     * @since 5.0.0
52     * @since 6.0.0 Make static.
53     *
54     * @return void
55     */
56    public static function addSetting()
57    {
58        register_setting(
59            'beyondwords_player_settings',
60            self::OPTION_NAME,
61            [
62                'default' => '',
63            ]
64        );
65
66        add_settings_field(
67            'beyondwords-player-call-to-action',
68            __('Call-to-action', 'speechkit'),
69            [self::class, 'render'],
70            'beyondwords_player',
71            'styling'
72        );
73    }
74
75    /**
76     * Render setting field.
77     *
78     * @since 5.0.0
79     * @since 6.0.0 Make static.
80     *
81     * @return void
82     **/
83    public static function render()
84    {
85        $option = get_option(self::OPTION_NAME);
86        ?>
87        <div class="beyondwords-setting__player beyondwords-setting__player--call-to-action">
88            <input
89                type="text"
90                name="<?php echo esc_attr(self::OPTION_NAME) ?>"
91                placeholder="<?php esc_attr_e('Listen to this article', 'speechkit'); ?>"
92                value="<?php echo esc_attr($option); ?>"
93                size="50"
94            />
95        </div>
96        <?php
97    }
98}