['Technical SEO', 18], 'onpage' => ['On-page SEO', 18], 'adsense' => ['AdSense readiness', 16], 'trust' => ['Trust (E-E-A-T)', 10], 'aeo' => $m['aeo'], 'ai' => ['AI search readiness', 10],
'speed' => ['Speed and mobile', 12], 'security' => ['Security', 8], 'domain' => ['E-mail and domain', 4], 'struct' => $m['struct'], 'a11y' => $m['a11y'], 'local' => $m['local'], 'shop' => $m['shop'], 'wp' => ['WordPress health', 4]];
}
/** id => [section, title, weight]. */
function aiotsa_registry() {
static $r = null; if ($r) return $r;
$r = [
't_status' => ['tech', 'Home page loads', 3], 't_https' => ['tech', 'HTTPS', 3], 't_ssl' => ['tech', 'SSL certificate', 2], 't_robots' => ['tech', 'robots.txt', 3], 't_sitemap' => ['tech', 'XML sitemap', 3],
't_sitemap_bad' => ['tech', 'Sitemap URLs that fail', 2], 't_noindex' => ['tech', 'Open to search engines', 3], 't_canonical' => ['tech', 'Canonical tag', 2], 't_variants' => ['tech', 'www and https versions', 2],
't_chain' => ['tech', 'Redirect chains', 1], 't_permalink' => ['tech', 'Permalink structure', 1], 't_broken' => ['tech', 'Broken links', 3], 't_compress' => ['tech', 'Compression', 1], 't_cache' => ['tech', 'Browser caching', 1],
't_mixed' => ['tech', 'Mixed content', 1], 't_basics' => ['tech', 'Favicon, language and viewport', 1], 't_404' => ['tech', '404 page', 1],
'o_title' => ['onpage', 'Title tags', 3], 'o_desc' => ['onpage', 'Meta descriptions', 3], 'o_h1' => ['onpage', 'One H1 per page', 2], 'o_heads' => ['onpage', 'Heading order', 1], 'o_alt' => ['onpage', 'Image alt text', 2],
'o_links' => ['onpage', 'Internal links', 2], 'o_og' => ['onpage', 'Open Graph tags', 1], 'o_schema' => ['onpage', 'Structured data', 2], 'o_read' => ['onpage', 'Readability', 1], 'o_dup' => ['onpage', 'Duplicate titles', 2],
'o_url' => ['onpage', 'Short, clean URLs', 1], 'o_cannibal' => ['onpage', 'Posts competing for the same topic', 1],
'a_privacy' => ['adsense', 'Privacy Policy page', 3], 'a_privacy_text' => ['adsense', 'Privacy Policy mentions cookies and advertising', 2], 'a_about' => ['adsense', 'About page', 2], 'a_contact' => ['adsense', 'Contact page', 2],
'a_terms' => ['adsense', 'Terms page', 1], 'a_disclaimer' => ['adsense', 'Disclaimer page', 1], 'a_posts' => ['adsense', 'Published posts', 3], 'a_thin' => ['adsense', 'Thin posts', 3], 'a_placeholder' => ['adsense', 'Placeholder content', 2],
'a_adstxt' => ['adsense', 'ads.txt', 1], 'a_consent' => ['adsense', 'Cookie consent banner', 2], 'a_nav' => ['adsense', 'Menu and navigation', 2], 'a_age' => ['adsense', 'Domain age', 1], 'a_risky' => ['adsense', 'Content that may break ad policies', 2],
'a_open' => ['adsense', 'Site is public and secure', 3],
'r_author' => ['trust', 'Author shown on posts', 2], 'r_dates' => ['trust', 'Dates shown on posts', 1], 'r_about' => ['trust', 'About page detail', 2], 'r_contact' => ['trust', 'Contact details', 2], 'r_org' => ['trust', 'Organization or Person schema', 1], 'r_social' => ['trust', 'Social profiles linked', 1],
'i_bots' => ['ai', 'AI crawlers in robots.txt', 0], 'i_llms' => ['ai', 'llms.txt', 1], 'i_nojs' => ['ai', 'Text readable without JavaScript', 3], 'i_qheads' => ['ai', 'Question-style headings', 2], 'i_answer' => ['ai', 'Short answer near the top', 2],
'i_faq' => ['ai', 'FAQ sections', 2], 'i_sources' => ['ai', 'Sources linked', 1], 'i_schema' => ['ai', 'Article schema with author and dates', 2],
's_psi_m' => ['speed', 'PageSpeed score (mobile)', 4], 's_psi_d' => ['speed', 'PageSpeed score (desktop)', 2], 's_lcp' => ['speed', 'Largest Contentful Paint (LCP)', 2], 's_cls' => ['speed', 'Layout shift (CLS)', 1], 's_inp' => ['speed', 'Interaction delay (INP)', 1],
's_ttfb' => ['speed', 'Server response time', 2], 's_size' => ['speed', 'HTML size', 1], 's_block' => ['speed', 'Render-blocking files', 1], 's_imgfmt' => ['speed', 'Modern image formats', 1], 's_imgdim' => ['speed', 'Image width and height set', 1], 's_viewport' => ['speed', 'Mobile viewport', 2],
'c_headers' => ['security', 'Security headers', 2], 'c_versions' => ['security', 'WordPress and PHP versions', 2], 'c_blacklist' => ['security', 'Spam blacklists', 2], 'c_files' => ['security', 'Exposed files', 2], 'c_safe' => ['security', 'Google Safe Browsing', 0],
'd_spf' => ['domain', 'SPF record', 1], 'd_dmarc' => ['domain', 'DMARC record', 1], 'd_mx' => ['domain', 'Mail (MX) records', 1], 'd_expiry' => ['domain', 'Domain expiry', 2], 'd_host' => ['domain', 'Server', 0],
'w_seo' => ['wp', 'SEO plugin', 2], 'w_orphan' => ['wp', 'Orphan posts', 2], 'w_image' => ['wp', 'Posts without a featured image', 1], 'w_cat' => ['wp', 'Uncategorized posts', 1], 'w_stale' => ['wp', 'Posts not updated in 12 months', 1],
'w_drafts' => ['wp', 'Drafts and pending posts', 0], 'w_comments' => ['wp', 'Comments waiting or spam', 1],
];
$r += aiotsa_more_registry();
return $r;
}
/** Build one result. $list rows: [label, url, edit_url]. */
function aiotsa_r($s, $m, $ma = [], $f = '', $fa = [], $list = []) { $o = ['s' => $s, 'm' => array_merge([$m], (array) $ma)]; if ($f !== '') $o['f'] = array_merge([$f], (array) $fa); if ($list) $o['l'] = array_slice($list, 0, 200); return $o; }
function aiotsa_skip($why = 'Could not check: %s', $a = []) { return aiotsa_r('skip', $why, $a); }
function aiotsa_origin($url) { $p = wp_parse_url($url); return ($p['scheme'] ?? 'https') . '://' . ($p['host'] ?? '') . (isset($p['port']) ? ':' . $p['port'] : ''); }
/* ---------- site tasks ---------- */
function aiotsa_task_home(&$A) {
$url = $A['target']; $R = &$A['results']; $C = &$A['summary']['ctx'];
$r = aiotsa_fetch($url, ['timeout' => 15]);
if (!$r['ok']) { $R['t_status'] = aiotsa_r('fail', 'The page did not load (%s).', [$r['error'] ?: ('HTTP ' . $r['code'])], 'Check that the address is right and the site is online.'); $C['home'] = ['ok' => false]; return; }
$f = aiotsa_parse($r['body'], $r['url']); $C['home'] = $f; $C['home_url'] = $r['url']; $C['home_ms'] = $r['ms']; $C['home_bytes'] = strlen($r['body']);
$R['t_status'] = aiotsa_r('pass', 'Loads with HTTP %d.', [$r['code']]);
$https = stripos($r['url'], 'https://') === 0;
$R['t_https'] = $https ? aiotsa_r('pass', 'The site uses HTTPS.') : aiotsa_r('fail', 'The site does not use HTTPS.', [], 'Install an SSL certificate (free with most hosts) and switch the site address to https.');
$noi = strpos($f['robots'], 'noindex') !== false || stripos(aiotsa_hdr($r, 'x-robots-tag'), 'noindex') !== false; $C['noindex'] = $noi;
$R['t_noindex'] = $noi ? aiotsa_r('fail', 'The page tells search engines not to index it (noindex).', [], 'Remove the noindex setting. In WordPress: Settings > Reading > untick "Discourage search engines".') : aiotsa_r('pass', 'No noindex on the page.');
if ($f['canonical'] === '') $R['t_canonical'] = aiotsa_r('warn', 'No canonical tag.', [], 'Turn on canonical URLs in your SEO plugin.');
else { $same = untrailingslashit(strtolower($f['canonical'])) === untrailingslashit(strtolower($r['url'])); $R['t_canonical'] = $same ? aiotsa_r('pass', 'Points to this page.') : aiotsa_r('warn', 'Points to another address: %s', [$f['canonical']], 'Make sure the canonical is the address you want in Google.'); }
$R['t_mixed'] = !$https ? aiotsa_skip('Not on HTTPS.') : ($f['mixed'] ? aiotsa_r('warn', '%d files load over http on an https page.', [$f['mixed']], 'Change those links to https.') : aiotsa_r('pass', 'None found.'));
$miss = []; if (!$f['favicon']) $miss[] = 'favicon'; if ($f['lang'] === '') $miss[] = 'language'; if (!$f['viewport']) $miss[] = 'viewport';
$R['t_basics'] = $miss ? aiotsa_r('warn', 'Missing: %s.', [implode(', ', $miss)], 'Add a site icon in Appearance > Customize, and use a mobile-ready theme.') : aiotsa_r('pass', 'All set.');
$R['s_viewport'] = $f['viewport'] ? aiotsa_r('pass', 'The page has a mobile viewport.') : aiotsa_r('fail', 'No mobile viewport tag: the page will look zoomed out on phones.', [], 'Use a responsive theme.');
$R['s_ttfb'] = $r['ms'] <= 800 ? aiotsa_r('pass', '%d ms.', [$r['ms']]) : ($r['ms'] <= 1800 ? aiotsa_r('warn', '%d ms. Under 800 ms is good.', [$r['ms']], 'Turn on page caching.') : aiotsa_r('fail', '%d ms. Under 800 ms is good.', [$r['ms']], 'Turn on page caching, or move to faster hosting.'));
$kb = (int) round(strlen($r['body']) / 1024);
$R['s_size'] = $kb <= 150 ? aiotsa_r('pass', '%d KB of HTML.', [$kb]) : aiotsa_r('warn', '%d KB of HTML. Under 150 KB is good.', [$kb], 'Remove unused page-builder sections, inline CSS and scripts.');
$bl = $f['block_css'] + $f['block_js'];
$R['s_block'] = $bl <= 4 ? aiotsa_r('pass', '%1$d CSS and %2$d JS files in the head.', [$f['block_css'], $f['block_js']]) : aiotsa_r('warn', '%1$d CSS and %2$d JS files block the first paint.', [$f['block_css'], $f['block_js']], 'Turn on "delay JavaScript" and "combine CSS" in your cache plugin.');
if ($f['imgs']) {
$R['s_imgfmt'] = $f['img_old'] <= $f['imgs'] / 2 ? aiotsa_r('pass', '%1$d of %2$d images use WebP, AVIF or SVG.', [$f['imgs'] - $f['img_old'], $f['imgs']]) : aiotsa_r('warn', '%1$d of %2$d images are JPG, PNG or GIF.', [$f['img_old'], $f['imgs']], 'Serve WebP with an image optimization plugin.');
$R['s_imgdim'] = $f['nodim'] <= 1 ? aiotsa_r('pass', 'Images have width and height.') : aiotsa_r('warn', '%d images have no width and height, which makes the page jump while loading.', [$f['nodim']], 'Add width and height to those images.');
} else { $R['s_imgfmt'] = aiotsa_skip('No images on the page.'); $R['s_imgdim'] = aiotsa_skip('No images on the page.'); }
// security headers
$want = ['strict-transport-security' => 'HSTS', 'x-content-type-options' => 'X-Content-Type-Options', 'x-frame-options' => 'X-Frame-Options', 'content-security-policy' => 'Content-Security-Policy', 'referrer-policy' => 'Referrer-Policy', 'permissions-policy' => 'Permissions-Policy'];
$have = []; $no = []; foreach ($want as $k => $n) { if (aiotsa_hdr($r, $k) !== '' || ($k === 'x-frame-options' && stripos(aiotsa_hdr($r, 'content-security-policy'), 'frame-ancestors') !== false)) $have[] = $n; else $no[] = $n; }
$C['sec_headers'] = count($have);
$R['c_headers'] = count($have) >= 5 ? aiotsa_r('pass', '%d of 6 set.', [count($have)]) : aiotsa_r(count($have) >= 2 ? 'warn' : 'fail', '%1$d of 6 set. Missing: %2$s.', [count($have), implode(', ', $no)], 'Add them with a security plugin or in .htaccess.');
$C['server'] = aiotsa_hdr($r, 'server'); $C['cdn'] = aiotsa_hdr($r, 'cf-ray') !== '' ? 'Cloudflare' : (aiotsa_hdr($r, 'x-amz-cf-id') !== '' ? 'CloudFront' : (stripos(aiotsa_hdr($r, 'server'), 'bunny') !== false ? 'bunny.net' : ''));
// compression
$GLOBALS['aiotsa_raw'] = true; $z = aiotsa_fetch($r['url'], ['timeout' => 10, 'max' => 3000, 'headers' => ['Accept-Encoding' => 'br, gzip']]); $enc = strtolower(aiotsa_hdr($z, 'content-encoding'));
$R['t_compress'] = $z['error'] !== '' ? aiotsa_skip('Could not check: %s', [$z['error']]) : ($enc !== '' ? aiotsa_r('pass', '%s is on.', [$enc === 'br' ? 'Brotli' : strtoupper($enc)]) : aiotsa_r('warn', 'Pages are sent without compression.', [], 'Turn on GZIP or Brotli in your host panel or cache plugin.'));
// caching of one static file
$asset = ''; if (preg_match('#]+rel=["\']stylesheet["\'][^>]+href=["\']([^"\']+\.css[^"\']*)#i', $r['body'], $m) || preg_match('#
]+src=["\']([^"\']+\.(?:png|jpe?g|webp|svg)[^"\']*)#i', $r['body'], $m)) $asset = WP_Http::make_absolute_url(html_entity_decode($m[1]), $r['url']);
if ($asset) { $c = aiotsa_fetch($asset, ['method' => 'HEAD', 'timeout' => 8]); $cc = aiotsa_hdr($c, 'cache-control'); $age = preg_match('/max-age=(\d+)/', $cc, $mm) ? (int) $mm[1] : 0;
$R['t_cache'] = $c['error'] !== '' ? aiotsa_skip('Could not check: %s', [$c['error']]) : ($age >= 604800 || aiotsa_hdr($c, 'expires') !== '' && $age === 0 && $cc === '' ? aiotsa_r('pass', 'Static files are cached by the browser.') : aiotsa_r('warn', 'Static files have a short or no cache lifetime.', [], 'Turn on browser caching in your cache plugin.')); }
else $R['t_cache'] = aiotsa_skip('No static file found to test.');
$soc = []; foreach ($f['ext'] as $l) if (preg_match('#//(?:www\.)?(facebook|instagram|linkedin|youtube|x|twitter|pinterest|t|threads|tiktok)\.(?:com|me|net)/#i', $l, $m)) $soc[strtolower($m[1])] = 1;
$C['social'] = array_keys($soc);
}
add_filter('http_request_args', function ($a) { if (!empty($GLOBALS['aiotsa_raw'])) { $a['decompress'] = false; $GLOBALS['aiotsa_raw'] = false; } return $a; });
function aiotsa_ai_bots() {
return ['GPTBot' => 'ChatGPT training', 'OAI-SearchBot' => 'ChatGPT search', 'ChatGPT-User' => 'ChatGPT browsing for a user', 'ClaudeBot' => 'Claude training', 'Claude-SearchBot' => 'Claude search', 'PerplexityBot' => 'Perplexity search',
'Google-Extended' => 'Gemini training', 'Applebot-Extended' => 'Apple AI training', 'CCBot' => 'Common Crawl', 'Bytespider' => 'ByteDance', 'Meta-ExternalAgent' => 'Meta AI', 'Amazonbot' => 'Amazon'];
}
/** Is $agent allowed to fetch "/" under this robots.txt? Returns 'allow', 'block' or 'partial'. */
function aiotsa_robots_rule($txt, $agent) {
$groups = []; $cur = null; $last = '';
foreach (preg_split('/\r\n|\r|\n/', (string) $txt) as $line) {
$line = trim(preg_replace('/#.*$/', '', $line)); if ($line === '' || strpos($line, ':') === false) continue;
[$k, $v] = array_map('trim', explode(':', $line, 2)); $k = strtolower($k);
if ($k === 'user-agent') { if ($last !== 'user-agent') { $groups[] = ['ua' => [], 'rules' => []]; $cur = count($groups) - 1; } $groups[$cur]['ua'][] = strtolower($v); }
elseif (($k === 'allow' || $k === 'disallow') && $cur !== null) $groups[$cur]['rules'][] = [$k, $v];
$last = $k;
}
$pick = null; foreach ($groups as $g) if (in_array(strtolower($agent), $g['ua'], true)) { $pick = $g; break; }
if (!$pick) foreach ($groups as $g) if (in_array('*', $g['ua'], true)) { $pick = $g; break; }
if (!$pick) return 'allow';
$block = false; $some = false; $allowroot = false;
foreach ($pick['rules'] as [$k, $v]) { if ($k === 'disallow' && ($v === '/' || $v === '/*')) $block = true; elseif ($k === 'disallow' && $v !== '') $some = true; elseif ($k === 'allow' && ($v === '/' || $v === '/*')) $allowroot = true; }
return $block && !$allowroot ? 'block' : 'allow';
}
function aiotsa_task_robots(&$A) {
$R = &$A['results']; $C = &$A['summary']['ctx']; $o = aiotsa_origin($A['target']);
$r = aiotsa_fetch($o . '/robots.txt', ['timeout' => 10, 'max' => 300000]); $txt = ($r['code'] === 200 && stripos(aiotsa_hdr($r, 'content-type'), 'html') === false) ? $r['body'] : ''; $C['robots'] = substr($txt, 0, 20000);
if ($r['error'] !== '') { $R['t_robots'] = aiotsa_skip('Could not check: %s', [$r['error']]); }
elseif ($txt === '') $R['t_robots'] = aiotsa_r('warn', 'No robots.txt found.', [], 'WordPress normally makes one for you. Check that nothing blocks /robots.txt.');
elseif (aiotsa_robots_rule($txt, 'Googlebot') === 'block') $R['t_robots'] = aiotsa_r('fail', 'robots.txt blocks the whole site for search engines.', [], 'Remove the line "Disallow: /".');
else $R['t_robots'] = aiotsa_r('pass', 'Found. It does not block the site.');
preg_match_all('/^\s*sitemap:\s*(\S+)/im', $txt, $m); $C['robots_sitemaps'] = array_slice($m[1], 0, 5);
$list = []; $blocked = 0; foreach (aiotsa_ai_bots() as $b => $what) { $st = aiotsa_robots_rule($txt, $b); if ($st === 'block') $blocked++; $list[] = [$b . ' - ' . $what, '', '', $st]; }
$C['ai_blocked'] = $blocked;
$R['i_bots'] = aiotsa_r('info', $blocked ? '%1$d of %2$d AI crawlers are blocked.' : 'All %2$d AI crawlers are allowed.', [$blocked, count($list)], '', [], $list);
}
function aiotsa_sitemap_urls($url, &$count, &$sample, $depth = 0) {
$r = aiotsa_fetch($url, ['timeout' => 12, 'max' => 3000000]); if ($r['code'] !== 200 || stripos($r['body'], '<') === false) return false;
if (preg_match_all('#.*?\s*(?:.*?\s*(?:= 1500) break; $sample[] = trim(html_entity_decode($u)); }
return true;
}
function aiotsa_task_sitemap(&$A) {
$R = &$A['results']; $C = &$A['summary']['ctx']; $o = aiotsa_origin($A['target']);
$try = array_merge($C['robots_sitemaps'] ?? [], [$o . '/sitemap_index.xml', $o . '/sitemap.xml', $o . '/wp-sitemap.xml']); $found = ''; $count = 0; $sample = [];
foreach (array_unique($try) as $u) { $count = 0; $sample = []; if (aiotsa_sitemap_urls($u, $count, $sample)) { $found = $u; break; } }
$C['sitemap'] = $found; $C['sitemap_count'] = $count; $C['sitemap_sample'] = $sample;
if ($found === '') { $R['t_sitemap'] = aiotsa_r('fail', 'No XML sitemap found.', [], 'Turn on the sitemap in your SEO plugin, or use the WordPress one at /wp-sitemap.xml.'); $R['t_sitemap_bad'] = aiotsa_skip('No sitemap.'); return; }
$inrobots = !empty($C['robots_sitemaps']);
$R['t_sitemap'] = $inrobots ? aiotsa_r('pass', 'Found with %d URLs, and listed in robots.txt.', [$count]) : aiotsa_r('warn', 'Found with %d URLs, but not listed in robots.txt.', [$count], 'Add a line "Sitemap: %s" to robots.txt.', [$found]);
$bad = []; $n = 0; $pick = $sample; shuffle($pick);
foreach (array_slice($pick, 0, 8) as $u) { $s = aiotsa_status($u); $n++; if ($s['error'] === '' && $s['code'] >= 400) $bad[] = [$u . ' (' . $s['code'] . ')', $u]; }
$R['t_sitemap_bad'] = $bad ? aiotsa_r('warn', '%1$d of %2$d sitemap URLs we tested do not load.', [count($bad), $n], 'Update or remove these pages, then rebuild the sitemap.', [], $bad) : aiotsa_r('pass', '%d sitemap URLs tested, all load.', [$n]);
}
function aiotsa_task_variants(&$A) {
$R = &$A['results']; $h = preg_replace('/^www\./', '', strtolower((string) wp_parse_url($A['target'], PHP_URL_HOST)));
if (wp_parse_url($A['target'], PHP_URL_PORT) || strpos($h, '.') === false || filter_var($h, FILTER_VALIDATE_IP)) { $R['t_variants'] = aiotsa_skip('Not tested on a local or test address.'); $R['t_chain'] = aiotsa_skip('Not tested on a local or test address.'); return; }
$final = []; $maxchain = 0; $errs = 0;
foreach (['http://' . $h . '/', 'http://www.' . $h . '/', 'https://' . $h . '/', 'https://www.' . $h . '/'] as $u) { $r = aiotsa_fetch($u, ['method' => 'GET', 'timeout' => 8, 'max' => 2000]); if ($r['error'] !== '' && !$r['chain']) { $errs++; continue; } $final[] = untrailingslashit($r['url']); $maxchain = max($maxchain, count($r['chain']) - 1); }
if (!$final) { $R['t_variants'] = aiotsa_skip('Could not reach the site.'); $R['t_chain'] = aiotsa_skip('Could not reach the site.'); return; }
$u = array_unique($final);
$R['t_variants'] = count($u) === 1 ? aiotsa_r('pass', 'Every version leads to %s.', [$u[0]]) : aiotsa_r('warn', 'The www/non-www or http/https versions end at different addresses.', [], 'Redirect all versions to one address.', [], array_map(function ($x) { return [$x, $x]; }, array_values($u)));
$R['t_chain'] = $maxchain <= 1 ? aiotsa_r('pass', 'No chain longer than one step.') : aiotsa_r('warn', 'A redirect takes %d steps.', [$maxchain], 'Redirect straight to the final address in one step.');
}
function aiotsa_task_ssl(&$A) {
$R = &$A['results']; $host = strtolower((string) wp_parse_url($A['target'], PHP_URL_HOST)); $own = aiotsa_is_own($A['target']);
if (stripos($A['summary']['ctx']['home_url'] ?? $A['target'], 'https://') !== 0) { $R['t_ssl'] = aiotsa_skip('Not on HTTPS.'); return; }
$ip = $host; if (!$own) { $ips = aiotsa_resolve($host); if (!$ips) { $R['t_ssl'] = aiotsa_skip('Could not check: %s', ['private or unresolved host']); return; } $ip = $ips[0]; }
$ctx = stream_context_create(['ssl' => ['capture_peer_cert' => true, 'verify_peer' => false, 'verify_peer_name' => false, 'peer_name' => $host, 'SNI_enabled' => true]]);
$s = @stream_socket_client('ssl://' . $ip . ':443', $en, $es, 8, STREAM_CLIENT_CONNECT, $ctx); // phpcs:ignore WordPress.PHP.NoSilencedErrors
if (!$s) { $R['t_ssl'] = aiotsa_skip('Could not check: %s', [$es ?: 'connection failed']); return; }
$p = stream_context_get_params($s); fclose($s); $c = isset($p['options']['ssl']['peer_certificate']) && function_exists('openssl_x509_parse') ? openssl_x509_parse($p['options']['ssl']['peer_certificate']) : null; // phpcs:ignore WordPress.WP.AlternativeFunctions
if (!$c || empty($c['validTo_time_t'])) { $R['t_ssl'] = aiotsa_skip('Could not read the certificate.'); return; }
$days = (int) floor(($c['validTo_time_t'] - time()) / 86400); $A['summary']['ctx']['ssl_days'] = $days; $iss = $c['issuer']['O'] ?? ($c['issuer']['CN'] ?? '');
$R['t_ssl'] = $days < 0 ? aiotsa_r('fail', 'The certificate has expired.', [], 'Renew it in your hosting panel now.') : ($days <= 14 ? aiotsa_r('warn', 'Expires in %1$d days (issued by %2$s).', [$days, $iss], 'Check that auto-renew is on.') : aiotsa_r('pass', 'Valid for %1$d more days (issued by %2$s).', [$days, $iss]));
}
function aiotsa_task_dns(&$A) {
$R = &$A['results']; $d = aiotsa_root_domain((string) wp_parse_url($A['target'], PHP_URL_HOST));
$txt = aiotsa_dns($d, DNS_TXT); if ($txt === null) { foreach (['d_spf', 'd_dmarc', 'd_mx'] as $k) $R[$k] = aiotsa_skip('DNS lookups are not available on this server.'); return; }
$spf = false; foreach ($txt as $t) if (stripos($t['txt'] ?? '', 'v=spf1') === 0) $spf = true;
$mx = aiotsa_dns($d, DNS_MX) ?: [];
$R['d_mx'] = $mx ? aiotsa_r('pass', '%d mail server(s) found.', [count($mx)]) : aiotsa_r('info', 'No MX records: this domain does not receive e-mail.');
$R['d_spf'] = $spf ? aiotsa_r('pass', 'Found.') : aiotsa_r('warn', 'Not found: e-mail from your site may land in spam.', [], 'Add an SPF TXT record at your domain provider.');
$dm = aiotsa_dns('_dmarc.' . $d, DNS_TXT) ?: []; $has = false; foreach ($dm as $t) if (stripos($t['txt'] ?? '', 'v=DMARC1') === 0) $has = true;
$R['d_dmarc'] = $has ? aiotsa_r('pass', 'Found.') : aiotsa_r('warn', 'Not found: contact form e-mails may land in spam.', [], 'Add a DMARC TXT record at your domain provider.');
}
/** Host details of the audited site. No outside service is contacted: the IP comes from a normal DNS lookup of the site's own name. */
function aiotsa_task_hostinfo(&$A) {
$R = &$A['results']; $host = strtolower((string) wp_parse_url($A['target'], PHP_URL_HOST)); $ip = gethostbyname($host);
$R['d_host'] = aiotsa_r('info', 'IP %1$s. Server: %2$s. CDN: %3$s.', [$ip, ($A['summary']['ctx']['server'] ?? '') ?: '-', ($A['summary']['ctx']['cdn'] ?? '') ?: '-']);
$R['c_safe'] = aiotsa_r('info', 'Open the Google Safe Browsing page for this site to see its status.', [], '', [], [['Google Safe Browsing', 'https://transparencyreport.google.com/safe-browsing/search?url=' . rawurlencode($host)]]);
}
function aiotsa_task_files(&$A) {
$R = &$A['results']; $C = &$A['summary']['ctx']; $o = aiotsa_origin($A['target']); $bad = [];
$r = aiotsa_fetch($o . '/wp-content/debug.log', ['timeout' => 7, 'max' => 3000]); if ($r['code'] === 200 && preg_match('/PHP (Warning|Notice|Fatal|Deprecated)|\[\d{2}-\w{3}-\d{4}/', $r['body'])) $bad[] = ['debug.log is public', $o . '/wp-content/debug.log'];
$r = aiotsa_fetch($o . '/wp-content/uploads/', ['timeout' => 7, 'max' => 5000]); if ($r['code'] === 200 && stripos($r['body'], 'Index of') !== false) $bad[] = ['Directory listing is on for /wp-content/uploads/', $o . '/wp-content/uploads/'];
$r = aiotsa_fetch($o . '/.env', ['timeout' => 7, 'max' => 2000]); if ($r['code'] === 200 && preg_match('/^[A-Z_]+=.+/m', $r['body']) && stripos($r['body'], ' 7, 'max' => 2000]); if ($r['code'] === 200 && strpos($r['body'], 'DB_PASSWORD') !== false) $bad[] = ['wp-config.php.bak is public', $o . '/wp-config.php.bak'];
$R['c_files'] = $bad ? aiotsa_r('fail', '%d sensitive file(s) can be opened by anyone.', [count($bad)], 'Delete them or block them in .htaccess.', [], $bad) : aiotsa_r('pass', 'debug.log, .env, backups and directory listing are closed.');
$r = aiotsa_fetch($o . '/ads.txt', ['timeout' => 7, 'max' => 100000]); $ok = $r['code'] === 200 && stripos(aiotsa_hdr($r, 'content-type'), 'html') === false && trim($r['body']) !== '';
if (!$ok) $R['a_adstxt'] = aiotsa_r('warn', 'No ads.txt yet. This is normal before approval.', [], 'Add it once you have your AdSense publisher ID.');
else { $good = preg_match_all('/^[a-z0-9.-]+\s*,\s*[^,\s]+\s*,\s*(DIRECT|RESELLER)/mi', $r['body']); $R['a_adstxt'] = $good ? aiotsa_r('pass', 'Found with %d valid line(s).', [$good]) : aiotsa_r('warn', 'Found, but no line has the right format.', [], 'Use the line AdSense gives you: google.com, pub-XXXX, DIRECT, f08c47fec0942fa0'); }
$r = aiotsa_fetch($o . '/llms.txt', ['timeout' => 7, 'max' => 300000]); $ok = $r['code'] === 200 && stripos(aiotsa_hdr($r, 'content-type'), 'html') === false && trim($r['body']) !== ''; $C['llms'] = $ok;
if (!$ok) $R['i_llms'] = aiotsa_r('warn', 'Not found. It is a new, optional file that tells AI services which pages matter.', [], 'Create one with the llms.txt generator in this plugin.');
else { $h1 = preg_match('/^#\s+\S/m', $r['body']); $links = preg_match_all('/\[[^\]]+\]\([^)]+\)/', $r['body']); $R['i_llms'] = $h1 && $links ? aiotsa_r('pass', 'Found with a title and %d links.', [$links]) : aiotsa_r('warn', 'Found, but it needs a "# Title" line and markdown links.', [], 'Rebuild it with the llms.txt generator.'); }
$r = aiotsa_fetch($o . '/aiotsa-missing-page-' . wp_rand(10000, 99999) . '/', ['timeout' => 8, 'max' => 3000]);
$R['t_404'] = $r['error'] !== '' ? aiotsa_skip('Could not check: %s', [$r['error']]) : ($r['code'] === 404 || $r['code'] === 410 ? aiotsa_r('pass', 'A missing page answers with 404.') : aiotsa_r('warn', 'A missing page answers with HTTP %d instead of 404.', [$r['code']], 'Set up a proper 404 page so search engines do not index empty pages.'));
}
function aiotsa_task_psi(&$A) {
$R = &$A['results']; $key = aiotsa_key('psi');
if ($key === '') { foreach (['s_psi_m', 's_psi_d', 's_lcp', 's_cls', 's_inp'] as $k) $R[$k] = aiotsa_skip('Add the free Google PageSpeed key in the API Keys tab to see this.'); return; }
foreach (['mobile' => 's_psi_m', 'desktop' => 's_psi_d'] as $st => $id) {
$r = wp_remote_get('https://www.googleapis.com/pagespeedonline/v5/runPagespeed?' . http_build_query(['url' => $A['summary']['ctx']['home_url'] ?? $A['target'], 'strategy' => $st, 'category' => 'performance', 'key' => $key]), ['timeout' => 60]);
$j = is_wp_error($r) ? null : json_decode(wp_remote_retrieve_body($r), true);
if (!is_array($j) || !isset($j['lighthouseResult']['categories']['performance']['score'])) { $why = is_wp_error($r) ? $r->get_error_message() : ($j['error']['message'] ?? 'no result'); $R[$id] = aiotsa_skip('Google PageSpeed did not answer: %s', [mb_substr($why, 0, 140)]); if ($st === 'mobile') foreach (['s_lcp', 's_cls', 's_inp'] as $k) $R[$k] = aiotsa_skip('Google PageSpeed did not answer: %s', [mb_substr($why, 0, 140)]); continue; }
$sc = (int) round($j['lighthouseResult']['categories']['performance']['score'] * 100); $A['summary']['ctx']['psi_' . $st] = $sc;
$R[$id] = aiotsa_r($sc >= 90 ? 'pass' : ($sc >= 50 ? 'warn' : 'fail'), '%d of 100.', [$sc], $sc >= 90 ? '' : 'See the Speed checks in this report, then test again.');
if ($st !== 'mobile') continue; $au = $j['lighthouseResult']['audits'] ?? []; $fd = $j['loadingExperience']['metrics'] ?? [];
$lcp = isset($fd['LARGEST_CONTENTFUL_PAINT_MS']['percentile']) ? $fd['LARGEST_CONTENTFUL_PAINT_MS']['percentile'] / 1000 : (($au['largest-contentful-paint']['numericValue'] ?? 0) / 1000);
$R['s_lcp'] = aiotsa_r($lcp <= 2.5 ? 'pass' : ($lcp <= 4 ? 'warn' : 'fail'), '%s s. Under 2.5 s is good.', [number_format($lcp, 1)], $lcp <= 2.5 ? '' : 'Compress the largest image at the top of the page and preload it.');
$cls = isset($fd['CUMULATIVE_LAYOUT_SHIFT_SCORE']['percentile']) ? $fd['CUMULATIVE_LAYOUT_SHIFT_SCORE']['percentile'] / 100 : ($au['cumulative-layout-shift']['numericValue'] ?? 0);
$R['s_cls'] = aiotsa_r($cls <= 0.1 ? 'pass' : ($cls <= 0.25 ? 'warn' : 'fail'), '%s. Under 0.1 is good.', [number_format($cls, 2)], $cls <= 0.1 ? '' : 'Set width and height on images and ads so the page does not jump.');
if (isset($fd['INTERACTION_TO_NEXT_PAINT']['percentile'])) { $inp = (int) $fd['INTERACTION_TO_NEXT_PAINT']['percentile']; $R['s_inp'] = aiotsa_r($inp <= 200 ? 'pass' : ($inp <= 500 ? 'warn' : 'fail'), '%d ms. Under 200 ms is good.', [$inp], $inp <= 200 ? '' : 'Remove or delay heavy scripts.'); }
else $R['s_inp'] = aiotsa_skip('Google has no visitor data for this page yet.');
$R['s_source'] = aiotsa_r('info', isset($fd['LARGEST_CONTENTFUL_PAINT_MS']['percentile']) ? 'LCP, CLS and INP come from real Chrome visitors of the last 28 days (field data). The PageSpeed score is a lab test.' : 'Google has no real-visitor data for this page, so LCP and CLS come from a lab test, like the PageSpeed score.');
$opp = []; foreach (['render-blocking-resources', 'render-blocking-insight', 'unused-css-rules', 'unused-javascript', 'offscreen-images', 'uses-optimized-images', 'modern-image-formats', 'uses-responsive-images', 'image-delivery-insight', 'font-display', 'font-display-insight', 'uses-text-compression', 'uses-long-cache-ttl', 'cache-insight', 'server-response-time', 'total-byte-weight', 'dom-size', 'dom-size-insight', 'third-party-summary', 'third-parties-insight', 'bootup-time'] as $oid) { $o = $au[$oid] ?? null; if (is_array($o) && isset($o['score']) && is_numeric($o['score']) && $o['score'] < 0.9) $opp[] = [mb_substr(wp_strip_all_tags((string) ($o['title'] ?? $oid)), 0, 120) . (!empty($o['displayValue']) ? ' - ' . mb_substr(wp_strip_all_tags((string) $o['displayValue']), 0, 80) : ''), '', '', '']; }
$R['s_psi_opps'] = $opp ? aiotsa_r('info', 'Google PageSpeed lists %d things to improve on the home page (lab test, mobile).', [count($opp)], '', [], $opp) : aiotsa_r('info', 'Google PageSpeed lists nothing major to improve on the home page.');
}
}