Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
10.53% |
4 / 38 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
AutoPublish | |
10.53% |
4 / 38 |
|
0.00% |
0 / 3 |
9.45 | |
0.00% |
0 / 1 |
init | |
66.67% |
4 / 6 |
|
0.00% |
0 / 1 |
1.04 | |||
addSetting | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
render | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | /** |
6 | * Setting: Auto-publish |
7 | * |
8 | * @package Beyondwords\Wordpress |
9 | * @author Stuart McAlpine <stu@beyondwords.io> |
10 | * @since 5.1.0 |
11 | */ |
12 | |
13 | namespace Beyondwords\Wordpress\Component\Settings\Fields\AutoPublish; |
14 | |
15 | use Beyondwords\Wordpress\Component\Settings\Sync; |
16 | |
17 | /** |
18 | * AutoPublish |
19 | * |
20 | * @since 5.1.0 |
21 | */ |
22 | class AutoPublish |
23 | { |
24 | /** |
25 | * Default value. |
26 | * |
27 | * @var string |
28 | */ |
29 | public const DEFAULT_VALUE = true; |
30 | |
31 | /** |
32 | * Option name. |
33 | * |
34 | * @var string |
35 | */ |
36 | public const OPTION_NAME = 'beyondwords_project_auto_publish_enabled'; |
37 | |
38 | /** |
39 | * Init. |
40 | * |
41 | * @since 5.1.0 |
42 | */ |
43 | public function init() |
44 | { |
45 | add_action('admin_init', array($this, 'addSetting')); |
46 | add_action('pre_update_option_' . self::OPTION_NAME, function ($value) { |
47 | Sync::syncOptionToDashboard(self::OPTION_NAME); |
48 | return $value; |
49 | }); |
50 | add_filter('option_' . self::OPTION_NAME, 'rest_sanitize_boolean'); |
51 | } |
52 | |
53 | /** |
54 | * Init setting. |
55 | * |
56 | * @since 5.1.0 |
57 | * |
58 | * @return void |
59 | */ |
60 | public function addSetting() |
61 | { |
62 | register_setting( |
63 | 'beyondwords_content_settings', |
64 | self::OPTION_NAME, |
65 | [ |
66 | 'type' => 'boolean', |
67 | 'sanitize_callback' => 'rest_sanitize_boolean', |
68 | 'default' => self::DEFAULT_VALUE, |
69 | ] |
70 | ); |
71 | |
72 | add_settings_field( |
73 | 'beyondwords-auto-publish', |
74 | __('Auto-publish', 'speechkit'), |
75 | array($this, 'render'), |
76 | 'beyondwords_content', |
77 | 'content' |
78 | ); |
79 | } |
80 | |
81 | /** |
82 | * Render setting field. |
83 | * |
84 | * @since 5.1.0 |
85 | * |
86 | * @return void |
87 | **/ |
88 | public function render() |
89 | { |
90 | $value = get_option(self::OPTION_NAME); |
91 | ?> |
92 | <div> |
93 | <label> |
94 | <input type="hidden" name="<?php echo esc_attr(self::OPTION_NAME); ?>" value="" /> |
95 | <input |
96 | type="checkbox" |
97 | id="<?php echo esc_attr(self::OPTION_NAME); ?>" |
98 | name="<?php echo esc_attr(self::OPTION_NAME); ?>" |
99 | value="1" |
100 | <?php checked($value); ?> |
101 | /> |
102 | <?php |
103 | esc_html_e( |
104 | 'When auto-publish is disabled all audio content created in WordPress will need to be manually published in the BeyondWords dashboard', // phpcs:ignore Generic.Files.LineLength.TooLong |
105 | 'speechkit' |
106 | ); |
107 | ?> |
108 | </label> |
109 | </div> |
110 | <?php |
111 | } |
112 | } |