Changeset 2956822
- Timestamp:
- 08/22/2023 01:32:00 PM (3 years ago)
- Location:
- accessibility-plus
- Files:
-
- 8 added
- 2 edited
-
tags/1.2.2 (added)
-
tags/1.2.2/accessibility.php (added)
-
tags/1.2.2/assets (added)
-
tags/1.2.2/assets/style.css (added)
-
tags/1.2.2/inc (added)
-
tags/1.2.2/inc/options.php (added)
-
tags/1.2.2/inc/simple_html_dom.php (added)
-
tags/1.2.2/readme.txt (added)
-
trunk/accessibility.php (modified) (15 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
accessibility-plus/trunk/accessibility.php
r2951458 r2956822 4 4 Plugin URI: 5 5 Description: Improve pagespeed insight or lighthouse accessibility scores by fixing recommended issues. 6 Version: 1.2. 16 Version: 1.2.2 7 7 Author: easywpstuff 8 8 Author URI: https://easywpstuff.com … … 17 17 include_once('inc/options.php'); 18 18 19 function process_html_with_dom($html, $callback) { 20 $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' '); 21 22 if (empty($dom)) { 23 return $html; 24 } 25 26 $callback($dom); 27 28 $html = $dom->save(); 29 return $html; 30 } 19 31 20 32 // Name: Form elements do not have associated labels 21 33 function easywpstuff_assesplus_check_input_labels($html) { 22 if (empty($html)) { 23 return $html; 24 } 25 26 $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' '); 27 if (empty($dom)) { 28 return $dom; 29 } 34 return process_html_with_dom($html, function($dom) { 30 35 $inputs = $dom->find('input'); 31 36 … … 41 46 } 42 47 } 43 return $dom->save();48 }); 44 49 } 45 50 … … 49 54 $html = str_replace('</source>', '', $html); 50 55 51 $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' '); 52 if (empty($dom)) { 53 return $dom; 54 } 56 return process_html_with_dom($html, function($dom) { 55 57 $links = $dom->find('a'); 56 58 $headerLinks = $dom->find('header a'); … … 102 104 } 103 105 104 return $dom->save();106 }); 105 107 } 106 108 … … 110 112 function easywpstuff_assesplus_add_aria_labels_to_buttons($html) { 111 113 112 $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' '); 113 if (empty($dom)) { 114 return $dom; 115 } 114 return process_html_with_dom($html, function($dom) { 116 115 $buttons = $dom->find('button'); 117 118 116 foreach ($buttons as $button) { 119 117 if (!trim($button->plaintext) && !$button->getattribute('aria-label')) { … … 139 137 } 140 138 } 141 return $dom->save();139 }); 142 140 } 143 141 … … 145 143 function easywpstuff_assesplus_modify_viewport_meta_tag($html) { 146 144 147 $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' '); 148 if (empty($dom)) { 149 return $dom; 150 } 145 return process_html_with_dom($html, function($dom) { 151 146 $viewport_meta_tag = $dom->find('meta[name=viewport]', 0); 152 147 if ($viewport_meta_tag) { … … 167 162 $viewport_meta_tag->setAttribute('content', $content); 168 163 } 169 return $dom->save();164 }); 170 165 } 171 166 172 167 173 168 function easywpstuff_assesplus_add_aria_labels_to_headers($html) { 174 $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' '); 175 if (empty($dom)) { 176 return $dom; 177 } 169 return process_html_with_dom($html, function($dom) { 178 170 179 171 foreach($dom->find('header div') as $div) { … … 189 181 } 190 182 191 $html = $dom->save(); // Save the modified HTML 192 return $html; // Return the modified HTML 183 }); 193 184 } 194 185 195 186 // <frame> or <iframe> elements do not have a title 196 187 function easywpstuff_assesplus_booster_add_to_iframes($html) { 197 $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' '); 198 if (empty($dom)) { 199 return $dom; 200 } 188 return process_html_with_dom($html, function($dom) { 201 189 202 190 foreach($dom->find('iframe') as $iframe) { … … 206 194 } 207 195 208 $html = $dom->save(); 209 return $html; 196 }); 210 197 } 211 198 212 199 //Links are not crawlable 213 200 function easywpstuff_assesplus_addHashToBlankLinks($html) { 214 $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' '); 215 if (empty($dom)) { 216 return $dom; 217 } 201 return process_html_with_dom($html, function($dom) { 218 202 $blankLinks = $dom->find('a'); 219 203 foreach ($blankLinks as $link) { … … 228 212 } 229 213 } 230 $html = $dom->save(); 231 return $html; 214 }); 232 215 } 233 216 … … 235 218 function easywpstuff_assesplus_add_aria_label_to_progressbar($html) { 236 219 // Use Simple HTML DOM to parse the HTML 237 $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' '); 238 if (empty($dom)) { 239 return $dom; 240 } 220 return process_html_with_dom($html, function($dom) { 241 221 foreach($dom->find('[role=progressbar]') as $element) { 242 222 // Check if the element has aria-label, aria-labelledby or title attribute … … 249 229 } 250 230 } 251 // Return the modified HTML 252 $html = $dom->save(); 253 return $html; 231 }); 254 232 } 255 233 //Image elements do not have [alt] attributes 256 234 function easywpstuff_assesplus_addAltToImg($html) { 257 $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' '); 258 if (empty($dom)) { 259 return $dom; 260 } 235 return process_html_with_dom($html, function($dom) { 261 236 $imgs = $dom->find('img'); 262 237 foreach ($imgs as $img) { … … 276 251 } 277 252 } 278 $html = $dom->save(); 279 return $html; 253 }); 280 254 } 281 255 282 256 // buffer if option is enabled 283 function easywpstuff_assesplus_bstr_template_redirect( $buffer ) { 284 285 if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_booster_field_no_labels'] == 1 ) { 286 $buffer = easywpstuff_assesplus_check_input_labels( $buffer ); 287 } 288 289 if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_booster_field_no_discernible_name'] == 1 ) { 290 291 $buffer = easywpstuff_assesplus_add_aria_labels_to_links( $buffer ); 292 } 293 294 if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_booster_field_no_accessible_name'] == 1 ) { 295 296 $buffer = easywpstuff_assesplus_add_aria_labels_to_buttons( $buffer ); 297 } 298 299 if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_booster_field_viewport_meta_tag'] == 1 ) { 300 $buffer = easywpstuff_assesplus_modify_viewport_meta_tag( $buffer ); 301 } 302 303 if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_booster_field_menuitem_accessible'] == 1 ) { 304 $buffer = easywpstuff_assesplus_add_aria_labels_to_headers( $buffer ); 305 } 306 307 if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_booster_field_iframe_title_tag'] == 1 ) { 308 $buffer = easywpstuff_assesplus_booster_add_to_iframes( $buffer ); 309 } 310 311 if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_add_aria_label_to_progressbar'] == 1 ) { 312 $buffer = easywpstuff_assesplus_add_aria_label_to_progressbar( $buffer ); 313 } 314 315 if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_links_not_crawlable'] == 1 ) { 316 $buffer = easywpstuff_assesplus_addHashToBlankLinks( $buffer ); 317 } 318 319 if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_img_donot_alt'] == 1 ) { 320 $buffer = easywpstuff_assesplus_addAltToImg( $buffer ); 321 } 322 323 return $buffer; 324 } 325 //add_action( 'template_redirect', 'easywpstuff_assesplus_bstr_template_redirect', 99 ); 326 327 // run the function 257 258 function easywpstuff_assesplus_bstr_template_redirect($buffer) { 259 $options = get_option('easywpstuff_assesplus_booster_options'); 260 261 if ($options['easywpstuff_assesplus_booster_field_no_labels'] == 1) { 262 $buffer = easywpstuff_assesplus_check_input_labels($buffer); 263 } 264 265 if ($options['easywpstuff_assesplus_booster_field_no_discernible_name'] == 1) { 266 $buffer = easywpstuff_assesplus_add_aria_labels_to_links($buffer); 267 } 268 269 if ($options['easywpstuff_assesplus_booster_field_no_accessible_name'] == 1) { 270 $buffer = easywpstuff_assesplus_add_aria_labels_to_buttons($buffer); 271 } 272 273 if ($options['easywpstuff_assesplus_booster_field_viewport_meta_tag'] == 1) { 274 $buffer = easywpstuff_assesplus_modify_viewport_meta_tag($buffer); 275 } 276 277 if ($options['easywpstuff_assesplus_booster_field_menuitem_accessible'] == 1) { 278 $buffer = easywpstuff_assesplus_add_aria_labels_to_headers($buffer); 279 } 280 281 if ($options['easywpstuff_assesplus_booster_field_iframe_title_tag'] == 1) { 282 $buffer = easywpstuff_assesplus_booster_add_to_iframes($buffer); 283 } 284 285 if ($options['easywpstuff_assesplus_add_aria_label_to_progressbar'] == 1) { 286 $buffer = easywpstuff_assesplus_add_aria_label_to_progressbar($buffer); 287 } 288 289 if ($options['easywpstuff_assesplus_links_not_crawlable'] == 1) { 290 $buffer = easywpstuff_assesplus_addHashToBlankLinks($buffer); 291 } 292 293 if ($options['easywpstuff_assesplus_img_donot_alt'] == 1) { 294 $buffer = easywpstuff_assesplus_addAltToImg($buffer); 295 } 296 297 return $buffer; 298 } 299 328 300 add_action( 'template_redirect', 'easywpstuff_assesplus_loader', 99 ); 329 301 function easywpstuff_assesplus_loader() { -
accessibility-plus/trunk/readme.txt
r2951458 r2956822 5 5 Tested up to: 6.3 6 6 Requires PHP: 5.6 7 Stable tag: 1.2. 17 Stable tag: 1.2.2 8 8 License: GNU General Public License v2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 52 52 53 53 == Changelog == 54 = 1.2.2 = 55 * Improved DOM 54 56 = 1.2.1 = 55 57 * Minor Fixes … … 57 59 * Speedup DOM and Fixed Fatal error 58 60 = 1.1.3 = 59 * Minor eImprovement61 * Minor Improvement 60 62 = 1.1.2 = 61 63 * Fixed svg conflict
Note: See TracChangeset
for help on using the changeset viewer.