0, 'remaining' => -1, ); } $budget = (int) apply_filters( 'aeoora_scan_time_budget', 40 ); $start = microtime( true ); $scanned = 0; $args = array( 'post_type' => self::post_types(), 'post_status' => 'publish', 'has_password' => false, 'posts_per_page' => 50, 'fields' => 'ids', 'orderby' => 'ID', 'order' => 'ASC', 'no_found_rows' => true, 'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery array( 'key' => '_aeoora_score', 'compare' => 'NOT EXISTS', ), ), ); try { do { $ids = get_posts( $args ); Aeoora_Content::in_batch( static function () use ( $ids, $start, $budget, &$scanned ) { foreach ( $ids as $id ) { if ( microtime( true ) - $start > $budget ) { return; } self::score_post( $id, 'content' ); $scanned++; } } ); } while ( count( $ids ) === 50 && microtime( true ) - $start <= $budget ); $left = get_posts( array_merge( $args, array( 'posts_per_page' => 1 ) ) ); $remaining = count( $left ); } finally { Aeoora_Util::unlock( 'scan_site' ); } update_option( 'aeoora_scan_site_last', array( 'at' => time(), 'scanned' => $scanned, 'done' => 0 === $remaining, ), false ); if ( $remaining && ! wp_next_scheduled( 'aeoora_scan_site' ) ) { wp_schedule_single_event( time() + 2 * MINUTE_IN_SECONDS, 'aeoora_scan_site' ); } return array( 'scanned' => $scanned, 'remaining' => $remaining, ); } /** * Cron callback for a debounced score. * * @param int $post_id Post ID. */ public static function score_scheduled( $post_id ) { $post = get_post( (int) $post_id ); if ( $post && 'publish' === $post->post_status ) { self::score_post( $post, 'content' ); } } /** * Score on save (fast mode: no loopback render). * * @param int $post_id Post ID. * @param WP_Post $post Post. */ public static function on_save( $post_id, $post ) { if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) || 'publish' !== $post->post_status || '' !== $post->post_password ) { return; } if ( ! in_array( $post->post_type, self::post_types(), true ) ) { return; } // Never slow down saves, imports or bulk edits: score in the background, once. if ( ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) || ( defined( 'WP_CLI' ) && WP_CLI ) || isset( $_REQUEST['bulk_edit'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification return; } // One shared, size-capped queue instead of one cron event per post: a // 10,000-product import must not add 10,000 entries to the cron option. Aeoora_Queue::push( 'score', (int) $post_id ); } /** * Post types audited. * * @return array */ public static function post_types() { $types = array_unique( array_merge( (array) Aeoora_Settings::get( 'suggestions', 'post_types', array() ), (array) Aeoora_Settings::get( 'markdown', 'post_types', array() ) ) ); return array_values( array_filter( $types, 'post_type_exists' ) ); } /** * Score a post and store the result. * * @param WP_Post|int $post Post. * @param string|null $mode Render mode. * @param string|null $html Optional HTML to analyze (unsaved editor content). * @return array Result. */ public static function score_post( $post, $mode = null, $html = null ) { $post = get_post( $post ); if ( ! $post ) { return array(); } $save = null === $html; if ( $save ) { $html = Aeoora_Content::render_html( $post, $mode ); } $result = self::analyze( $html, $post ); if ( $save ) { update_post_meta( $post->ID, '_aeoora_score', (int) $result['score'] ); update_post_meta( $post->ID, '_aeoora_checks', array( 'at' => time(), 'words' => $result['stats']['words'], 'checks' => array_map( static function ( $c ) { return array( $c['id'], $c['status'], $c['points'] ); }, $result['checks'] ), ) ); } return $result; } /** * Analyze HTML content (24 checks, 100 points). * * @param string $html Content HTML. * @param WP_Post $post Post. * @return array { score, grade, checks[], stats } */ public static function analyze( $html, WP_Post $post ) { $d = self::parse( (string) $html, $post ); $c = array(); $words = $d['words']; /* ---------- Structure ---------- */ $first = $d['first_p_words']; $lead = $d['first_sentence_words']; if ( $first >= 30 && $first <= 70 && $lead && $lead <= 30 ) { $c[] = self::check( 'answer_first', 12, 'pass', __( 'Answer-first intro', 'aeoora' ), sprintf( /* translators: %d: words. */ __( 'Opens with a %d-word answer paragraph that AI engines can quote.', 'aeoora' ), $first ) ); } elseif ( $d['has_takeaways'] || ( $first >= 20 && $first <= 100 ) ) { $c[] = self::check( 'answer_first', 12, 'warn', __( 'Answer-first intro', 'aeoora' ), $lead > 30 ? sprintf( /* translators: %d: words. */ __( 'The opening sentence runs %d words. Lead with a short, direct answer sentence.', 'aeoora' ), $lead ) : sprintf( /* translators: %d: words. */ __( 'The opening paragraph has %d words; 40–60 words that answer the question directly works best.', 'aeoora' ), $first ), __( 'Rewrite the first paragraph as a 40–60 word direct answer that names the topic.', 'aeoora' ), 'intro', 0.5 ); } else { $c[] = self::check( 'answer_first', 12, 'fail', __( 'Answer-first intro', 'aeoora' ), $first > 100 ? sprintf( /* translators: %d: words. */ __( 'The first paragraph runs %d words before getting to the point.', 'aeoora' ), $first ) : __( 'No clear answer paragraph at the top of the page.', 'aeoora' ), __( 'Open with a 40–60 word paragraph that directly answers the main question, then expand.', 'aeoora' ), 'intro' ); } $hcount = max( 1, $d['h2'] + $d['h3'] ); $qratio = $d['question_headings'] / $hcount; if ( $d['question_headings'] && $qratio >= 0.25 ) { $c[] = self::check( 'question_headings', 5, 'pass', __( 'Question-style headings', 'aeoora' ), sprintf( /* translators: %d: count. */ _n( '%d heading mirrors a question people ask.', '%d headings mirror questions people ask.', $d['question_headings'], 'aeoora' ), $d['question_headings'] ) ); } else { $c[] = self::check( 'question_headings', 5, $d['question_headings'] ? 'warn' : 'fail', __( 'Question-style headings', 'aeoora' ), __( 'Few H2/H3 headings match how people phrase questions to AI assistants.', 'aeoora' ), __( 'Phrase a quarter or more of your H2/H3s as real questions, each answered in the sentence right after it.', 'aeoora' ), 'headings' ); } $issues = array(); if ( $words > 400 && $d['h2'] < max( 2, (int) floor( $words / 400 ) ) - ( $words > 900 ? 0 : 1 ) ) { $issues[] = __( 'add more H2 sections (about one per 300–400 words)', 'aeoora' ); } if ( $d['h1_in_content'] ) { $issues[] = __( 'remove extra H1 headings inside the content', 'aeoora' ); } if ( $d['skipped_levels'] ) { $issues[] = __( 'do not skip heading levels (H2 → H4)', 'aeoora' ); } $c[] = $issues ? self::check( 'heading_hierarchy', 4, count( $issues ) > 1 ? 'fail' : 'warn', __( 'Heading hierarchy', 'aeoora' ), __( 'The heading outline is hard for machines to follow.', 'aeoora' ), self::sentence( $issues ), 'headings' ) : self::check( 'heading_hierarchy', 4, 'pass', __( 'Heading hierarchy', 'aeoora' ), __( 'Clean H2/H3 outline.', 'aeoora' ) ); $sec = $d['sections']; if ( $sec['count'] < 2 ) { $c[] = self::check( 'self_contained_sections', 5, $words < 400 ? 'warn' : 'fail', __( 'Self-contained sections', 'aeoora' ), __( 'Content is not split into sections that can be lifted on their own.', 'aeoora' ), __( 'Split the article into H2 sections that each answer one sub-question.', 'aeoora' ), 'headings' ); } else { $good = $sec['good'] / $sec['count']; $c[] = $good >= 0.7 ? self::check( 'self_contained_sections', 5, 'pass', __( 'Self-contained sections', 'aeoora' ), sprintf( /* translators: 1: good, 2: total. */ __( '%1$d of %2$d sections stand on their own (right size, direct opening).', 'aeoora' ), $sec['good'], $sec['count'] ) ) : self::check( 'self_contained_sections', 5, 'warn', __( 'Self-contained sections', 'aeoora' ), sprintf( /* translators: 1: good, 2: total. */ __( 'Only %1$d of %2$d sections are 50–450 words and open with a direct, explicit sentence.', 'aeoora' ), $sec['good'], $sec['count'] ), __( 'Start each section with a sentence that answers its heading and names the subject (not “It” or “This”); merge tiny sections.', 'aeoora' ), 'fixes', max( 0.2, $good ) ); } $struct = $d['lists'] + $d['tables']; $c[] = ( $d['lists'] && ( $words < 1200 || $struct >= 2 ) ) || $d['tables'] ? self::check( 'lists_tables', 5, 'pass', __( 'Lists and tables', 'aeoora' ), sprintf( /* translators: 1: number of lists, 2: number of tables. */ __( 'Lists: %1$d, tables: %2$d. Facts are easy to extract.', 'aeoora' ), $d['lists'], $d['tables'] ) ) : self::check( 'lists_tables', 5, $struct ? 'warn' : ( $words < 500 ? 'warn' : 'fail' ), __( 'Lists and tables', 'aeoora' ), __( 'Little structured content. AI answers lean on lists, steps and comparison tables.', 'aeoora' ), __( 'Turn steps, options or comparisons into a numbered list or a table with headers.', 'aeoora' ), 'fixes' ); $c[] = ( $d['p_over_200'] === 0 && $d['p_share_short'] >= 0.9 ) ? self::check( 'concise_paragraphs', 3, 'pass', __( 'Concise paragraphs', 'aeoora' ), __( 'Paragraphs are short and scannable.', 'aeoora' ) ) : self::check( 'concise_paragraphs', 3, $d['p_over_200'] ? 'fail' : 'warn', __( 'Concise paragraphs', 'aeoora' ), sprintf( /* translators: %d: count. */ _n( '%d paragraph is over 120 words.', '%d paragraphs are over 120 words.', $d['p_over_120'], 'aeoora' ), $d['p_over_120'] ), __( 'Keep paragraphs to 2–4 sentences (under ~120 words).', 'aeoora' ), 'fixes' ); $has_faq = (bool) Aeoora_Schema::get_faq( $post->ID ) || $d['faq_markup']; $c[] = $has_faq ? self::check( 'faq', 2, 'pass', __( 'FAQ section', 'aeoora' ), __( 'Has question/answer pairs.', 'aeoora' ) ) : self::check( 'faq', 2, 'warn', __( 'FAQ section', 'aeoora' ), __( 'No FAQ. Optional, but short Q&As match follow-up prompts.', 'aeoora' ), __( 'Add 3–6 real follow-up questions with 30–100 word answers.', 'aeoora' ), 'faq', 0 ); $tldr = '' !== trim( (string) get_post_meta( $post->ID, '_aeoora_tldr', true ) ); $c[] = ( $tldr || $d['has_takeaways'] ) ? self::check( 'key_takeaways', 2, 'pass', __( 'Key takeaways', 'aeoora' ), __( 'Has a summary / key takeaways.', 'aeoora' ) ) : self::check( 'key_takeaways', 2, 'warn', __( 'Key takeaways', 'aeoora' ), __( 'No summary box.', 'aeoora' ), __( 'Add a key takeaway: a 40–60 word summary in the aeoora panel, or a short “Key takeaways” list.', 'aeoora' ), 'tldr', 0 ); $need_int = $words > 800 ? 3 : 1; $c[] = $d['internal_links'] >= $need_int ? self::check( 'internal_links', 2, 'pass', __( 'Internal links', 'aeoora' ), sprintf( /* translators: %d: count. */ _n( '%d internal link.', '%d internal links.', $d['internal_links'], 'aeoora' ), $d['internal_links'] ) ) : self::check( 'internal_links', 2, $d['internal_links'] ? 'warn' : 'fail', __( 'Internal links', 'aeoora' ), __( 'Weakly connected to related pages on your site.', 'aeoora' ), __( 'Add descriptive links to 2–5 related pages.', 'aeoora' ), 'fixes' ); /* ---------- Content ---------- */ $nums = $d['numbers']; $per = $words ? $nums / $words * 1000 : 0; if ( $nums >= 5 && $per >= 3 ) { $c[] = self::check( 'statistics', 9, 'pass', __( 'Statistics and data', 'aeoora' ), sprintf( /* translators: %d: count. */ _n( '%d data point (numbers, percentages, measurements).', '%d data points (numbers, percentages, measurements).', $nums, 'aeoora' ), $nums ) ); } else { $c[] = self::check( 'statistics', 9, $nums ? 'warn' : 'fail', __( 'Statistics and data', 'aeoora' ), sprintf( /* translators: %d: count. */ _n( '%d data point. Adding statistics is one of the strongest measured boosts to AI citation.', '%d data points. Adding statistics is one of the strongest measured boosts to AI citation.', $nums, 'aeoora' ), $nums ), __( 'Add at least 5 specific, sourced figures (about 3 per 1,000 words).', 'aeoora' ), 'fixes', $nums ? min( 0.7, $nums / 5 ) : 0 ); } $ext = $d['external_links']; $c[] = $ext >= 3 ? self::check( 'cited_sources', 7, 'pass', __( 'Cited sources', 'aeoora' ), sprintf( /* translators: %d: count. */ _n( '%d link to an external source.', '%d links to external sources.', $ext, 'aeoora' ), $ext ) ) : self::check( 'cited_sources', 7, $ext ? 'warn' : 'fail', __( 'Cited sources', 'aeoora' ), sprintf( /* translators: %d: count. */ _n( '%d link to an external source.', '%d links to external sources.', $ext, 'aeoora' ), $ext ), __( 'Cite 3+ authoritative sources (studies, official docs, primary data) next to the claims they support.', 'aeoora' ), 'fixes', $ext / 3 ); $c[] = $d['quotes'] ? self::check( 'quotations', 5, 'pass', __( 'Attributed quotations', 'aeoora' ), __( 'Includes a quotation from a named source.', 'aeoora' ) ) : self::check( 'quotations', 5, 'fail', __( 'Attributed quotations', 'aeoora' ), __( 'No expert or source quotes. Quotations measurably raise visibility in generative answers.', 'aeoora' ), __( 'Add a real, attributed quote from a named expert or primary source.', 'aeoora' ), 'fixes' ); $c[] = $d['definition'] ? self::check( 'definitions', 3, 'pass', __( 'Clear definition', 'aeoora' ), __( 'The topic is defined in plain words early on.', 'aeoora' ) ) : self::check( 'definitions', 3, 'warn', __( 'Clear definition', 'aeoora' ), __( 'No “X is…” definitional sentence in the opening paragraphs.', 'aeoora' ), __( 'Define the main topic in one plain sentence near the top (“X is a …”).', 'aeoora' ), 'intro', 0 ); if ( $words >= 800 ) { $c[] = self::check( 'depth', 3, 'pass', __( 'Depth', 'aeoora' ), sprintf( /* translators: %d: words. */ __( '%d words.', 'aeoora' ), $words ) ); } else { $c[] = self::check( 'depth', 3, $words >= 300 ? 'warn' : 'fail', __( 'Depth', 'aeoora' ), sprintf( /* translators: %d: words. */ __( '%d words. Thin pages rarely become the cited source.', 'aeoora' ), $words ), __( 'Cover the question fully: definition, steps, examples, trade-offs.', 'aeoora' ), 'fixes' ); } $avg = $d['avg_sentence']; $c[] = ( $avg && $avg <= 20 && $d['long_sentence_share'] <= 0.15 ) ? self::check( 'readability', 3, 'pass', __( 'Readability', 'aeoora' ), sprintf( /* translators: %s: words. */ __( 'Average sentence: %s words.', 'aeoora' ), number_format_i18n( $avg, 1 ) ) ) : self::check( 'readability', 3, 'warn', __( 'Readability', 'aeoora' ), sprintf( /* translators: %s: words. */ __( 'Average sentence: %s words; many long sentences.', 'aeoora' ), number_format_i18n( $avg, 1 ) ), __( 'Aim for sentences under 20 words and plain vocabulary.', 'aeoora' ), 'fixes' ); $kw = Aeoora_Seo::get_focus_keyword( $post->ID ); if ( '' !== $kw && $words > 100 ) { $hits = substr_count( Aeoora_Util::lower( Aeoora_Util::one_line( $html ) ), Aeoora_Util::lower( $kw ) ); $density = $hits * max( 1, Aeoora_Util::word_count( $kw ) ) / $words * 100; $c[] = $density <= 2.5 ? self::check( 'no_stuffing', 2, 'pass', __( 'Natural keyword use', 'aeoora' ), sprintf( /* translators: %s: percent. */ __( 'Focus keyword density: %s%%.', 'aeoora' ), number_format_i18n( $density, 1 ) ) ) : self::check( 'no_stuffing', 2, 'fail', __( 'Natural keyword use', 'aeoora' ), sprintf( /* translators: %s: percent. */ __( 'Focus keyword density of %s%% looks like keyword stuffing.', 'aeoora' ), number_format_i18n( $density, 1 ) ), __( 'Use synonyms and natural phrasing; keep the focus keyword under 2.5%.', 'aeoora' ), 'fixes' ); } else { $c[] = self::check( 'no_stuffing', 2, 'pass', __( 'Natural keyword use', 'aeoora' ), __( 'No keyword stuffing detected.', 'aeoora' ) ); } if ( 0 === $d['images'] ) { $c[] = self::check( 'images_alt', 2, $words > 600 ? 'warn' : 'pass', __( 'Images with alt text', 'aeoora' ), __( 'No images in the content.', 'aeoora' ), __( 'Add a relevant image, chart or screenshot with descriptive alt text.', 'aeoora' ), '', 0.5 ); } elseif ( $d['images_no_alt'] ) { $c[] = self::check( 'images_alt', 2, 'warn', __( 'Images with alt text', 'aeoora' ), sprintf( /* translators: %d: count. */ _n( '%d image without alt text.', '%d images without alt text.', $d['images_no_alt'], 'aeoora' ), $d['images_no_alt'] ), __( 'Describe every image in its alt text.', 'aeoora' ) ); } else { $c[] = self::check( 'images_alt', 2, 'pass', __( 'Images with alt text', 'aeoora' ), __( 'All images are described.', 'aeoora' ) ); } /* ---------- Trust ---------- */ $modified = (int) get_post_modified_time( 'U', true, $post ); if ( $modified < DAY_IN_SECONDS || '0000-00-00 00:00:00' === $post->post_modified_gmt ) { $modified = (int) get_post_modified_time( 'U', false, $post ); } if ( $modified < DAY_IN_SECONDS || 'publish' !== $post->post_status ) { $modified = max( $modified, time() ); // Unpublished work is current by definition. } $age = max( 0, time() - $modified ) / DAY_IN_SECONDS; $c[] = $age <= 365 ? self::check( 'freshness', 7, 'pass', __( 'Freshness', 'aeoora' ), sprintf( /* translators: %d: days. */ _n( 'Updated %d day ago.', 'Updated %d days ago.', (int) $age, 'aeoora' ), (int) $age ) ) : self::check( 'freshness', 7, $age <= 730 ? 'warn' : 'fail', __( 'Freshness', 'aeoora' ), sprintf( /* translators: %d: days. */ _n( 'Last updated %d day ago. AI engines favor recently updated sources.', 'Last updated %d days ago. AI engines favor recently updated sources.', (int) $age, 'aeoora' ), (int) $age ), __( 'Refresh facts, statistics and examples, then update the post (and show the updated date).', 'aeoora' ), 'fixes' ); $author = get_userdata( $post->post_author ); $named = $author && ! in_array( strtolower( $author->display_name ), array( 'admin', 'administrator', 'wordpress', 'user', 'editor' ), true ); $bio = $author && strlen( trim( (string) $author->description ) ) > 30; $c[] = ( $named && $bio ) ? self::check( 'author', 5, 'pass', __( 'Author byline and bio', 'aeoora' ), __( 'Named author with a biography.', 'aeoora' ) ) : self::check( 'author', 5, $named ? 'warn' : 'fail', __( 'Author byline and bio', 'aeoora' ), $named ? __( 'The author has no biography.', 'aeoora' ) : __( 'Published under a generic account name.', 'aeoora' ), __( 'Publish under a real person with a short bio and credentials (Users → Profile → Biographical Info).', 'aeoora' ) ); $exp = $d['experience']; $c[] = $exp >= 2 ? self::check( 'original_insight', 4, 'pass', __( 'Original insight', 'aeoora' ), __( 'Shows first-hand experience or original data.', 'aeoora' ) ) : self::check( 'original_insight', 4, $exp ? 'warn' : 'fail', __( 'Original insight', 'aeoora' ), __( 'Little first-hand experience, testing or original data.', 'aeoora' ), __( 'Add something only you can provide: test results, your own data, screenshots or a reasoned first-hand opinion.', 'aeoora' ), 'fixes' ); /* ---------- Technical ---------- */ $noindex = Aeoora_Seo::is_noindex( $post->ID ); $will_pub = in_array( $post->post_status, array( 'draft', 'pending', 'future', 'auto-draft' ), true ); $c[] = ! $noindex && ( 'publish' === $post->post_status || $will_pub ) && '' === $post->post_password ? self::check( 'indexable', 4, 'pass', __( 'Indexable and snippet-eligible', 'aeoora' ), $will_pub ? __( 'Will be public and indexable once published.', 'aeoora' ) : __( 'Public, indexable, no password.', 'aeoora' ) ) : self::check( 'indexable', 4, 'fail', __( 'Indexable and snippet-eligible', 'aeoora' ), __( 'This page is noindex, private or password protected, so it cannot be cited.', 'aeoora' ), __( 'Make the page public and indexable if you want AI engines to cite it.', 'aeoora' ) ); $schema = Aeoora_Seo::outputs_schema() || 'off' !== Aeoora_Settings::get( 'schema', 'article', 'auto' ); $c[] = $schema ? self::check( 'structured_data', 3, 'pass', __( 'Article structured data', 'aeoora' ), Aeoora_Seo::outputs_schema() ? sprintf( /* translators: %s: plugin. */ __( 'Provided by %s.', 'aeoora' ), Aeoora_Seo::active_label() ) : __( 'Provided by aeoora.', 'aeoora' ) ) : self::check( 'structured_data', 3, 'fail', __( 'Article structured data', 'aeoora' ), __( 'No Article structured data on this page.', 'aeoora' ), __( 'Turn on Article schema in aeoora → Settings → Schema & meta.', 'aeoora' ) ); $title_len = mb_strlen( Aeoora_Seo::get_title( $post->ID ) ); $c[] = $title_len >= 30 && $title_len <= 65 ? self::check( 'meta_title', 1, 'pass', __( 'SEO title length', 'aeoora' ), sprintf( /* translators: %d: chars. */ __( '%d characters.', 'aeoora' ), $title_len ) ) : self::check( 'meta_title', 1, 'warn', __( 'SEO title length', 'aeoora' ), sprintf( /* translators: %d: chars. */ __( '%d characters (aim for 50–60).', 'aeoora' ), $title_len ), __( 'Write a 50–60 character title that front-loads the topic.', 'aeoora' ), 'meta', 0 ); $desc = Aeoora_Seo::get_description( $post->ID ); $len = mb_strlen( $desc ); $c[] = $len >= 120 && $len <= 165 ? self::check( 'meta_description', 2, 'pass', __( 'Meta description', 'aeoora' ), sprintf( /* translators: %d: chars. */ __( '%d characters.', 'aeoora' ), $len ) ) : self::check( 'meta_description', 2, $len ? 'warn' : 'fail', __( 'Meta description', 'aeoora' ), $len ? sprintf( /* translators: %d: chars. */ __( '%d characters (aim for 140–160).', 'aeoora' ), $len ) : __( 'No meta description.', 'aeoora' ), __( 'Write a 140–160 character description that states the answer, not just the topic.', 'aeoora' ), 'meta' ); $c = apply_filters( 'aeoora_post_checks', $c, $post, $d ); $score = 0; $max = 0; foreach ( $c as $one ) { $score += $one['points']; $max += $one['max']; } $score = $max ? (int) round( $score / $max * 100 ) : 0; unset( $d['headings_list'] ); return array( 'score' => $score, 'grade' => self::grade( $score ), 'checks' => $c, 'stats' => $d, ); } /** * Join issue fragments into a sentence. * * @param array $parts Fragments. * @return string */ private static function sentence( array $parts ) { $s = implode( '; ', $parts ); return Aeoora_Util::upper( mb_substr( $s, 0, 1 ) ) . mb_substr( $s, 1 ) . '.'; } /** * Build a check result. * * @param string $id Id. * @param int $max Max points. * @param string $status pass|warn|fail. * @param string $label Label. * @param string $message Message. * @param string $fix Fix. * @param string $ai AI task that can fix it. * @param float|null $partial Fraction of points for warn/fail. * @return array */ private static function check( $id, $max, $status, $label, $message, $fix = '', $ai = '', $partial = null ) { if ( 'pass' === $status ) { $points = $max; } elseif ( null !== $partial ) { $points = round( $max * max( 0, min( 1, $partial ) ), 1 ); } else { $points = 'warn' === $status ? round( $max * 0.5, 1 ) : 0; } return array( 'id' => $id, 'label' => $label, 'status' => $status, 'points' => $points, 'max' => $max, 'message' => $message, 'fix' => $fix, 'ai' => $ai, ); } /** * Display names of the per-post checks, keyed by check id (for lists that * only store the ids, e.g. "top issues" in the content audit table). * * @return array */ public static function check_labels() { return array( 'answer_first' => __( 'Answer-first intro', 'aeoora' ), 'question_headings' => __( 'Question-style headings', 'aeoora' ), 'heading_hierarchy' => __( 'Heading hierarchy', 'aeoora' ), 'self_contained_sections' => __( 'Self-contained sections', 'aeoora' ), 'lists_tables' => __( 'Lists and tables', 'aeoora' ), 'concise_paragraphs' => __( 'Concise paragraphs', 'aeoora' ), 'faq' => __( 'FAQ section', 'aeoora' ), 'key_takeaways' => __( 'Key takeaways', 'aeoora' ), 'internal_links' => __( 'Internal links', 'aeoora' ), 'statistics' => __( 'Statistics and data', 'aeoora' ), 'cited_sources' => __( 'Cited sources', 'aeoora' ), 'quotations' => __( 'Attributed quotations', 'aeoora' ), 'definitions' => __( 'Clear definition', 'aeoora' ), 'depth' => __( 'Depth', 'aeoora' ), 'readability' => __( 'Readability', 'aeoora' ), 'no_stuffing' => __( 'Natural keyword use', 'aeoora' ), 'images_alt' => __( 'Images with alt text', 'aeoora' ), 'freshness' => __( 'Freshness', 'aeoora' ), 'author' => __( 'Author byline and bio', 'aeoora' ), 'original_insight' => __( 'Original insight', 'aeoora' ), 'indexable' => __( 'Indexable and snippet-eligible', 'aeoora' ), 'structured_data' => __( 'Article structured data', 'aeoora' ), 'meta_title' => __( 'SEO title length', 'aeoora' ), 'meta_description' => __( 'Meta description', 'aeoora' ), ); } /** * Letter grade. * * @param int $score Score. * @return string */ public static function grade( $score ) { if ( $score >= 90 ) { return 'A+'; } if ( $score >= 80 ) { return 'A'; } if ( $score >= 70 ) { return 'B'; } if ( $score >= 55 ) { return 'C'; } if ( $score >= 40 ) { return 'D'; } return 'F'; } /** * Parse HTML into metrics. * * @param string $html HTML. * @param WP_Post $post Post. * @return array */ public static function parse( $html, WP_Post $post ) { $d = array( 'words' => 0, 'first_p_words' => 0, 'first_sentence_words' => 0, 'question_headings' => 0, 'h2' => 0, 'h3' => 0, 'h1_in_content' => 0, 'skipped_levels' => false, 'lists' => 0, 'tables' => 0, 'images' => 0, 'images_no_alt' => 0, 'external_links' => 0, 'internal_links' => 0, 'quotes' => 0, 'numbers' => 0, 'avg_sentence' => 0, 'long_sentence_share' => 0, 'p_over_120' => 0, 'p_over_200' => 0, 'p_share_short' => 1, 'faq_markup' => false, 'has_takeaways' => false, 'definition' => false, 'experience' => 0, 'sections' => array( 'count' => 0, 'good' => 0, ), ); $text = Aeoora_Util::one_line( $html ); $d['words'] = Aeoora_Util::word_count( $text ); if ( '' === trim( (string) $html ) || ! class_exists( 'DOMDocument' ) ) { return $d; } $doc = new DOMDocument(); $prev = libxml_use_internal_errors( true ); $doc->loadHTML( '' . $html . '', LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_PARSEHUGE ); libxml_clear_errors(); libxml_use_internal_errors( $prev ); $xp = new DOMXPath( $doc ); $home_host = preg_replace( '~^www\.~', '', strtolower( (string) wp_parse_url( home_url(), PHP_URL_HOST ) ) ); $last = 1; foreach ( $xp->query( '//h1|//h2|//h3|//h4|//h5|//h6' ) as $h ) { $level = (int) substr( $h->nodeName, 1 ); $t = Aeoora_Util::one_line( $h->textContent ); if ( '' === $t ) { continue; } if ( 1 === $level ) { $d['h1_in_content']++; } elseif ( 2 === $level ) { $d['h2']++; } elseif ( 3 === $level ) { $d['h3']++; } if ( $level > $last + 1 && $last >= 2 ) { $d['skipped_levels'] = true; } $last = $level; if ( $level >= 2 && $level <= 3 && preg_match( self::QUESTION_RE, $t ) ) { $d['question_headings']++; } if ( preg_match( '~(faq|frequently asked|preguntas frecuentes|questions fréquentes|häufige fragen|perguntas frequentes|domande frequenti)~iu', $t ) ) { $d['faq_markup'] = true; } if ( preg_match( '~(tl;?dr|key takeaways?|in short|summary|at a glance|quick answer|short answer|resumen|en bref|kurz gesagt|in breve)~iu', $t ) ) { $d['has_takeaways'] = true; } } // Paragraphs. $plens = array(); $early = ''; foreach ( $xp->query( '//p' ) as $i => $p ) { $ptext = Aeoora_Util::one_line( $p->textContent ); $wc = Aeoora_Util::word_count( $ptext ); if ( $wc < 3 ) { continue; } $plens[] = $wc; if ( ! $d['first_p_words'] && $wc >= 8 ) { $d['first_p_words'] = $wc; $lead_parts = preg_split( '~(?<=[.!?。!?])\s+~u', $ptext, 2 ); $d['first_sentence_words'] = Aeoora_Util::word_count( $lead_parts[0] ); } if ( count( $plens ) <= 2 ) { $early .= ' ' . $ptext; } } if ( $plens ) { $d['p_over_120'] = count( array_filter( $plens, static function ( $n ) { return $n > 120; } ) ); // phpcs:ignore $d['p_over_200'] = count( array_filter( $plens, static function ( $n ) { return $n > 200; } ) ); // phpcs:ignore $d['p_share_short'] = 1 - $d['p_over_120'] / count( $plens ); } $d['definition'] = (bool) preg_match( '~\b(is|are)\s+(a|an|the|one of)\b|\b(refers to|is defined as|stands for|is short for)\b|\b(es|son)\s+(un|una|el|la)\b|\b(est|sont)\s+(un|une|le|la)\b|\b(ist|sind)\s+(ein|eine|der|die|das)\b|\b(é|são)\s+(um|uma|o|a)\b|\b(è|sono)\s+(un|una|il|lo|la)\b~iu', $early ); $d['lists'] = $xp->query( '//ul[li] | //ol[li]' )->length; $d['tables'] = $xp->query( '//table[.//th or .//thead] | //table[.//tr]' )->length; $d['quotes'] = $xp->query( '//blockquote | //q | //cite' )->length; if ( ! $d['quotes'] && preg_match( '~["“„«][^"”“»]{40,}["”»]\s*[,—–-]?\s*(said|says|according to|explains|notes|writes|dijo|según|selon|sagt|disse)~iu', $text ) ) { $d['quotes'] = 1; } if ( ! $d['quotes'] && preg_match( '~(according to|said|says)\s+[A-Z][a-z]+\s+[A-Z][a-z]+~u', $text ) ) { $d['quotes'] = 1; } if ( $xp->query( '//*[contains(@class,"faq") or contains(@class,"rank-math-faq") or @itemtype="https://schema.org/FAQPage"]' )->length ) { $d['faq_markup'] = true; } if ( $xp->query( '//*[contains(@class,"aeoora-tldr-box") or contains(@class,"key-takeaways") or contains(@class,"tldr")]' )->length ) { $d['has_takeaways'] = true; } foreach ( $xp->query( '//img' ) as $img ) { $w = (int) $img->getAttribute( 'width' ); if ( $w && $w < 3 ) { continue; } $d['images']++; if ( '' === trim( $img->getAttribute( 'alt' ) ) ) { $d['images_no_alt']++; } } $social = '~(facebook\.|twitter\.|^x\.com|instagram\.|linkedin\.|pinterest\.|tiktok\.|wa\.me|t\.me|whatsapp\.)~i'; foreach ( $xp->query( '//a[@href]' ) as $a ) { $href = trim( $a->getAttribute( 'href' ) ); if ( '' === $href || '#' === $href[0] || preg_match( '~^(mailto|tel|javascript|sms):~i', $href ) ) { continue; } $host = preg_replace( '~^www\.~', '', strtolower( (string) wp_parse_url( $href, PHP_URL_HOST ) ) ); if ( '' === $host || $host === $home_host ) { $d['internal_links']++; } elseif ( ! preg_match( $social, $host ) ) { $d['external_links']++; } } // Data points: numbers with a unit/percent/currency, or 2+ digit figures. preg_match_all( '~(? $match ) { if ( ! empty( $m[2][ $i ] ) || strlen( preg_replace( '/\D/', '', $m[1][ $i ] ) ) >= 2 ) { $count++; } } $d['numbers'] = $count; // Sentences. $sentences = array_values( array_filter( preg_split( '~(?<=[.!?。!?])\s+~u', $text, -1, PREG_SPLIT_NO_EMPTY ), static function ( $s ) { return Aeoora_Util::word_count( $s ) >= 3; } ) ); if ( $sentences ) { $lens = array_map( array( 'Aeoora_Util', 'word_count' ), $sentences ); $d['avg_sentence'] = round( array_sum( $lens ) / count( $lens ), 1 ); $d['long_sentence_share'] = count( array_filter( $lens, static function ( $n ) { return $n > 30; } ) ) / count( $lens ); // phpcs:ignore } // First-hand experience markers. $d['experience'] = (int) preg_match_all( '~\b(we tested|i tested|we tried|i tried|in our experience|in my experience|our data|our research|our survey|we surveyed|we found|i found|we measured|our team|case study|hands-on|first-hand|we analy[sz]ed|our results|nuestra experiencia|probamos|notre expérience|nous avons testé|wir haben getestet|unsere erfahrung)\b~iu', $text ); if ( $d['images'] && $xp->query( '//img[contains(@src,"/wp-content/uploads/")]' )->length ) { $d['experience']++; } // Sections between H2s. $parts = preg_split( '~]*>.*?~is', $html ); if ( is_array( $parts ) && count( $parts ) > 1 ) { array_shift( $parts ); foreach ( $parts as $part ) { $wc = Aeoora_Util::word_count( Aeoora_Util::one_line( $part ) ); if ( $wc < 15 ) { continue; } $d['sections']['count']++; $fp = ''; if ( preg_match( '~]*>(.*?)

~is', $part, $pm ) ) { $fp = Aeoora_Util::one_line( $pm[1] ); } $fpw = Aeoora_Util::word_count( $fp ); $pronoun = (bool) preg_match( '~^(it|this|they|these|that|those|he|she)\b~i', $fp ); if ( $wc >= 50 && $wc <= 450 && $fpw >= 12 && $fpw <= 90 && ! $pronoun ) { $d['sections']['good']++; } } } return $d; } /* -------------------------------------------------------------------- * Site audit (18 checks, 100 points) * ------------------------------------------------------------------ */ /** * Run (or fetch cached) site audit. * * @param bool $force Re-run. * @return array|WP_Error Error when the site can't load its own pages. */ public static function site( $force = false ) { $cached = get_option( 'aeoora_site_audit' ); if ( ! $force && is_array( $cached ) && isset( $cached['at'] ) && time() - $cached['at'] < DAY_IN_SECONDS ) { return $cached; } if ( function_exists( 'set_time_limit' ) ) { @set_time_limit( 180 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors, Squiz.PHP.DiscouragedFunctions.Discouraged -- long-running admin task. } $c = array(); $home = home_url( '/' ); // Every check reads the site the way a crawler does. If the server can't // load its own home page, say why instead of scoring an error page. $start = microtime( true ); $hp = self::fetch( $home ); $ttfb = (int) round( ( microtime( true ) - $start ) * 1000 ); if ( 0 === $hp['code'] ) { $why = $hp['error']; if ( false !== stripos( $why, 'timed out' ) ) { $why = __( 'the request timed out', 'aeoora' ); } elseif ( false !== stripos( $why, 'resolve' ) ) { $why = __( 'its address could not be looked up', 'aeoora' ); } elseif ( false !== stripos( $why, 'SSL' ) || false !== stripos( $why, 'certificate' ) ) { $why = __( 'the security certificate was rejected', 'aeoora' ); } elseif ( false !== stripos( $why, 'connect' ) ) { $why = __( 'the connection was refused', 'aeoora' ); } else { $why = __( 'the request failed', 'aeoora' ); } return new WP_Error( 'aeoora_audit_unreachable', /* translators: %s: reason, e.g. "the request timed out". */ sprintf( __( 'Your server could not load its own home page (%s), so the audit can’t read your pages the way a crawler does. A firewall, a security plugin or password protection that blocks requests from the server to itself is the usual cause; Tools → Site Health reports it as a loopback problem. Fix that, then run the audit again.', 'aeoora' ), $why ), array( 'status' => 503 ) ); } if ( $hp['code'] >= 400 ) { return new WP_Error( 'aeoora_audit_unreachable', /* translators: %d: HTTP status code. */ sprintf( __( 'Your home page answered with error %d when your server loaded it, so the audit can’t read your pages the way a crawler does. Password protection, maintenance mode or a security plugin is the usual cause. Fix that, then run the audit again.', 'aeoora' ), $hp['code'] ), array( 'status' => 503 ) ); } // robots.txt. $rr = self::fetch( home_url( '/robots.txt' ) ); $robots = 200 === $rr['code'] ? $rr['body'] : Aeoora_Robots::preview(); $public = (bool) get_option( 'blog_public' ); $key = array( 'OAI-SearchBot' => 'ChatGPT search', 'ChatGPT-User' => 'ChatGPT', 'PerplexityBot' => 'Perplexity', 'Perplexity-User' => 'Perplexity', 'Claude-SearchBot' => 'Claude search', 'Claude-User' => 'Claude', 'Googlebot' => 'Google + AI Overviews', 'Bingbot' => 'Bing + Copilot', 'DuckAssistBot' => 'DuckDuckGo AI', 'MistralAI-User' => 'Le Chat', 'Applebot' => 'Siri / Apple Intelligence', ); $sample = self::sample_post(); $path = $sample ? (string) wp_parse_url( get_permalink( $sample ), PHP_URL_PATH ) : '/'; $blocked = array(); foreach ( $key as $token => $label ) { if ( ! Aeoora_Robots::is_allowed( $robots, $token, $path ? $path : '/' ) ) { $blocked[] = $token . ' (' . $label . ')'; } } $core_blocked = ! Aeoora_Robots::is_allowed( $robots, 'Googlebot', '/' ) || ! Aeoora_Robots::is_allowed( $robots, 'Bingbot', '/' ) || ! $public; $ratio = $core_blocked ? 0 : 1 - count( $blocked ) / count( $key ); $c[] = self::site_check( 'robots_ai_search', 18, $blocked || ! $public ? ( $ratio >= 0.6 ? 'warn' : 'fail' ) : 'pass', __( 'Answer engines may crawl your content', 'aeoora' ), ! $public ? __( '“Discourage search engines” is on (Settings → Reading).', 'aeoora' ) : ( $blocked ? sprintf( /* translators: %s: list. */ __( 'robots.txt blocks: %s', 'aeoora' ), implode( ', ', $blocked ) ) : __( 'All major AI search and assistant crawlers are allowed.', 'aeoora' ) ), admin_url( 'admin.php?page=aeoora-crawlers' ), $ratio ); $training = array( 'GPTBot', 'ClaudeBot', 'Google-Extended', 'Applebot-Extended', 'CCBot', 'meta-externalagent' ); $explicit = 0; foreach ( $training as $t ) { if ( preg_match( '~^\s*user-agent:\s*' . preg_quote( $t, '~' ) . '\s*$~im', $robots ) ) { $explicit++; } } $signals = false !== stripos( $robots, 'content-signal' ) || false !== stripos( $robots, 'content-usage' ); $c[] = self::site_check( 'training_policy', 2, ( $explicit >= 3 || $signals ) ? 'pass' : 'warn', __( 'AI training preference declared', 'aeoora' ), ( $explicit >= 3 || $signals ) ? __( 'You state explicitly how AI training crawlers may use your content.', 'aeoora' ) : __( 'No explicit choice for AI training crawlers (either way is fine — just decide).', 'aeoora' ), admin_url( 'admin.php?page=aeoora-crawlers' ) ); // Home (fetched above) + sample post HTML. $body = $hp['body']; $sp = $sample ? self::fetch( get_permalink( $sample ) ) : array( 'code' => 0, 'body' => '', 'type' => '', 'headers' => array() ); $restrict = array(); foreach ( array( $hp, $sp ) as $page ) { if ( preg_match( '~]+name=["\']robots["\'][^>]+content=["\']([^"\']+)~i', $page['body'], $rm ) && preg_match( '~(noindex|nosnippet|noarchive|nocache|noai|max-snippet:\s*0)~i', $rm[1], $hit ) ) { $restrict[] = strtolower( $hit[1] ); } $xr = isset( $page['headers']['x-robots-tag'] ) ? (string) ( is_array( $page['headers']['x-robots-tag'] ) ? implode( ',', $page['headers']['x-robots-tag'] ) : $page['headers']['x-robots-tag'] ) : ''; if ( $xr && preg_match( '~(noindex|nosnippet|noarchive|nocache|noai)~i', $xr, $hit ) ) { $restrict[] = 'X-Robots-Tag ' . strtolower( $hit[1] ); } } $restrict = array_unique( $restrict ); $c[] = self::site_check( 'no_sitewide_restrictions', 6, $restrict ? 'fail' : 'pass', __( 'No site-wide snippet restrictions', 'aeoora' ), $restrict ? sprintf( /* translators: %s: directives. */ __( 'Found: %s. These keep content out of Copilot and Google AI answers.', 'aeoora' ), implode( ', ', $restrict ) ) : __( 'No noindex / nosnippet / noarchive directives on key templates.', 'aeoora' ), '' ); // Server-rendered content. $ssr_ok = null; if ( $sample && 200 === $sp['code'] ) { $plain = Aeoora_Util::one_line( Aeoora_Content::render_html( $sample, 'content' ) ); $raw = Aeoora_Util::one_line( preg_replace( '~<(script|style|noscript|template)[^>]*>.*?~is', '', $sp['body'] ) ); $words = preg_split( '/\s+/u', $plain ); $probes = 0; $found = 0; $step = max( 6, (int) floor( count( $words ) / 8 ) ); for ( $i = 0; $i + 6 < count( $words ) && $probes < 8; $i += $step ) { $phrase = implode( ' ', array_slice( $words, $i, 6 ) ); $probes++; if ( Aeoora_Util::icontains( $raw, $phrase ) ) { $found++; } } $ssr_ok = $probes ? $found / $probes : null; } $visible = Aeoora_Util::word_count( Aeoora_Util::one_line( preg_replace( '~<(script|style|noscript)[^>]*>.*?~is', '', $body ) ) ); if ( null === $ssr_ok ) { $ssr_ok = $visible >= 150 ? 1 : 0.4; } $c[] = self::site_check( 'server_rendered', 15, $ssr_ok >= 0.9 ? 'pass' : ( $ssr_ok >= 0.5 ? 'warn' : 'fail' ), __( 'Content readable without JavaScript', 'aeoora' ), $ssr_ok >= 0.9 ? __( 'Your article text is in the page source, so crawlers that don’t run JavaScript can read it.', 'aeoora' ) : sprintf( /* translators: %d: percent. */ __( 'Only about %d%% of the article text is in the page source. Most AI crawlers don’t run JavaScript.', 'aeoora' ), (int) round( $ssr_ok * 100 ) ), '', $ssr_ok ); // Sitemap with lastmod. $sitemap = Aeoora_Compat::sitemap_url(); $sm = $sitemap ? self::fetch( $sitemap ) : array( 'code' => 0, 'body' => '' ); $sm_note = __( 'No working XML sitemap found.', 'aeoora' ); $sm_stat = 'fail'; $sm_r = 0; if ( 200 === $sm['code'] && false !== stripos( $sm['body'], '<' ) ) { $xml = $sm['body']; if ( false !== stripos( $xml, '\s*([^<]+?)\s*~i', $xml, $lm ) ) { $child = self::fetch( html_entity_decode( $lm[1] ) ); $xml = 200 === $child['code'] ? $child['body'] : $xml; } $urls = substr_count( strtolower( $xml ), '' ); $lmods = substr_count( strtolower( $xml ), '' ); $sm_r = $urls ? min( 1, $lmods / $urls ) : 0.5; $sm_stat = $sm_r >= 0.95 ? 'pass' : 'warn'; $sm_note = $sm_r >= 0.95 ? sprintf( /* translators: %s: URL. */ __( '%s lists when each page was last updated.', 'aeoora' ), $sitemap ) : sprintf( /* translators: %s: URL. */ __( '%s is missing “last updated” dates for many pages.', 'aeoora' ), $sitemap ); $sm_r = max( 0.5, $sm_r ); } $c[] = self::site_check( 'sitemap_lastmod', 10, $sm_stat, __( 'XML sitemap with update dates', 'aeoora' ), $sm_note, '', $sm_r ); // HTTPS. $https = 0 === strpos( $home, 'https://' ); $c[] = self::site_check( 'https', 7, $https && 200 === $hp['code'] ? 'pass' : ( $https ? 'warn' : 'fail' ), __( 'HTTPS and clean status codes', 'aeoora' ), $https ? sprintf( /* translators: %d: HTTP code. */ __( 'HTTPS on; home page answered HTTP %d.', 'aeoora' ), $hp['code'] ) : __( 'The site is not served over HTTPS.', 'aeoora' ), '' ); // Canonical. $canon = (bool) preg_match( '~]+rel=["\']canonical["\']~i', $body ) && ( ! $sample || (bool) preg_match( '~]+rel=["\']canonical["\']~i', $sp['body'] ) ); $c[] = self::site_check( 'canonical', 5, $canon ? 'pass' : 'warn', __( 'Canonical tags', 'aeoora' ), $canon ? __( 'Canonical URLs are declared.', 'aeoora' ) : __( 'Canonical tags are missing on the home page or posts.', 'aeoora' ), '' ); // Speed. $c[] = self::site_check( 'page_speed', 6, $ttfb && $ttfb < 800 ? 'pass' : ( $ttfb < 1800 ? 'warn' : 'fail' ), __( 'Server response time', 'aeoora' ), sprintf( /* translators: %d: ms. */ __( 'Home page answered in %d ms (measured from your own server; AI fetchers time out on slow pages).', 'aeoora' ), $ttfb ), '' ); // Organization schema. $org = (bool) preg_match( '~"@type"\s*:\s*\[?\s*"(Organization|Person|LocalBusiness|NewsMediaOrganization|OnlineStore|Corporation)"~', $body ); $sa = (bool) preg_match( '~"sameAs"~', $body ); $c[] = self::site_check( 'organization_schema', 5, $org && $sa ? 'pass' : ( $org ? 'warn' : 'fail' ), __( 'Organization schema with profiles', 'aeoora' ), $org ? ( $sa ? __( 'Organization details include your social profiles.', 'aeoora' ) : __( 'Organization details found, but without your social profiles.', 'aeoora' ) ) : __( 'No organization or person details in the home page’s structured data.', 'aeoora' ), admin_url( 'admin.php?page=aeoora-settings#schema' ) ); $bc = $sample ? (bool) preg_match( '~"BreadcrumbList"~', $sp['body'] ) : false; $c[] = self::site_check( 'breadcrumbs', 2, $bc ? 'pass' : 'warn', __( 'Breadcrumb schema', 'aeoora' ), $bc ? __( 'Posts include breadcrumb structured data.', 'aeoora' ) : __( 'No breadcrumb structured data on posts.', 'aeoora' ), admin_url( 'admin.php?page=aeoora-settings#schema' ), 0 ); // llms.txt (low weight: few AI engines read it today). $llms = self::fetch( home_url( '/llms.txt' ) ); $llms_ok = 200 === $llms['code'] && 0 === strpos( ltrim( $llms['body'] ), '# ' ); $c[] = self::site_check( 'llms_txt', 4, $llms_ok ? 'pass' : 'fail', __( 'llms.txt', 'aeoora' ), $llms_ok ? __( '/llms.txt is live and valid.', 'aeoora' ) : ( 200 === $llms['code'] ? __( '/llms.txt is there, but it isn’t a valid llms.txt file.', 'aeoora' ) : __( '/llms.txt is missing.', 'aeoora' ) ), admin_url( 'admin.php?page=aeoora-access' ) ); $full = self::fetch( home_url( '/llms-full.txt' ), true ); $c[] = self::site_check( 'llms_full', 1, 200 === $full['code'] ? 'pass' : 'warn', __( 'llms-full.txt', 'aeoora' ), 200 === $full['code'] ? __( '/llms-full.txt is live.', 'aeoora' ) : __( '/llms-full.txt is not available.', 'aeoora' ), admin_url( 'admin.php?page=aeoora-access' ), 0 ); $md_ok = false; if ( $sample && Aeoora_Markdown::is_eligible( $sample ) ) { $md = self::fetch( Aeoora_Markdown::url( $sample ), true ); $md_ok = 200 === $md['code'] && false !== stripos( $md['type'], 'markdown' ); } $c[] = self::site_check( 'markdown', 3, $md_ok ? 'pass' : 'warn', __( 'Markdown versions', 'aeoora' ), $md_ok ? __( 'Pages are available as clean Markdown (.md) for AI agents.', 'aeoora' ) : __( 'The Markdown versions of your pages didn’t load as expected.', 'aeoora' ), admin_url( 'admin.php?page=aeoora-access' ), 0 ); $in = Aeoora_Settings::get( 'indexnow', 'enabled', false ); $c[] = self::site_check( 'indexnow', 5, $in ? 'pass' : 'warn', __( 'IndexNow', 'aeoora' ), $in ? __( 'New and updated URLs are pushed to Bing and IndexNow engines.', 'aeoora' ) : __( 'IndexNow is off. Bing (and Copilot) pick up changes much faster with it.', 'aeoora' ), admin_url( 'admin.php?page=aeoora-settings#indexnow' ), 0 ); $bing = (bool) preg_match( '~]+name=["\']msvalidate\.01["\']~i', $body ) || file_exists( trailingslashit( ABSPATH ) . 'BingSiteAuth.xml' ); $c[] = self::site_check( 'bing_webmaster', 3, $bing ? 'pass' : 'warn', __( 'Bing Webmaster Tools', 'aeoora' ), $bing ? __( 'Bing verification found.', 'aeoora' ) : __( 'No Bing verification tag found (it may be verified by DNS). Bing feeds Copilot and other AI search.', 'aeoora' ), 'https://www.bing.com/webmasters', 0 ); $og = (bool) preg_match( '~]+property=["\']og:title~i', $body ); $c[] = self::site_check( 'open_graph', 3, $og ? 'pass' : 'warn', __( 'Open Graph tags', 'aeoora' ), $og ? __( 'Present.', 'aeoora' ) : __( 'No Open Graph tags on the home page.', 'aeoora' ), '', 0 ); $bios = self::author_bio_ratio(); $c[] = self::site_check( 'author_pages', 3, $bios >= 1 ? 'pass' : ( $bios > 0 ? 'warn' : 'fail' ), __( 'Author bios', 'aeoora' ), sprintf( /* translators: %d: percent. */ __( '%d%% of authors with published posts have a biography.', 'aeoora' ), (int) round( $bios * 100 ) ), admin_url( 'users.php' ), $bios ); $about = self::find_page( array( 'about', 'about-us', 'who-we-are', 'acerca', 'sobre', 'sobre-nosotros', 'a-propos', 'uber-uns', 'ueber-uns', 'chi-siamo', 'over-ons', 'quienes-somos' ) ); $contact = self::find_page( array( 'contact', 'contact-us', 'contacto', 'contato', 'kontakt', 'contatti', 'contactez-nous' ) ); $c[] = self::site_check( 'about_contact', 2, $about && $contact ? 'pass' : ( $about || $contact ? 'warn' : 'fail' ), __( 'About and Contact pages', 'aeoora' ), $about && $contact ? __( 'Both exist.', 'aeoora' ) : __( 'Publish About and Contact pages that explain who runs the site.', 'aeoora' ), admin_url( 'edit.php?post_type=page' ) ); // Informational notes. $notes = array(); $avg = self::average_score(); if ( null !== $avg ) { /* translators: %d: score. */ $notes[] = sprintf( __( 'Average content AEO score across scanned posts: %d/100.', 'aeoora' ), $avg ); } if ( Aeoora_Robots::has_physical() && ! get_option( 'aeoora_robots_physical_sync' ) ) { $notes[] = __( 'A physical robots.txt file exists and overrides WordPress. Sync the aeoora rules into it from AI crawlers → robots.txt.', 'aeoora' ); } if ( Aeoora_Llms::foreign_file() ) { $notes[] = __( 'A physical llms.txt created by another tool overrides the aeoora one.', 'aeoora' ); } if ( ! get_option( 'permalink_structure' ) ) { $notes[] = __( 'Plain permalinks are in use. Pretty permalinks give AI engines cleaner URLs.', 'aeoora' ); } $seo = Aeoora_Seo::active_label(); if ( $seo ) { /* translators: %s: plugin. */ $notes[] = sprintf( __( '%s detected: aeoora reads and writes titles and descriptions through it and does not duplicate its schema.', 'aeoora' ), $seo ); } $notes[] = __( 'Off-site signals (brand mentions, reviews, links from other sites) weigh heavily in AI answers but cannot be measured from inside WordPress.', 'aeoora' ); $score = 0; $max = 0; foreach ( $c as $one ) { $score += $one['points']; $max += $one['max']; } $score = $max ? (int) round( $score / $max * 100 ) : 0; $result = array( 'at' => time(), 'score' => $score, 'grade' => self::grade( $score ), 'checks' => $c, 'notes' => $notes, ); update_option( 'aeoora_site_audit', $result, false ); return $result; } /** * A recent public post to test against. * * @return WP_Post|null */ private static function sample_post() { $posts = get_posts( array( 'post_type' => array( 'post', 'page' ), 'post_status' => 'publish', 'has_password' => false, 'posts_per_page' => 5, 'orderby' => 'date', ) ); foreach ( $posts as $p ) { if ( Aeoora_Content::is_public( $p, 'audit' ) && (int) get_option( 'page_on_front' ) !== $p->ID ) { return $p; } } return null; } /** * Share of authors (with published posts) that have a bio. * * @return float */ private static function author_bio_ratio() { $users = get_users( array( 'has_published_posts' => array( 'post' ), 'fields' => array( 'ID' ), 'number' => 50, ) ); if ( ! $users ) { return 0; } $with = 0; foreach ( $users as $u ) { if ( strlen( trim( (string) get_user_meta( $u->ID, 'description', true ) ) ) > 30 ) { $with++; } } return $with / count( $users ); } /** * Is one of these slugs a published page? (Looked up by slug, so it is * found on a site with thousands of pages too.) * * @param string[] $slugs Slugs. * @return bool */ private static function find_page( array $slugs ) { $q = new WP_Query( array( 'post_type' => 'page', 'post_status' => 'publish', 'post_name__in' => $slugs, 'posts_per_page' => 1, 'fields' => 'ids', 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ) ); return ! empty( $q->posts ); } /** * Site check helper. * * @param string $id Id. * @param int $max Points. * @param string $status Status. * @param string $label Label. * @param string $message Message. * @param string $link Fix link. * @param float|null $ratio Partial ratio. * @return array */ private static function site_check( $id, $max, $status, $label, $message, $link = '', $ratio = null ) { $c = self::check( $id, $max, $status, $label, $message, '', '', 'pass' === $status ? null : $ratio ); $c['link'] = $link; return $c; } /** * Loopback GET. * * @param string $url URL. * @param bool $head Only status/type needed (body truncated). * @return array { code, body, type, headers } */ private static function fetch( $url, $head = false ) { $res = wp_remote_get( $url, Aeoora_Util::loopback_args( array( 'timeout' => 15, 'limit_response_size' => $head ? 4096 : 3145728 ) ) ); if ( is_wp_error( $res ) ) { return array( 'code' => 0, 'body' => '', 'type' => '', 'headers' => array(), 'error' => $res->get_error_message(), ); } $headers = wp_remote_retrieve_headers( $res ); return array( 'error' => '', 'code' => (int) wp_remote_retrieve_response_code( $res ), 'body' => (string) wp_remote_retrieve_body( $res ), 'type' => (string) wp_remote_retrieve_header( $res, 'content-type' ), 'headers' => is_object( $headers ) && method_exists( $headers, 'getAll' ) ? $headers->getAll() : (array) $headers, ); } /** * Average stored score across audited posts. * * @return int|null */ public static function average_score() { $s = self::score_stats(); return $s['scanned'] ? (int) round( $s['avg'] ) : null; } /** * Score distribution for the dashboard. * * @return array */ public static function distribution() { $s = self::score_stats(); unset( $s['avg'] ); return $s; } /** * Count, average and bands of stored scores, aggregated in SQL (one row, * never one value per post) and kept for the rest of the request. * * @return array { scanned, avg, great, good, poor } */ private static function score_stats() { global $wpdb; static $memo = null; if ( null !== $memo ) { return $memo; } $row = $wpdb->get_row( $wpdb->prepare( 'SELECT COUNT(*) n, AVG(v) a, SUM(v >= 80) great, SUM(v >= 55 AND v < 80) good, SUM(v < 55) poor FROM ( SELECT CAST(pm.meta_value AS UNSIGNED) v FROM %i pm INNER JOIN %i p ON p.ID = pm.post_id WHERE pm.meta_key = %s AND p.post_status = %s ) s', $wpdb->postmeta, $wpdb->posts, '_aeoora_score', 'publish' ), ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- one aggregate over post meta, no core API. $memo = array( 'great' => $row ? (int) $row['great'] : 0, 'good' => $row ? (int) $row['good'] : 0, 'poor' => $row ? (int) $row['poor'] : 0, 'scanned' => $row ? (int) $row['n'] : 0, 'avg' => $row ? (float) $row['a'] : 0.0, ); return $memo; } }