save(); return $html; } // Name: Form elements do not have associated labels function easywpstuff_assesplus_check_input_labels($html) { return process_html_with_dom($html, function($dom) { $inputs = $dom->find('input'); foreach ($inputs as $input) { $parent = $input->parent(); if ($parent && $parent->tag !== 'label') { if (!$input->getAttribute('id') && !$input->getAttribute('placeholder') && !$input->getAttribute('aria-label') && !$input->getAttribute('aria-labelledby')) { $inputType = $input->getAttribute('type'); if ($inputType && !in_array($inputType, ['hidden', 'button', 'submit'])) { $input->setAttribute('aria-label', $inputType); } } } } }); } // Links do not have a discernible name function easywpstuff_assesplus_add_aria_labels_to_links($html) { $html = str_replace('', '', $html); $html = str_replace('', '', $html); return process_html_with_dom($html, function($dom) { $links = $dom->find('a'); $headerLinks = $dom->find('header a'); $filteredHeaderLinks = array_filter($headerLinks, function($link) { return $link->find('i', 0) || ($link->find('span', 0) && trim($link->plaintext)); }); $links = array_merge($links, $filteredHeaderLinks); foreach ($links as $link) { $span = $link->find('span',0); $div = $link->find('div',0); $spnimg = $link->find('img',0); if($span && !$div && !$spnimg && !$link->getattribute('aria-label')){ $span_text = trim($span->plaintext); if($span_text){ $link->setattribute('aria-label', $span_text); } } $spanimg = $link->find('span img',0); if ($spanimg && !$link->getattribute('aria-label') && ($img->getattribute('alt')=='' || $img->getattribute('title')=='') ) { $link->setattribute('aria-label', 'image'); } if (!trim($link->plaintext) && !$link->getattribute('aria-label')) { $child_elements = $link->find('*'); if (empty($child_elements)) { $link->setattribute('aria-label', 'link'); } else { $icon = $link->find('i', 0); if ($icon) { $link->setattribute('aria-label', 'icon'); } else { $img = $link->find('img', 0); if ($img && !$img->getattribute('alt')) { $link->setattribute('aria-label', 'image'); } else if ($img && ($img->getattribute('alt')=='' || $img->getattribute('title')=='')) { $link->setattribute('aria-label', 'image'); } $svg = $link->find('svg', 0); if ($svg) { $link->setattribute('aria-label', 'svg'); } if (!$svg && !$img) { $link->setattribute('aria-label', 'link'); } } } } } }); } //Buttons do not have an accessible name function easywpstuff_assesplus_add_aria_labels_to_buttons($html) { return process_html_with_dom($html, function($dom) { $buttons = $dom->find('button'); foreach ($buttons as $button) { if (!trim($button->plaintext) && !$button->getattribute('aria-label')) { $child_elements = $button->find('*'); if (empty($child_elements)) { $button->setattribute('aria-label', 'button'); } else { $button->setattribute('aria-label', 'button'); } } if (!$button->getattribute('aria-label')) { $svg = $button->find('svg',0); $path = $button->find('path',0); $span = $button->find('span',0); if($svg && $path){ $button->setattribute('aria-label', 'button'); }elseif($span){ $span_text = trim($span->plaintext); if($span_text){ $button->setattribute('aria-label', $span_text); } } } } }); } //[user-scalable="no"] is used in the element or the [maximum-scale] attribute is less than 5. function easywpstuff_assesplus_modify_viewport_meta_tag($html) { return process_html_with_dom($html, function($dom) { $viewport_meta_tag = $dom->find('meta[name=viewport]', 0); if ($viewport_meta_tag) { $content = $viewport_meta_tag->getAttribute('content'); $content = preg_replace('/,\s*user-scalable=(?:no|0)/', '', $content); if (preg_match('/maximum-scale=([^,\s]*)/', $content, $matches)) { $maximum_scale = (float) $matches[1]; if ($maximum_scale < 2) { $content = preg_replace('/maximum-scale=[^,\s]*/', 'maximum-scale=2', $content); } } else { $content .= ', maximum-scale=2'; } $viewport_meta_tag->setAttribute('content', $content); } }); } function easywpstuff_assesplus_add_aria_labels_to_headers($html) { return process_html_with_dom($html, function($dom) { foreach($dom->find('header div') as $div) { if ($div->role == 'link' && !$div->hasAttribute('aria-label')) { $div->setAttribute('aria-label', 'link'); } if ($div->role == 'button' && !$div->hasAttribute('aria-label')) { $div->setAttribute('aria-label', 'button'); } if ($div->role == 'menuitem' && !$div->hasAttribute('aria-label')) { $div->setAttribute('aria-label', 'menuitem'); } } }); } // or