Skip to content

Commit

Permalink
Reverted back to using get_the_content() for the base excerpt text
Browse files Browse the repository at this point in the history
  • Loading branch information
aprea committed Jun 5, 2014
1 parent 93e8b1d commit 25c2f2a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
49 changes: 27 additions & 22 deletions class/advanced-excerpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Advanced_Excerpt {

public $options_basic_tags; // Basic HTML tags (determines which tags are in the checklist by default)
public $options_all_tags; // Almost all HTML tags (extra options)
public $filter_type; // Determines wether we're filtering the_content or the_excerpt at any given time

function __construct( $plugin_file_path ) {
$this->load_options();
Expand Down Expand Up @@ -91,11 +92,11 @@ function hook_content_filters() {
if ( 1 == $this->options['the_excerpt'] ) {
remove_all_filters( 'get_the_excerpt' );
remove_all_filters( 'the_excerpt' );
add_filter( 'get_the_excerpt', array( $this, 'filter' ) );
add_filter( 'get_the_excerpt', array( $this, 'filter_excerpt' ) );
}

if ( 1 == $this->options['the_content'] ) {
add_filter( 'the_content', array( $this, 'filter' ) );
add_filter( 'the_content', array( $this, 'filter_content' ) );
}
}

Expand Down Expand Up @@ -204,46 +205,48 @@ function plugin_action_links( $links ) {
return $links;
}

function filter( $text ) {
global $post;
function filter_content( $content ) {
$this->filter_type = 'content';
return $this->filter( $content );
}

function filter_excerpt( $content ) {
$this->filter_type = 'excerpt';
return $this->filter( $content );
}

function filter( $content ) {
extract( wp_parse_args( $this->options, $this->default_options ), EXTR_SKIP );
$original_excerpt = $text;

// Avoid custom excerpts
if ( !empty( $text ) && !$no_custom ) {
return $text;
global $post;
if ( $the_content_no_break && false !== strpos( $post->post_content, '<!--more-->' ) && 'content' == $this->filter_type ) {
return $content;
}

// Get the full content and filter it
$text = $post->post_content;
if ( 1 == $no_shortcode ) {
$text = strip_shortcodes( $text );
// Avoid custom excerpts
if ( !empty( $content ) && !$no_custom ) {
return $content;
}

// prevent recursion on 'the_content' hook
$content_has_filter = false;
if ( has_filter( 'the_content', array( $this, 'filter' ) ) ) {
remove_filter( 'the_content', array( $this, 'filter' ) );
if ( has_filter( 'the_content', array( $this, 'filter_content' ) ) ) {
remove_filter( 'the_content', array( $this, 'filter_content' ) );
$content_has_filter = true;
}

$text = get_the_content( '' );
$text = apply_filters( 'the_content', $text );

// add our filter back in
if ( $content_has_filter ) {
add_filter( 'the_content', array( $this, 'filter' ) );
}

if ( $the_content_no_break && false !== strpos( $text, '<!--more-->' ) ) {
return $original_excerpt;
add_filter( 'the_content', array( $this, 'filter_content' ) );
}

// From the default wp_trim_excerpt():
// Some kind of precaution against malformed CDATA in RSS feeds I suppose
$text = str_replace( ']]>', ']]&gt;', $text );

$original_post_content = $text;

if ( empty( $allowed_tags ) ) {
$allowed_tags = array();
}
Expand All @@ -264,11 +267,13 @@ function filter( $text ) {
$text = strip_tags( $text, $tag_string );
}

$text_before_trimming = $text;

// Create the excerpt
$text = $this->text_excerpt( $text, $length, $length_type, $finish );

// Add the ellipsis or link
if ( !apply_filters( 'advanced_excerpt_disable_add_more', false, $original_post_content, $this->options ) ) {
if ( !apply_filters( 'advanced_excerpt_disable_add_more', false, $text_before_trimming, $this->options ) ) {
$text = $this->text_add_more( $text, $ellipsis, ( $add_link ) ? $read_more : false );
}

Expand Down
4 changes: 2 additions & 2 deletions functions/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ function the_advanced_excerpt( $args = '', $get = false ) {
$advanced_excerpt->options = wp_parse_args( $args, $advanced_excerpt->options );

// Ensure our filter is hooked, regardless of the page type
if ( ! has_filter( 'get_the_excerpt', array( $advanced_excerpt, 'filter' ) ) ) {
if ( ! has_filter( 'get_the_excerpt', array( $advanced_excerpt, 'filter_excerpt' ) ) ) {
remove_all_filters( 'get_the_excerpt' );
remove_all_filters( 'the_excerpt' );
add_filter( 'get_the_excerpt', array( $advanced_excerpt, 'filter' ) );
add_filter( 'get_the_excerpt', array( $advanced_excerpt, 'filter_excerpt' ) );
}

if ( $get ) {
Expand Down

0 comments on commit 25c2f2a

Please sign in to comment.