-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathAddNewWindowWarningFix.php
More file actions
184 lines (162 loc) · 4.58 KB
/
Copy pathAddNewWindowWarningFix.php
File metadata and controls
184 lines (162 loc) · 4.58 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
<?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 AddNewWindowWarningFix implements FixInterface {
/**
* The slug of the fix.
*
* @return string
*/
public static function get_slug(): string {
return 'new_window_warning';
}
/**
* The nicename for the fix.
*
* @return string
*/
public static function get_nicename(): string {
return __( 'Add warning when link opens new tab/window', '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__( 'Add Label To Links That Open A New Tab/Window', 'accessibility-checker' ),
'type' => 'checkbox',
'labelledby' => 'add_new_window_warning',
'description' => sprintf(
// translators: %1%s: A <code> tag containing target="_blank".
esc_html__( 'Add a label and icon to links with %1$s informing users they will open a new tab/window. %2$sNote: This setting will have no effect if the "Block Links Opening New Windows" fix is enabled.%3$s', 'accessibility-checker' ),
'<code>target="_blank"</code>',
'<br><strong>',
'</strong>'
),
'fix_slug' => $this->get_slug(),
'group_name' => $this->get_nicename(),
'help_id' => 9946,
];
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;
}
// unregister the anww script if it's present, this fix supercedes it.
if ( class_exists( '\ANWW' ) && defined( 'ANWW_VERSION' ) ) {
add_action(
'wp_enqueue_scripts',
function () {
wp_deregister_script( 'anww' );
wp_deregister_style( 'anww' );
},
PHP_INT_MAX
);
}
add_filter(
'edac_filter_frontend_fixes_data',
function ( $data ) {
$data[ $this->get_slug() ] = [
'enabled' => true,
'classPrefix' => 'edac-nww',
'localizedString' => __( 'opens a new window', 'accessibility-checker' ),
];
return $data;
}
);
add_action( 'wp_head', [ $this, 'add_styles' ] );
}
/**
* Add the styles for the new window warning.
*
* @return void
*/
public function add_styles() {
$font_url = EDAC_PLUGIN_URL . 'assets/fonts';
?>
<style id="edac-nww">
@font-face {
font-family: 'anww';
src: url('<?php echo esc_url( $font_url ); ?>/anww.eot?7msg3d');
src: url('<?php echo esc_url( $font_url ); ?>/anww.eot?7msg3d#iefix') format('embedded-opentype'),
url('<?php echo esc_url( $font_url ); ?>/anww.ttf?7msg3d') format('truetype'),
url('<?php echo esc_url( $font_url ); ?>/anww.woff?7msg3d') format('woff'),
url('<?php echo esc_url( $font_url ); ?>/anww.svg?7msg3d#anww') format('svg');
font-weight: normal;
font-style: normal;
font-display: block;
}
:root {
--edac-nww-font-base: 'anww', sans-serif;
--edac-nww-icon-size: 0.75em;
}
.anww-external-link-icon,
.edac-nww-external-link-icon {
font: normal normal normal 1em var(--edac-nww-font-base) !important;
speak: never;
text-transform: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.anww-external-link-icon:before,
.edac-nww-external-link-icon:before {
content: " \e900";
font-size: var(--edac-nww-icon-size);
}
.anww-external-link-icon.elementor-button-link-content:before,
.edac-nww-external-link-icon.elementor-button-link-content:before {
vertical-align: middle;
}
/* Modifier classes: add these to a container element to opt out of specific behaviors. */
.anww-no-icon .anww-external-link-icon,
.anww-no-icon .edac-nww-external-link-icon,
.edac-nww-no-icon .anww-external-link-icon,
.edac-nww-no-icon .edac-nww-external-link-icon {
display: none !important;
}
</style>
<?php
}
}