bool, tags_count => int, categories_count => int, * word_count => int, has_thumbnail => bool, images_missing_alt => int, * duplicate_title => bool, * ] */ defined('ABSPATH') || exit; class Postlint_Checks { /** @return string[] code => label */ public static function all_checks() { return [ 'featured-image' => 'Missing featured image', 'excerpt' => 'Missing excerpt', 'tags' => 'Missing tags', 'categories' => 'Missing categories', 'alt-text' => 'Images without alt text', 'thin-content' => 'Thin content', 'duplicate-title' => 'Duplicate title', ]; } /** Default-enabled checks (thin-content off by default to avoid noise). */ public static function default_enabled() { return ['featured-image', 'excerpt', 'tags', 'categories', 'alt-text', 'duplicate-title']; } /** * @param array $snapshot one post snapshot * @param array $settings normalized settings (checks, thin_content_words) * @return string[] issue codes present on this post, in registry order */ public static function evaluate(array $snapshot, array $settings) { $enabled = isset($settings['checks']) && is_array($settings['checks']) ? $settings['checks'] : self::default_enabled(); $issues = []; foreach (array_keys(self::all_checks()) as $code) { if (!in_array($code, $enabled, true)) { continue; } $method = 'check_' . str_replace('-', '_', $code); if (self::$method($snapshot, $settings)) { $issues[] = $code; } } return $issues; } /** Pages have no tags, categories or excerpts in core; flagging them would be a false alarm. */ private static function supports(array $s, $feature) { return !isset($s['supports'][$feature]) || $s['supports'][$feature]; } public static function check_featured_image(array $s, array $settings) { return self::supports($s, 'thumbnail') && empty($s['has_thumbnail']); } public static function check_excerpt(array $s, array $settings) { return self::supports($s, 'excerpt') && empty($s['excerpt_set']); } public static function check_tags(array $s, array $settings) { return self::supports($s, 'tags') && (int) $s['tags_count'] === 0; } public static function check_categories(array $s, array $settings) { return self::supports($s, 'categories') && (int) $s['categories_count'] === 0; } public static function check_alt_text(array $s, array $settings) { return (int) $s['images_missing_alt'] > 0; } public static function check_thin_content(array $s, array $settings) { $threshold = max(1, (int) ($settings['thin_content_words'] ?? 150)); return (int) $s['word_count'] < $threshold; } public static function check_duplicate_title(array $s, array $settings) { return !empty($s['duplicate_title']); } }