'on'); $s = get_option(CITAMI_AEO_SETTINGS_OPT, array()); if (is_array($s) && isset($s['enabled']) && $s['enabled'] === 'off') { $d['enabled'] = 'off'; } return $d; } add_action('admin_init', function () { register_setting('citami_seo', CITAMI_AEO_SETTINGS_OPT, array( 'type' => 'array', 'sanitize_callback' => function ($v) { return array('enabled' => (is_array($v) && isset($v['enabled']) && $v['enabled'] === 'off') ? 'off' : 'on'); }, 'default' => array(), )); }); /* ---------------------------------------------------------------- */ /* Text analysis (pure, no WordPress state) */ /* ---------------------------------------------------------------- */ /** Block-editor comments and shortcodes out, tags kept. */ function citami_aeo_clean_html($html) { $html = preg_replace('//s', '', (string) $html); $html = preg_replace('/\[\/?[a-zA-Z0-9_\-]+[^\]]*\]/', '', $html); return $html; } function citami_aeo_plain($html) { // Block boundaries become spaces so "
" never glues two words. $html = preg_replace('#?(p|h[1-6]|li|ul|ol|div|br|tr|td|th|table|blockquote|figure|figcaption|section|article|details|summary|pre)\b[^>]*>#i', ' ', citami_aeo_clean_html($html)); $text = wp_strip_all_tags($html); $text = html_entity_decode($text, ENT_QUOTES | ENT_HTML5, 'UTF-8'); return trim(preg_replace('/\s+/u', ' ', $text)); } function citami_aeo_word_count($text) { return preg_match_all('/[\p{L}\p{N}][\p{L}\p{N}\'’\-]*/u', (string) $text); } /** Paragraph texts:
contents when present, blank-line blocks otherwise. */ function citami_aeo_paragraphs($html) { $html = citami_aeo_clean_html($html); $out = array(); if (preg_match_all('#
]*>(.*?)
#is', $html, $m)) { foreach ($m[1] as $p) { $t = citami_aeo_plain($p); if ($t !== '') { $out[] = $t; } } return $out; } // Headings, lists and tables are not paragraphs. $html = preg_replace('#<(h[1-6]|ul|ol|table|blockquote|figure|pre)\b[^>]*>.*?\1>#is', "\n\n", $html); foreach (preg_split('/\n\s*\n/', $html) as $chunk) { $t = citami_aeo_plain($chunk); if ($t !== '') { $out[] = $t; } } return $out; } /** [[level, text], ...] */ function citami_aeo_headings($html) { $out = array(); if (preg_match_all('#