post_excerpt); $source = 'manual excerpt'; if ($text === '') { $content=(string)$post->post_content; $text = wp_strip_all_tags(function_exists('strip_shortcodes') ? strip_shortcodes($content) : preg_replace('/\[[^\]]*\]/', '', $content), true); $source = 'page content'; } $text = trim((string) preg_replace('/\s+/', ' ', $text)); if ($text === '') return ['text' => '', 'source' => '']; $limit = TheDotDevAgenticBridge_Content_Metadata::MAX_SUMMARY_CHARS; $length = function_exists('mb_strlen') ? mb_strlen($text) : strlen($text); if ($length <= $limit) return ['text' => $text, 'source' => $source]; $cut = function_exists('mb_substr') ? mb_substr($text, 0, $limit - 1) : substr($text, 0, $limit - 1); $space = strrpos($cut, ' '); $cut = rtrim($space === false ? $cut : substr($cut, 0, $space)); return ['text' => $cut . '…', 'source' => $source]; } }