WordPress.org

Ready to get started?Download WordPress

Forums

WP Tweet Button
[resolved] WP Tweet Button bug that conflicts with All in One SEO (3 posts)

  1. monodistortion
    Member
    Posted 3 years ago #

    I'm using the WP Tweet Button version Version 2.0.2 and I was having a problem with it not appearing only on certain posts. It would appear on almost every post but not on a few. It was on someone else's site so I didn't have it on my local server to do as much testing as I normally could. I spent several hours tracking down the problem and adding and changing lots of code, but I knew it was connected to the filters that you're using on the_content and get_the_excerpt.

    In the process I eventually found out that the pages where the tweet button was appearing had manual excerpts and the pages where the tweet button was missing didn't have a manual excerpt. The All in One SEO plugin uses the_excerpt for the meta description if there isn't a manual excerpt. There may have been other plugins or parts of the theme that were triggering the bug also.

    This is the code I ended up changing to fix the bug:

    I added a variable to the first section of the class as a flag to show if we're in an excerpt:

    /**
     * @var bool If the excerpt filter is run, we set this to true so we know
     * it's an excerpt
     */
    var $_is_excerpt = false;
    

    Then I added two filters that replaced your get_the_excerpt filter:

    add_filter('get_the_excerpt', array(&$this,'enter_excerpt'), 1);
    add_filter('get_the_excerpt', array(&$this,'exit_excerpt'), 9999);
    //add_filter('get_the_excerpt', array(&$this, 'tw_remove_filter'), 9);
    

    Then I commented out the two functions tw_remove_filter and tw_add_content_filter as they wouldn't be needed and replaced them with two simple functions:

    /**
     * This is called if a post is in excerpt.  It sets $this->_is_excerpt to
     * true, so we can test for it later.
     */
    function enter_excerpt($the_excerpt) {
    	$this->_is_excerpt = true;
    	return $the_excerpt;
    }
    function exit_excerpt($the_excerpt) {
    	$this->_is_excerpt = false;
    	return $the_excerpt;
    }
    

    Finally in the function tw_update I needed to add one more check to the long if statement at the beginning:

    ($this->tw_get_option('tw_display_excerpt') == '' && $this->_is_excerpt )
    

    I would really recommend adding comments explaining your functions since without any comments at all in your code it makes it much harder to debug. With one filter calling another filter removing one filter and then calling a third filter it was just easier to replace the code instead of trying to figure out what was wrong with the functions.

  2. Tanin
    Member
    Plugin Author

    Posted 3 years ago #

    The jumping through hoops in filters was done because some templates do crazy things with the excerpt filter. I'll be testing your mutations against these templates and implement them in the next version.

  3. Tanin
    Member
    Plugin Author

    Posted 3 years ago #

    This concept has been applied in 2.0.3

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic