find('input');
foreach ($inputs as $input) {
$label = $input->prev_sibling();
if ($label && $label->tag == 'label') {
continue;
}
if (!$input->getAttribute('aria-label')) {
$input->setAttribute('aria-label', 'hidden');
}
}
return $dom->save();
}
// Links do not have a discernible name
function easywpstuff_assesplus_add_aria_labels_to_links($html) {
$picture_html = str_replace('', '', $html);
$picture_html = str_replace('', '', $picture_html);
$dom = lhb_str_get_html($picture_html, false, true, 'UTF-8', false, PHP_EOL, ' ');
$links = $dom->find('a');
$headerLinks = $dom->find('header a');
$headerLinks = array_filter($headerLinks, function($link) {
return $link->find('i', 0) || ($link->find('span', 0) && trim($link->plaintext));
});
$links = array_diff($links, $headerLinks);
foreach ($links as $link) {
$span = $link->find('span',0);
$div = $link->find('div',0);
if($span && !$div && !$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');
}
}
}
}
}
return $dom->save();
}
//Buttons do not have an accessible name
function easywpstuff_assesplus_add_aria_labels_to_buttons($html) {
$dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' ');
$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);
}
}
}
}
return $dom->save();
}
//[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) {
$dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' ');
$viewport_meta_tag = $dom->find('meta[name=viewport]', 0);
if ($viewport_meta_tag) {
$content = $viewport_meta_tag->getAttribute('content');
$content = preg_replace('/user-scalable=no/', '', $content);
$content = preg_replace('/user-scalable=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);
}
return $dom->save();
}
function easywpstuff_assesplus_add_aria_labels_to_headers($html) {
$dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' '); // Parse the HTML into a DOM object
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');
}
}
$html = $dom->save(); // Save the modified HTML
return $html; // Return the modified HTML
}
// or