-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathAddLabelToUnlabelledFormFieldsFix.php
More file actions
143 lines (125 loc) · 3.14 KB
/
Copy pathAddLabelToUnlabelledFormFieldsFix.php
File metadata and controls
143 lines (125 loc) · 3.14 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
<?php
/**
* Try label unlabelled form fields.
*
* @package accessibility-checker
*/
namespace EqualizeDigital\AccessibilityChecker\Fixes\Fix;
use EqualizeDigital\AccessibilityChecker\Fixes\FixInterface;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Try to add labels to unlabelled form fields.
*
* @since 1.16.0
*/
class AddLabelToUnlabelledFormFieldsFix implements FixInterface {
/**
* Whether the pro version is active.
*
* @var bool
*/
public $is_pro = false;
/**
* The slug of the fix.
*
* @return string
*/
public static function get_slug(): string {
return 'add_label_to_unlabelled_form_fields';
}
/**
* The nicename for the fix.
*
* @return string
*/
public static function get_nicename(): string {
return __( 'Add Labels to Unlabelled Form Fields', 'accessibility-checker' );
}
/**
* The fancyname for the fix.
*
* @return string
*/
public static function get_fancyname(): string {
return __( 'Label Form Fields', 'accessibility-checker' );
}
/**
* The type of the fix.
*
* @return string
*/
public static function get_type(): string {
return 'none';
}
/**
* Registers everything needed for the fix.
*
* @return void
*/
public function register(): void {
add_filter(
'edac_filter_fixes_settings_sections',
function ( $sections ) {
$sections[ $this->get_slug() ] = [
'title' => esc_html__( 'Label Form Fields', 'accessibility-checker' ),
'callback' => [ $this, $this->get_slug() . '_section_callback' ],
];
return $sections;
}
);
add_filter(
'edac_filter_fixes_settings_fields',
[ $this, 'get_fields_array' ],
);
}
/**
* Get the settings fields for the fix.
*
* @param array $fields The array of fields that are already registered, if any.
*
* @return array
*/
public function get_fields_array( array $fields = [] ): array {
$fields[ 'edac_fix_' . $this->get_slug() ] = [
'label' => esc_html__( 'Label Form Fields', 'accessibility-checker' ),
'type' => 'checkbox',
'labelledby' => $this->get_slug(),
'description' => esc_html__( 'Add labels to unlabelled form fields if field purpose can be determined.', 'accessibility-checker' ),
'section' => $this->get_slug(),
'upsell' => isset( $this->is_pro ) && $this->is_pro ? false : true,
'group_name' => $this->get_nicename(),
'fancy_name' => $this->get_fancyname(),
'fix_slug' => $this->get_slug(),
'help_id' => 8497,
];
return $fields;
}
/**
* Run the fix for adding the comment and search form labels.
*
* @return void
*/
public function run(): void {
// Intentionally left empty.
}
/**
* Callback for the fix settings section.
*
* @return void
*/
public function add_label_to_unlabelled_form_fields_section_callback() {
?>
<p>
<?php
printf(
// translators: %1$s: a CSS class name wrapped in a <code> tag.
esc_html__( 'Attempt to add labels to form fields that are missing them. Note: You may need to add custom styles targeting the %1$s class if adding labels affects your form layouts.', 'accessibility-checker' ),
'<code>.edac-generated-label</code>'
);
?>
</p>
<?php
}
}