-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathFixesPage.php
More file actions
232 lines (201 loc) · 5.86 KB
/
Copy pathFixesPage.php
File metadata and controls
232 lines (201 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
/**
* Admin page that holds the list of fix options.
*
* @package Accessibility_Checker
*/
namespace EqualizeDigital\AccessibilityChecker\Admin\AdminPage;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Registers the Fixes page and it's settings.
*
* Sections and settings are passed through filters so that other plugins can add their own.
*
* @since 1.16.0
*/
class FixesPage implements PageInterface {
use FixesSettingType\Checkbox;
use FixesSettingType\Text;
/**
* The capability required to access the settings page.
*
* @var string
*/
private $settings_capability;
const PAGE_TAB_SLUG = 'fixes';
/**
* The settings page slug which all sections, settings and fields are registered to.
*
* @var string
*/
const SETTINGS_SLUG = 'edac_settings_fixes';
/**
* Constructor.
*
* @param string $settings_capability The capability required to access the settings page.
*/
public function __construct( $settings_capability ) {
$this->settings_capability = $settings_capability;
}
/**
* Add the settings sections and fields and setup it's tabs and filter in for the content.
*
* @return void
*/
public function add_page() {
$this->register_settings_sections();
$this->register_fields_and_settings();
add_filter( 'edac_filter_admin_scripts_slugs', [ $this, 'add_slug_to_admin_scripts' ] );
add_filter( 'edac_filter_remove_admin_notices_screens', [ $this, 'add_slug_to_admin_notices' ] );
add_filter( 'edac_filter_settings_tab_items', [ $this, 'add_fixes_tab' ] );
add_action( 'edac_settings_tab_content', [ $this, 'add_fixes_tab_content' ], 11, 1 );
}
/**
* Add fixes tab to settings page.
*
* @param array $settings_tab_items arrray of tab items.
* @return array
*/
public function add_fixes_tab( $settings_tab_items ) {
$scan_tab = [
'slug' => 'fixes',
'label' => __( 'Fixes', 'accessibility-checker' ),
'order' => 2,
];
array_push( $settings_tab_items, $scan_tab );
return $settings_tab_items;
}
/**
* Licence fixes tab content to settings page.
*
* @param string $tab name of tab.
* @return void
*/
public function add_fixes_tab_content( $tab ) {
if ( 'fixes' === $tab ) {
include EDAC_PLUGIN_DIR . '/partials/admin-page/fixes-page.php';
}
}
/**
* Add the fixes slug to the admin scripts.
*
* @param array $slugs The slugs that are already added.
* @return array
*/
public function add_slug_to_admin_scripts( $slugs ) {
$slugs[] = 'accessibility_checker_' . self::PAGE_TAB_SLUG;
return $slugs;
}
/**
* Add the fixes slug to the admin notices.
*
* @param array $slugs The slugs that are already added.
* @return array
*/
public function add_slug_to_admin_notices( $slugs ) {
$slugs[] = 'accessibility-checker_page_accessibility_checker_' . self::PAGE_TAB_SLUG;
return $slugs;
}
/**
* Render the page.
*
* @return void
*/
public function render_page() {
include_once EDAC_PLUGIN_DIR . 'partials/admin-page/fixes-page.php';
}
/**
* Register the settings sections for this options page.
*
* Sections are passed through a filter so that other plugins can add their own.
*
* @return void
*/
public function register_settings_sections() {
/**
* Filter the sections that are registered for the fixes settings page.
*
* @since 1.16.0
*
* @param array $sections The sections that are to be registered for the fixes settings page. Must have the id as the key and an array with a title and callback.
*/
$sections = apply_filters(
'edac_filter_fixes_settings_sections',
[
'edac_fixes_general' => [
'title' => __( 'General Fixes', 'accessibility-checker' ),
'callback' => [ $this, 'fixes_section_general_cb' ],
],
]
);
if ( ! is_array( $sections ) ) {
$sections = [];
}
foreach ( $sections as $section_id => $section ) {
if ( ! is_string( $section_id ) || ! isset( $section['title'], $section['callback'] ) ) {
continue;
}
// The callback must be callable otherwise it will throw an error.
if ( ! is_callable( $section['callback'] ) ) {
continue;
}
add_settings_section(
$section_id,
$section['title'],
$section['callback'],
self::SETTINGS_SLUG,
);
}
}
/**
* Register the settings fields and settings for this options page.
*
* It passed through a filter so that other plugins can add their own settings.
*
* @return void
*/
public function register_fields_and_settings() {
/**
* Filter the fields that are registered for the fixes settings page.
*
* @since 1.16.0
*
* @param array $fields The fields that are to be registered for the fixes settings page.
*/
$fields = apply_filters( 'edac_filter_fixes_settings_fields', [] );
foreach ( $fields as $field_id => $field ) {
$field_type = $field['type'] ?? 'checkbox';
$sanitizer = $field['sanitize_callback'] ?? [ $this, 'sanitize_checkbox' ];
$is_upsell = $field['upsell'] ?? false;
add_settings_field(
$field_id,
$field['label'],
$field['callback'] ?? [ $this, $field_type ],
self::SETTINGS_SLUG,
$field['section'] ?? 'edac_fixes_general',
[
'name' => $field_id,
'labelledby' => $field_id,
'description' => $field['description'] ?? '',
'condition' => $field['condition'] ?? '',
'required_when' => $field['required_when'] ?? '',
'default' => $field['default'] ?? '',
'upsell' => $is_upsell,
'help_id' => $field['help_id'] ?? '',
'label' => $field['label'] ?? '',
]
);
register_setting( self::SETTINGS_SLUG, $field_id, $sanitizer );
}
}
/**
* Callback for the general settings section that renders a description for it.
*
* @return void
*/
public function fixes_section_general_cb() {
echo '<p>' . esc_html__( 'These fixes help improve accessibility by modifying HTML elements and behaviors on your site.', 'accessibility-checker' ) . '</p>';
}
}