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(); $previousSibling = $input->previousSibling(); $nextSibling = $input->nextSibling(); // Check if label is a sibling and has the 'for' attribute matching input's 'id' if ( ($previousSibling && $previousSibling->tag === 'label' && $previousSibling->getAttribute('for') === $input->getAttribute('id')) || ($nextSibling && $nextSibling->tag === 'label' && $nextSibling->getAttribute('for') === $input->getAttribute('id')) || ($parent && $parent->tag === 'label' && $parent->getAttribute('for') === $input->getAttribute('id')) ) { continue; // Skip if label with 'for' attribute is found } // Check if no descriptive attributes and not in a labeled context if (!$input->getAttribute('placeholder') || !$input->getAttribute('aria-label') || !$input->getAttribute('aria-labelledby')) { $inputType = $input->getAttribute('type'); // Check if input type is not hidden, button, or submit if ($inputType && !in_array($inputType, ['hidden', 'button', 'submit'])) { $input->setAttribute('aria-label', $inputType); } } } }); } function hasNonEmptyTextContent($element) { $textContent = $element->plaintext; return $textContent !== '' && trim($textContent) !== ''; // Check if it's not empty or consists only of whitespace } // 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'); foreach ($links as $link) { $hasTextContent = false; $hasImageWithNonBlankAlt = false; // Check if link or its child elements have text content if (hasNonEmptyTextContent($link)) { $hasTextContent = true; } else { foreach ($link->find('*') as $element) { if (hasNonEmptyTextContent($element)) { $hasTextContent = true; break; } } } // Check if link lacks text content or child with text content, and aria-label attributes if (!$hasTextContent && !$link->getAttribute('aria-label') && !$link->getAttribute('aria-labelledby')) { foreach ($link->find('img') as $imgElement) { if (trim($imgElement->getAttribute('alt'))) { $hasImageWithNonBlankAlt = true; break; } } // Exclude links with image children having non-blank alt attribute if (!$hasImageWithNonBlankAlt) { $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('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