10 ] );
$html = is_wp_error( $response ) ? '' : wp_remote_retrieve_body( $response );
if ( empty( $html ) ) {
return [ 'score' => 0, 'issues' => [ [ 'type' => 'error', 'msg' => __( 'Could not fetch homepage. Try scanning from a browser where your site is accessible.', 'ago-access' ) ] ] ];
}
// Lang attribute
if ( ! preg_match( '/html[^>]*lang=/i', $html ) ) {
$issues[] = [ 'type' => 'error', 'msg' => __( 'Missing lang attribute on tag', 'ago-access' ), 'fix' => __( 'Enable "Lang Attribute" in auto fixes', 'ago-access' ) ];
$score -= 10;
}
// Viewport meta
if ( ! preg_match( '/meta[^>]*viewport/i', $html ) ) {
$issues[] = [ 'type' => 'warning', 'msg' => __( 'Missing viewport meta tag', 'ago-access' ), 'fix' => __( 'Your theme should include a viewport meta tag', 'ago-access' ) ];
$score -= 5;
}
// Skip link
if ( ! preg_match( '/skip.*content|skip.*nav|skip.*main/i', $html ) ) {
$issues[] = [ 'type' => 'warning', 'msg' => __( 'No skip-to-content link found', 'ago-access' ), 'fix' => __( 'Enable "Skip Link" in auto fixes', 'ago-access' ) ];
$score -= 10;
}
// Images without alt
preg_match_all( '/
]*>/i', $html, $imgs );
$no_alt = 0;
foreach ( $imgs[0] ?? [] as $img ) {
if ( ! preg_match( '/alt\s*=/i', $img ) ) $no_alt++;
}
if ( $no_alt > 0 ) {
/* translators: %d: number of images without alt attribute */
$issues[] = [ 'type' => 'error', 'msg' => sprintf( __( '%d images without alt attribute', 'ago-access' ), $no_alt ), 'fix' => __( 'Add descriptive alt text to all images', 'ago-access' ) ];
$score -= min( 20, $no_alt * 5 );
}
// Heading structure (h1)
preg_match_all( '/
]*>/i', $html, $h1s );
$h1_count = count( $h1s[0] );
if ( $h1_count === 0 ) {
$issues[] = [ 'type' => 'warning', 'msg' => __( 'No H1 heading found', 'ago-access' ), 'fix' => __( 'Every page should have one H1', 'ago-access' ) ];
$score -= 10;
} elseif ( $h1_count > 1 ) {
/* translators: %d: number of H1 headings found */
$issues[] = [ 'type' => 'warning', 'msg' => sprintf( __( '%d H1 headings found (recommended: 1)', 'ago-access' ), $h1_count ), 'fix' => __( 'Use only one H1 per page', 'ago-access' ) ];
$score -= 5;
}
// Form inputs without labels
preg_match_all( '/]*type=["\'](?:text|email|password|tel|search|number)["\'][^>]*>/i', $html, $inputs );
$input_count = count( $inputs[0] );
preg_match_all( '/