public function make_excerpt($more_text = null)
{
// Author inserted a <!--more--> tag
$parts = get_extended($this->post_content);
if (!empty($parts['extended'])) {
$ret = trim($parts['main']);
// Conditionally add a read more link and
// clean up punctuation and ellipsis at end of excerpt
$wc_excerpt = str_word_count($ret);
$wc_content = str_word_count($this->post_content);
if ($wc_excerpt < $wc_content) {
$ret = preg_replace('/([\\.,;:!?\'"]{4,})$/', '...', $ret . '...');
if (!empty($more_text)) {
$ret = $ret . ' <a href="' . $this->permalink . '" class="more-link">' . $more_text . '</a>';
}
}
}
// Excerpt is empty, so generate one
if (empty($parts['extended'])) {
$text = strip_shortcodes($this->post_content);
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$excerpt_length = apply_filters('excerpt_length', 55);
$read_more = apply_filters('read_more', ' ' . '[...]', $this);
$words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
if (count($words) > $excerpt_length) {
array_pop($words);
$text = implode(' ', $words);
$text = $text . $read_more;
} else {
$text = implode(' ', $words);
}
$ret = apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}
/* TODO: cache results of this function */
return $ret;
}