Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
11.54% |
3 / 26 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
CallToAction | |
11.54% |
3 / 26 |
|
0.00% |
0 / 3 |
9.23 | |
0.00% |
0 / 1 |
init | |
60.00% |
3 / 5 |
|
0.00% |
0 / 1 |
1.06 | |||
addSetting | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 | |||
render | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(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 | |
13 | namespace Beyondwords\Wordpress\Component\Settings\Fields\CallToAction; |
14 | |
15 | use Beyondwords\Wordpress\Component\Settings\Sync; |
16 | |
17 | /** |
18 | * CallToAction |
19 | * |
20 | * @since 5.0.0 |
21 | */ |
22 | class 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 | */ |
36 | public function init() |
37 | { |
38 | add_action('admin_init', array($this, 'addSetting')); |
39 | add_action('pre_update_option_' . self::OPTION_NAME, function ($value) { |
40 | Sync::syncOptionToDashboard(self::OPTION_NAME); |
41 | return $value; |
42 | }); |
43 | } |
44 | |
45 | /** |
46 | * Init setting. |
47 | * |
48 | * @since 5.0.0 |
49 | * |
50 | * @return void |
51 | */ |
52 | public function addSetting() |
53 | { |
54 | register_setting( |
55 | 'beyondwords_player_settings', |
56 | self::OPTION_NAME, |
57 | [ |
58 | 'default' => '', |
59 | ] |
60 | ); |
61 | |
62 | add_settings_field( |
63 | 'beyondwords-player-call-to-action', |
64 | __('Call-to-action', 'speechkit'), |
65 | array($this, 'render'), |
66 | 'beyondwords_player', |
67 | 'styling' |
68 | ); |
69 | } |
70 | |
71 | /** |
72 | * Render setting field. |
73 | * |
74 | * @since 5.0.0 |
75 | * |
76 | * @return void |
77 | **/ |
78 | public function render() |
79 | { |
80 | $option = get_option(self::OPTION_NAME); |
81 | ?> |
82 | <div class="beyondwords-setting__player beyondwords-setting__player--call-to-action"> |
83 | <input |
84 | type="text" |
85 | name="<?php echo esc_attr(self::OPTION_NAME) ?>" |
86 | placeholder="<?php esc_attr_e('Listen to this article', 'speechkit'); ?>" |
87 | value="<?php echo esc_attr($option); ?>" |
88 | size="50" |
89 | /> |
90 | </div> |
91 | <?php |
92 | } |
93 | } |