PluginProbe
WP Accessibility / trunk
WP Accessibility vtrunk
2.3.5 trunk 1.0.0 1.2.3 1.2.9 1.3.0 1.3.11 1.4.0 1.4.6 1.5.0 1.5.10 1.6.0 1.6.10 1.7.0 1.7.14 1.8.0 1.8.1 1.9.0 1.9.2 2.0.0 2.0.1 2.1.0 2.1.19 2.2.0 2.2.5 All 29 releases
wp-accessibility / wp-accessibility-admin.php

wp-accessibility-admin.php in WP Accessibility trunk, at wp-accessibility-admin.php

209 lines 11.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Output the WP Accessibility admin and author Settings.
4 *
5 * @category Settings
6 * @package WP Accessibility
7 * @author Joe Dolson
8 * @license GPLv2
9 * @link https://www.joedolson.com/wp-accessibility/
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 /**
17 * Update WP Accessibility admin & author settings.
18 *
19 * @return string Update confirmation message.
20 */
21 function wpa_update_admin_settings() {
22 wpa_check_version();
23 if ( ! empty( $_POST ) ) {
24 $nonce = $_REQUEST['_wpnonce'];
25 if ( ! wp_verify_nonce( $nonce, 'wpa-nonce' ) ) {
26 wp_die( 'WP Accessibility: Security check failed' );
27 }
28 if ( isset( $_POST['action'] ) && 'tools' === $_POST['action'] ) {
29 $wpa_search_alt = ( isset( $_POST['wpa_search_alt'] ) ) ? 'on' : '';
30 $wpa_diagnostics = ( isset( $_POST['wpa_diagnostics'] ) ) ? 'on' : '';
31 $wpa_disable_fullscreen = ( isset( $_POST['wpa_disable_fullscreen'] ) ) ? 'on' : '';
32 $wpa_enable_visibility = ( isset( $_POST['wpa_enable_visibility'] ) ) ? 'on' : '';
33 $wpa_disable_file_embed = ( isset( $_POST['wpa_disable_file_embed'] ) ) ? 'on' : '';
34 $wpa_allow_h1 = ( isset( $_POST['wpa_allow_h1'] ) ) ? 'on' : '';
35 $wpa_disable_logout = ( isset( $_POST['wpa_disable_logout'] ) ) ? 'on' : '';
36 $wpa_track_stats = ( isset( $_POST['wpa_track_stats'] ) ) ? sanitize_text_field( $_POST['wpa_track_stats'] ) : '';
37 update_option( 'wpa_search_alt', $wpa_search_alt );
38 update_option( 'wpa_diagnostics', $wpa_diagnostics );
39 update_option( 'wpa_disable_fullscreen', $wpa_disable_fullscreen );
40 update_option( 'wpa_enable_visibility', $wpa_enable_visibility );
41 update_option( 'wpa_disable_file_embed', $wpa_disable_file_embed );
42 update_option( 'wpa_allow_h1', $wpa_allow_h1 );
43 update_option( 'wpa_track_stats', $wpa_track_stats );
44 update_option( 'wpa_disable_logout', $wpa_disable_logout );
45 $message = __( 'Accessibility Tools Updated', 'wp-accessibility' );
46
47 return "<div class='notice notice-success'><p>" . $message . '</p></div>';
48 }
49 } else {
50 return;
51 }
52 }
53
54 /**
55 * Display settings admin page.
56 */
57 function wpa_admin_admin_settings() {
58 echo wpa_update_admin_settings();
59 ?>
60 <div class="wrap">
61 <h1><?php _e( 'WP Accessibility Features', 'wp-accessibility' ); ?></h1>
62 <p>
63 <?php esc_html_e( 'WP Accessibility contains many features that enhance the accessibility of your site. Enable these features to improve access for users with disabilities.', 'wp-accessibility' ); ?>
64 </p>
65 <div class="wpa-settings-wrapper">
66 <div id="wpa_settings_page" class="postbox-container">
67 <div class="metabox-holder">
68 <div class="ui-sortable meta-box-sortables">
69 <div class="postbox">
70 <h2 class="hndle"><?php _e( 'Testing & Admin Experience', 'wp-accessibility' ); ?></h2>
71
72 <div class="inside">
73 <p><?php _e( 'These change the admin experience or help with testing.', 'wp-accessibility' ); ?></p>
74 <hr>
75 <form method="post" action="<?php echo admin_url( 'admin.php?page=wp-accessibility-admin' ); ?>">
76 <p>
77 <input type="checkbox" id="wpa_search_alt" name="wpa_search_alt" <?php checked( get_option( 'wpa_search_alt' ), 'on' ); ?> aria-describedby="wpa_search_alt_note" />
78 <label for="wpa_search_alt"><?php _e( 'Include alt attribute in media library searches', 'wp-accessibility' ); ?></label> <em class="wpa-note" id="wpa_search_alt_note"><?php _e( '* May cause slow searches on large media libraries.', 'wp-accessibility' ); ?></em>
79 </p>
80 <p>
81 <input type="checkbox" id="wpa_disable_logout" name="wpa_disable_logout" <?php checked( get_option( 'wpa_disable_logout' ), 'on' ); ?> aria-describedby="wpa_logout_note" />
82 <label for="wpa_disable_logout"><?php _e( 'Disable top-level adminbar logout link', 'wp-accessibility' ); ?></label> <em class="wpa-note" id="wpa_logout_note"><?php _e( '* Accessibility problems accessing adminbar dropdowns were fixed in WordPress 6.5.', 'wp-accessibility' ); ?></em>
83 </p>
84 <p>
85 <input type="checkbox" id="wpa_disable_fullscreen" name="wpa_disable_fullscreen" <?php checked( get_option( 'wpa_disable_fullscreen' ), 'on' ); ?>/>
86 <label for="wpa_disable_fullscreen"><?php _e( 'Disable fullscreen block editor by default', 'wp-accessibility' ); ?></label>
87 </p>
88 <p>
89 <input type="checkbox" id="wpa_enable_visibility" name="wpa_enable_visibility" <?php checked( get_option( 'wpa_enable_visibility' ), 'on' ); ?>/>
90 <label for="wpa_enable_visibility"><?php _e( 'Make block boundaries visible on hover', 'wp-accessibility' ); ?></label>
91 </p>
92 <p>
93 <input type="checkbox" id="wpa_disable_file_embed" name="wpa_disable_file_embed" <?php checked( get_option( 'wpa_disable_file_embed' ), 'on' ); ?>/>
94 <label for="wpa_disable_file_embed"><?php _e( 'Disable embed behavior as default on file block', 'wp-accessibility' ); ?></label>
95 </p>
96 <p>
97 <input type="checkbox" id="wpa_allow_h1" name="wpa_allow_h1" <?php checked( get_option( 'wpa_allow_h1' ), 'on' ); ?>/>
98 <label for="wpa_allow_h1"><?php _e( 'Allow <code>h1</code> in the headings block', 'wp-accessibility' ); ?></label>
99 </p>
100 <p>
101 <input type="checkbox" id="wpa_diagnostics" name="wpa_diagnostics" <?php checked( get_option( 'wpa_diagnostics' ), 'on' ); ?>/>
102 <label for="wpa_diagnostics"><?php _e( 'Enable diagnostic CSS', 'wp-accessibility' ); ?></label>
103 </p>
104 <fieldset>
105 <legend><?php _e( 'Statistics Tracking', 'wp-accessibility' ); ?></legend>
106 <ul>
107 <li>
108 <input type="radio" id="wpa_track_stats_none" value="off" name="wpa_track_stats" <?php checked( get_option( 'wpa_track_stats' ), 'off' ); ?>/>
109 <label for="wpa_track_stats_none"><?php _e( 'Disabled', 'wp-accessibility' ); ?></label>
110 </li>
111 <li>
112 <input type="radio" id="wpa_track_stats_all" value="all" name="wpa_track_stats" <?php checked( get_option( 'wpa_track_stats' ), 'all' ); ?>/>
113 <label for="wpa_track_stats_all"><?php _e( 'All Visitors', 'wp-accessibility' ); ?></label>
114 </li>
115 <li>
116 <input type="radio" id="wpa_track_stats_admin" value="" name="wpa_track_stats" <?php checked( get_option( 'wpa_track_stats' ), '' ); ?>/>
117 <label for="wpa_track_stats_admin"><?php _e( 'Site Administrators', 'wp-accessibility' ); ?></label>
118 </li>
119 </ul>
120 </fieldset>
121 <p>
122 <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'wpa-nonce' ); ?>" />
123 <input type="hidden" name="action" value="tools" />
124 </p>
125 <p><input type="submit" name="wpa-settings" class="button-primary" value="<?php _e( 'Update Accessibility Tools', 'wp-accessibility' ); ?>"/></p>
126 </form>
127 </div>
128 </div>
129 <div class="postbox">
130 <h2 class='hndle'><?php _e( 'Color Contrast Tester', 'wp-accessibility' ); ?></h2>
131
132 <div class="inside">
133 <?php
134 $colors = wpa_contrast();
135 if ( $colors ) {
136 $luminance_raw = wpa_luminosity( $colors['red1'], $colors['red2'], $colors['green1'], $colors['green2'], $colors['blue1'], $colors['blue2'] );
137 $l_contrast = $luminance_raw . ':1';
138 $hex1 = esc_attr( $colors['hex1'] );
139 $hex2 = esc_attr( $colors['hex2'] );
140 } else {
141 $hex1 = '';
142 $hex2 = '';
143 $l_contrast = false;
144 $luminance_raw = 0;
145 }
146 if ( $l_contrast ) {
147 $results = "<div class='notice notice-info'>";
148 // Translators: Contrast ratio, foreground Hex color, background Hex color.
149 $results .= '<h2 class="stats wcag2">' . sprintf( __( 'Luminosity Contrast Ratio for %2$s and %3$s is %1$s (Threshold: greater than 7:1 for AAA, 4.5:1 for AA)', 'wp-accessibility' ), '<strong>' . $l_contrast . '</strong>', '<code>#' . $hex1 . '</code>', '<code>#' . $hex2 . '</code>' ) . '</h2><p>';
150 if ( $luminance_raw >= 7 ) {
151 $results .= __( 'The colors compared <strong>pass</strong> the relative luminosity test at level AAA.', 'wp-accessibility' );
152 }
153 if ( $luminance_raw >= 4.5 && $luminance_raw < 7 ) {
154 $results .= __( 'The colors compared <strong>pass</strong> the relative luminosity test at level AA.', 'wp-accessibility' );
155 }
156 if ( $luminance_raw >= 3 && $luminance_raw < 4.5 ) {
157 $results .= __( 'The colors compared pass the relative luminosity test <strong>only when used in large print</strong> situations (greater than 18pt (24px) text or 14pt (18.66px) bold text.)', 'wp-accessibility' );
158 }
159 if ( $luminance_raw < 3 ) {
160 $results .= __( 'The colors compared <strong>do not pass</strong> the relative luminosity test.', 'wp-accessibility' );
161 }
162 $results .= " <a href='#contrast'>" . __( 'Test another set of colors', 'wp-accessibility' ) . '</a>';
163 $results .= '</p>';
164 $results .= "
165 <div class=\"views\">
166 <p class='large' style=\"color: #$hex1;background: #$hex2\">Large Text (24px)</p>
167 <p class='small' style=\"color: #$hex1;background: #$hex2\">Standard Text (18px)</p>
168 <p class='large' style=\"color: #$hex2;background: #$hex1\">Large Text (24px) (Inverted)</p>
169 <p class='small' style=\"color: #$hex2;background: #$hex1\">Standard Text (18px) (Inverted)</p>
170 </div>
171 </div>";
172 echo $results;
173 }
174 ?>
175 <form method="get" id="contrast" action="<?php echo admin_url( 'admin.php?page=wp-accessibility-admin' ); ?>">
176 <fieldset>
177 <legend><?php _e( 'Test of relative luminosity', 'wp-accessibility' ); ?></legend>
178 <ul id="contrast-tester">
179 <li class='fore'>
180 <div id="fore"></div>
181 <label for="color1"><?php _e( 'Foreground color', 'wp-accessibility' ); ?></label><br/>
182 <input type="text" class="wpa-color-input" name="color" value="#<?php echo esc_attr( $hex1 ); ?>" size="34" id="color1" />
183 </li>
184 <li class='back'>
185 <div id="back"></div>
186 <label for="color2"><?php _e( 'Background color', 'wp-accessibility' ); ?></label><br/>
187 <input type="text" class="wpa-color-input" name="color2" value="#<?php echo esc_attr( $hex2 ); ?>" size="34" id="color2" />
188 </li>
189 </ul>
190 </fieldset>
191 <p>
192 <input type="hidden" name="action" value="contrast" />
193 <input type="hidden" name="page" value="wp-accessibility" />
194 </p>
195
196 <p><input type="submit" name="wpa-settings" class="button-primary" value="<?php _e( 'Check Color Contrast', 'wp-accessibility' ); ?>"/></p>
197 </form>
198 </div>
199 </div>
200 </div>
201 </div>
202 </div>
203
204 <?php wpa_admin_sidebar(); ?>
205 </div>
206 </div>
207 <?php
208 }
209