*/ public static function groups(): array { return array( 'crawl' => __( 'Crawling & indexing', 'ai-rank-suite' ), 'ai' => __( 'AI discoverability', 'ai-rank-suite' ), 'meta' => __( 'Identity & metadata', 'ai-rank-suite' ), 'perf' => __( 'Performance & delivery', 'ai-rank-suite' ), 'privacy' => __( 'Security & housekeeping', 'ai-rank-suite' ), ); } /** * Run every test. * * @return array */ public static function run(): array { $tests = array_merge( self::crawl_tests(), self::ai_tests(), self::meta_tests(), self::perf_tests(), self::privacy_tests() ); $weights = array( 'fail' => 0, 'warn' => 0.5, 'pass' => 1, 'info' => 1 ); $total = 0; $earned = 0.0; foreach ( $tests as $test ) { if ( 'info' === $test['status'] ) { continue; } $weight = (int) $test['weight']; $total += $weight; $earned += $weight * $weights[ $test['status'] ]; } return array( 'ran_at' => time(), 'score' => $total > 0 ? (int) round( $earned / $total * 100 ) : 0, 'groups' => self::groups(), 'tests' => $tests, /* * Four statuses, four counts. * * `info` was left out, and the screen breaks the run down into * failing, worth fixing and passing beside a subtitle giving the * total. Those three did not add up to it: three readings — response * time, pages on noindex, unpublished drafts — were counted nowhere, * so the row silently lost them and the reader had no way to see * where the difference went. They score nothing, by design; that is * a separate question from whether they are reported. */ 'counts' => array( 'fail' => count( array_filter( $tests, static fn( $t ) => 'fail' === $t['status'] ) ), 'warn' => count( array_filter( $tests, static fn( $t ) => 'warn' === $t['status'] ) ), 'pass' => count( array_filter( $tests, static fn( $t ) => 'pass' === $t['status'] ) ), 'info' => count( array_filter( $tests, static fn( $t ) => 'info' === $t['status'] ) ), ), ); } /** @return array> */ private static function crawl_tests(): array { $out = array(); $public = (int) get_option( 'blog_public' ); $out[] = self::t( 'blog_public', 'crawl', $public ? 'pass' : 'fail', 5, __( 'Search engine visibility', 'ai-rank-suite' ), $public ? __( 'The site asks to be indexed.', 'ai-rank-suite' ) : __( 'Settings → Reading is discouraging search engines.', 'ai-rank-suite' ), __( 'Nothing this plugin emits can override it. Uncheck "Discourage search engines" in Settings → Reading.', 'ai-rank-suite' ) ); $permalinks = (string) get_option( 'permalink_structure' ); $out[] = self::t( 'permalinks', 'crawl', '' === $permalinks ? 'fail' : 'pass', 4, __( 'Pretty permalinks', 'ai-rank-suite' ), '' === $permalinks ? __( 'Permalinks are set to Plain.', 'ai-rank-suite' ) : $permalinks, __( 'Plain permalinks break /llms.txt and the XML sitemap, and produce URLs no human or model can read. Settings → Permalinks, anything but Plain.', 'ai-rank-suite' ) ); // robots.txt is read over HTTP rather than guessed from the filesystem, // because a physical file, a plugin filter and a server rule all end up // in the same place and only the response tells the truth. $robots = self::fetch( home_url( '/robots.txt' ) ); if ( null === $robots ) { $out[] = self::t( 'robots_reachable', 'crawl', 'warn', 3, __( 'robots.txt reachable', 'ai-rank-suite' ), __( 'Could not be fetched from this server.', 'ai-rank-suite' ), __( 'Open it in a browser. If it 404s, flush your permalinks; if it times out, the site may be blocking its own loopback requests.', 'ai-rank-suite' ) ); } else { // Only a bare "Disallow: /" under "User-agent: *" closes the site. // Scanning the whole file for that line flags every deliberately // blocked scraper — this plugin writes three of them itself — and // tells the owner their site is invisible when it is not. A test // that cries wolf is a test people learn to ignore. $rules = self::parse_robots( $robots ); $blocks_all = in_array( '/', (array) ( $rules['*'] ?? array() ), true ); $out[] = self::t( 'robots_blocks', 'crawl', $blocks_all ? 'fail' : 'pass', 5, __( 'robots.txt does not block the whole site', 'ai-rank-suite' ), $blocks_all ? __( 'A bare "Disallow: /" is present.', 'ai-rank-suite' ) : __( 'No site-wide block.', 'ai-rank-suite' ), __( 'One line closes the entire site to every crawler. Edit it under Advanced → robots.txt.', 'ai-rank-suite' ) ); $has_sitemap = false !== stripos( $robots, 'sitemap:' ); $out[] = self::t( 'robots_sitemap', 'crawl', $has_sitemap ? 'pass' : 'warn', 2, __( 'Sitemap declared in robots.txt', 'ai-rank-suite' ), $has_sitemap ? __( 'Declared.', 'ai-rank-suite' ) : __( 'No Sitemap: line.', 'ai-rank-suite' ), __( 'It is how a crawler that has never seen your site finds the full URL list on its first visit.', 'ai-rank-suite' ) ); } $sitemap = self::fetch( home_url( '/sitemap_index.xml' ) ) ?? self::fetch( home_url( '/wp-sitemap.xml' ) ); $out[] = self::t( 'sitemap', 'crawl', null !== $sitemap && str_contains( $sitemap, '<' ) ? 'pass' : 'warn', 4, __( 'XML sitemap responds', 'ai-rank-suite' ), null !== $sitemap ? __( 'Served and parses as XML.', 'ai-rank-suite' ) : __( 'No sitemap answered at the usual paths.', 'ai-rank-suite' ), __( 'Enable the Sitemaps module, or point the check at your own sitemap if another plugin owns it.', 'ai-rank-suite' ) ); $https = is_ssl() || str_starts_with( (string) get_option( 'home' ), 'https://' ); $out[] = self::t( 'https', 'crawl', $https ? 'pass' : 'fail', 4, 'HTTPS', $https ? __( 'The site URL is https.', 'ai-rank-suite' ) : __( 'The site URL is still http.', 'ai-rank-suite' ), __( 'HTTPS has been a ranking signal for a decade, and several AI crawlers skip plain HTTP entirely.', 'ai-rank-suite' ) ); return $out; } /** @return array> */ private static function ai_tests(): array { $out = array(); $llms = self::fetch( home_url( '/llms.txt' ) ); $out[] = self::t( 'llms_txt', 'ai', null !== $llms && '' !== trim( (string) $llms ) ? 'pass' : 'warn', 4, __( '/llms.txt is served', 'ai-rank-suite' ), null !== $llms ? sprintf( /* translators: %d: byte count. */ __( 'Served, %d bytes.', 'ai-rank-suite' ), strlen( (string) $llms ) ) : __( 'Nothing answered at /llms.txt.', 'ai-rank-suite' ), __( 'This is the file that tells an assistant what your site is and which pages matter. Without it, it has to guess from whatever it happened to crawl.', 'ai-rank-suite' ) ); $blocked = self::blocked_ai_agents(); $out[] = self::t( 'ai_crawlers', 'ai', empty( $blocked ) ? 'pass' : 'warn', 3, __( 'AI crawlers are not blocked', 'ai-rank-suite' ), empty( $blocked ) ? __( 'No AI user agent is disallowed.', 'ai-rank-suite' ) : sprintf( /* translators: %s: comma separated agent list. */ __( 'Blocked: %s', 'ai-rank-suite' ), implode( ', ', $blocked ) ), __( 'Blocking GPTBot or ClaudeBot removes you from the answers those assistants give. That can be a deliberate choice — it should not be an accident.', 'ai-rank-suite' ) ); $schema_on = ! in_array( 'schema', (array) get_option( 'airanksuite_disabled_modules', array() ), true ); $out[] = self::t( 'schema_module', 'ai', $schema_on ? 'pass' : 'warn', 3, __( 'Structured data is being emitted', 'ai-rank-suite' ), $schema_on ? __( 'The Schema module is active.', 'ai-rank-suite' ) : __( 'The Schema module is switched off.', 'ai-rank-suite' ), __( 'JSON-LD is the only part of a page a model reads without having to interpret it. Everything else is prose it has to trust.', 'ai-rank-suite' ) ); $local = get_option( 'airanksuite_local_seo_settings', array() ); $out[] = self::t( 'entity', 'ai', ! empty( $local['enabled'] ) && '' !== trim( (string) ( $local['name'] ?? '' ) ) ? 'pass' : 'warn', 2, __( 'The site declares who it is', 'ai-rank-suite' ), ! empty( $local['enabled'] ) ? __( 'A business entity is published.', 'ai-rank-suite' ) : __( 'No organisation or business entity is published.', 'ai-rank-suite' ), __( 'An assistant asked "who are they" needs a named entity with an address or a set of linked profiles. Local SEO publishes it.', 'ai-rank-suite' ) ); return $out; } /** @return array> */ private static function meta_tests(): array { $out = array(); $tagline = trim( (string) get_option( 'blogdescription' ) ); $default = 'Just another WordPress site'; $out[] = self::t( 'tagline', 'meta', '' === $tagline || strtolower( $tagline ) === strtolower( $default ) ? 'fail' : 'pass', 3, __( 'The tagline describes the site', 'ai-rank-suite' ), '' === $tagline ? __( 'Empty.', 'ai-rank-suite' ) : $tagline, __( 'It is the one-line answer to "what is this site", it appears in title templates, and it ships with every WordPress install saying nothing.', 'ai-rank-suite' ) ); $out[] = self::t( 'site_title', 'meta', '' !== trim( (string) get_option( 'blogname' ) ) ? 'pass' : 'fail', 3, __( 'The site has a name', 'ai-rank-suite' ), (string) get_option( 'blogname' ), __( 'Settings → General.', 'ai-rank-suite' ) ); $icon = (int) get_option( 'site_icon' ); $out[] = self::t( 'favicon', 'meta', $icon > 0 ? 'pass' : 'warn', 1, __( 'Site icon is set', 'ai-rank-suite' ), $icon > 0 ? __( 'Set.', 'ai-rank-suite' ) : __( 'None.', 'ai-rank-suite' ), __( 'Google shows it beside every one of your results on mobile. Without one you get a generic globe.', 'ai-rank-suite' ) ); $front = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; if ( $front > 0 ) { $desc = (string) get_post_meta( $front, '_airanksuite_seo_desc', true ); $out[] = self::t( 'home_description', 'meta', '' !== trim( $desc ) ? 'pass' : 'warn', 3, __( 'The home page has its own meta description', 'ai-rank-suite' ), '' !== trim( $desc ) ? __( 'Set.', 'ai-rank-suite' ) : __( 'Falling back to generated text.', 'ai-rank-suite' ), __( 'The home page is the result most people see first and the one an assistant quotes when asked about the site as a whole. It deserves a written sentence, not a fallback.', 'ai-rank-suite' ) ); } global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $uncategorised = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->terms} WHERE slug = %s", 'uncategorized' ) ); $out[] = self::t( 'default_category', 'meta', $uncategorised > 0 ? 'warn' : 'pass', 1, __( 'Default category renamed', 'ai-rank-suite' ), $uncategorised > 0 ? __( 'The "Uncategorized" category still exists.', 'ai-rank-suite' ) : __( 'Renamed or removed.', 'ai-rank-suite' ), __( 'It becomes an indexable archive page whose name tells a reader and a model nothing.', 'ai-rank-suite' ) ); return $out; } /** @return array> */ private static function perf_tests(): array { $out = array(); $start = microtime( true ); $response = self::fetch( home_url( '/' ) ); $ms = (int) round( ( microtime( true ) - $start ) * 1000 ); $out[] = self::t( 'ttfb', 'perf', null === $response ? 'info' : ( $ms < 800 ? 'pass' : ( $ms < 2000 ? 'warn' : 'fail' ) ), 3, __( 'Home page response time', 'ai-rank-suite' ), null === $response /* translators: no measurement possible. */ ? __( 'Could not measure from this server.', 'ai-rank-suite' ) /* translators: %d: milliseconds. */ : sprintf( __( '%d ms, measured from this server.', 'ai-rank-suite' ), $ms ), __( 'This is a loopback request, so it excludes the network — treat it as a floor, not as what a visitor experiences.', 'ai-rank-suite' ) ); $cache = wp_using_ext_object_cache(); $out[] = self::t( 'object_cache', 'perf', $cache ? 'pass' : 'warn', 2, __( 'Persistent object cache', 'ai-rank-suite' ), $cache ? __( 'Active.', 'ai-rank-suite' ) : __( 'None.', 'ai-rank-suite' ), __( 'Optional below roughly 10,000 posts. Above it, this is the cheapest speed-up available.', 'ai-rank-suite' ) ); $cron = ! ( defined( 'DISABLE_WP_CRON' ) && constant( 'DISABLE_WP_CRON' ) ); $out[] = self::t( 'cron', 'perf', $cron ? 'pass' : 'warn', 2, 'WP-Cron', $cron ? __( 'Enabled.', 'ai-rank-suite' ) : __( 'DISABLE_WP_CRON is set.', 'ai-rank-suite' ), __( 'Scheduled audits, alerts and sitemap pings depend on it. Disabling it is fine only if a real cron job calls wp-cron.php.', 'ai-rank-suite' ) ); $out[] = self::t( 'php', 'perf', version_compare( PHP_VERSION, '8.1', '>=' ) ? 'pass' : 'fail', 2, 'PHP', PHP_VERSION, __( 'Below 8.1 this plugin will not run at all, and an unsupported PHP version stops receiving security fixes.', 'ai-rank-suite' ) ); return $out; } /** @return array> */ private static function privacy_tests(): array { $out = array(); global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching // Published pages of the eligible types (Support\Inventory) — the same // population every other counter uses; drafts likewise from the inventory. $counts = \AiRankSuite\Support\Inventory::counts(); $noindexed = max( 0, (int) $counts['published'] - (int) $counts['indexable'] ); $out[] = self::t( 'noindex_pages', 'privacy', 'info', 1, __( 'Pages set to noindex', 'ai-rank-suite' ), /* translators: %d: number of pages. */ sprintf( _n( '%d page.', '%d pages.', $noindexed, 'ai-rank-suite' ), $noindexed ), __( 'Deliberate for a thank-you page, expensive on anything you want found. Worth a glance after a bulk edit.', 'ai-rank-suite' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $drafts = (int) $counts['drafts']; $out[] = self::t( 'drafts', 'privacy', 'info', 1, __( 'Unpublished drafts', 'ai-rank-suite' ), /* translators: %d: number of drafts. */ sprintf( _n( '%d draft.', '%d drafts.', $drafts, 'ai-rank-suite' ), $drafts ), __( 'Not a fault. Listed because a finished draft nobody published is the cheapest content a site owns.', 'ai-rank-suite' ) ); $out[] = self::t( 'file_edit', 'privacy', defined( 'DISALLOW_FILE_EDIT' ) && constant( 'DISALLOW_FILE_EDIT' ) ? 'pass' : 'warn', 1, __( 'Theme and plugin file editor disabled', 'ai-rank-suite' ), defined( 'DISALLOW_FILE_EDIT' ) && constant( 'DISALLOW_FILE_EDIT' ) ? __( 'Disabled.', 'ai-rank-suite' ) : __( 'Enabled.', 'ai-rank-suite' ), __( 'Add define( \'DISALLOW_FILE_EDIT\', true ); to wp-config.php. It turns a stolen admin password from a full server compromise into a nuisance.', 'ai-rank-suite' ) ); return $out; } /** * AI user agents currently disallowed in robots.txt. * * @return array */ private static function blocked_ai_agents(): array { $robots = self::fetch( home_url( '/robots.txt' ) ); if ( null === $robots ) { return array(); } $rules = self::parse_robots( $robots ); $agents = array( 'GPTBot', 'ChatGPT-User', 'ClaudeBot', 'anthropic-ai', 'PerplexityBot', 'Google-Extended', 'CCBot', 'Applebot-Extended' ); $blocked = array(); foreach ( $agents as $agent ) { // An agent blocked by its own name, or caught by a site-wide block. $own = (array) ( $rules[ strtolower( $agent ) ] ?? array() ); if ( in_array( '/', $own, true ) || in_array( '/', (array) ( $rules['*'] ?? array() ), true ) ) { $blocked[] = $agent; } } return $blocked; } /** * robots.txt as user-agent => disallowed paths. * * One directive can carry several agents ("User-agent: A" followed * immediately by "User-agent: B" then one Disallow applies to both), which * is why agents accumulate until the first rule line closes the group. * * @return array> */ private static function parse_robots( string $robots ): array { $rules = array(); $current = array(); $fresh = true; foreach ( preg_split( '/\r\n|\r|\n/', $robots ) ?: array() as $line ) { $line = trim( (string) preg_replace( '/#.*$/', '', (string) $line ) ); if ( '' === $line || ! str_contains( $line, ':' ) ) { continue; } list( $field, $value ) = array_map( 'trim', explode( ':', $line, 2 ) ); $field = strtolower( $field ); if ( 'user-agent' === $field ) { if ( ! $fresh ) { $current = array(); $fresh = true; } $current[] = strtolower( $value ); continue; } if ( 'disallow' === $field && ! empty( $current ) ) { $fresh = false; foreach ( $current as $agent ) { // An empty Disallow means "nothing is disallowed" and must // not be recorded as a path. if ( '' !== $value ) { $rules[ $agent ][] = $value; } } } } return $rules; } /** * Fetch a URL from this site, or null. * * Loopback requests fail on plenty of hosts, and a failed fetch must read * as "unknown" rather than as "broken" — a test that cries wolf about the * server's own firewall is a test people learn to ignore. */ private static function fetch( string $url ): ?string { $response = wp_remote_get( $url, array( 'timeout' => 8, 'headers' => array( 'User-Agent' => 'AI Rank Suite Site Test/' . AIRANKSUITE_VERSION ), ) ); if ( is_wp_error( $response ) || (int) wp_remote_retrieve_response_code( $response ) >= 400 ) { return null; } return (string) wp_remote_retrieve_body( $response ); } /** * @return array */ private static function t( string $id, string $group, string $status, int $weight, string $label, string $value, string $fix ): array { return compact( 'id', 'group', 'status', 'weight', 'label', 'value', 'fix' ); } }