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) { $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' '); $links = $dom->find('a'); foreach ($links as $link) { 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'); } } } } } 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'); } } } 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