-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathPreventLinksOpeningNewWindowFix.php
More file actions
108 lines (95 loc) · 2.26 KB
/
Copy pathPreventLinksOpeningNewWindowFix.php
File metadata and controls
108 lines (95 loc) · 2.26 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
<?php
/**
* Prevents links from opening in new windows.
*
* @package accessibility-checker
*/
namespace EqualizeDigital\AccessibilityChecker\Fixes\Fix;
use EqualizeDigital\AccessibilityChecker\Fixes\FixInterface;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Prevents links from opening in new windows.
*
* @since 1.16.0
*/
class PreventLinksOpeningNewWindowFix implements FixInterface {
/**
* The slug of the fix.
*
* @return string
*/
public static function get_slug(): string {
return 'prevent_links_opening_new_windows';
}
/**
* The nicename for the fix.
*
* @return string
*/
public static function get_nicename(): string {
return __( 'Prevent Links Opening New Windows', 'accessibility-checker' );
}
/**
* The type of the fix.
*
* @return string
*/
public static function get_type(): string {
return 'frontend';
}
/**
* Registers everything needed for the fix.
*
* @return void
*/
public function register(): void {
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__( 'Block Links Opening New Windows', 'accessibility-checker' ),
'type' => 'checkbox',
'labelledby' => 'prevent_links_opening_in_new_windows',
'description' => sprintf(
// translators: %1%s: A <code> tag containing target="_blank".
esc_html__( 'Prevent links from opening in a new window or tab by removing %1$s.', 'accessibility-checker' ),
'<code>target="_blank"</code>'
),
'fix_slug' => $this->get_slug(),
'group_name' => $this->get_nicename(),
'help_id' => 8493,
];
return $fields;
}
/**
* Run the fix for adding the comment and search form labels.
*
* @return void
*/
public function run(): void {
if ( ! get_option( 'edac_fix_' . $this->get_slug(), false ) ) {
return;
}
add_filter(
'edac_filter_frontend_fixes_data',
function ( $data ) {
$data[ $this->get_slug() ] = [
'enabled' => true,
];
return $data;
}
);
}
}