Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi Julka,

    thanks for reporting and for providing the modification. We’ll change this accordingly to ensure the compatibility with your plugin. ??

    Cheers!

    Thread Starter Julka Grodel

    (@jgrodel)

    Thanks MH!

    Hi Julka,

    thanks again – we’ve taken a look at your patch and at the moment we have the issue that it’s breaking the ability to set the excerpt length in characters (not words). Could you please provide more information what exactly is breaking your plugin?

    The theme itself has been downloaded almost 300,000 times and we haven’t received any reports from users about an issue with your plugin, so at the moment we’re not sure what exactly the issue with your plugin is. It would be helpful to have more information so that we can code a solution that is compatible with your plugin without breaking theme functionality.

    The function mh_trim_excerpt() is only a slightly modified version of wp_trim_excerpt(), so probably that isn’t the issue.

    If the HTML escaping was the issue, would something like this work for you?

    if (!function_exists('mh_excerpt')) {
    	function mh_excerpt($excerpt_length = '175') {
    		global $post;
    		$mh_magazine_lite_options = mh_magazine_lite_theme_options();
    		$excerpt = get_the_excerpt();
    		if (!has_excerpt()) {
    			$excerpt = substr($excerpt, 0, intval($excerpt_length));
    			$excerpt = substr($excerpt, 0, strrpos($excerpt, ' '));
    		}
    		echo '<div class="mh-excerpt">' . wp_kses_post($excerpt) . ' <a href="' . esc_url(get_permalink($post->ID)) . '" title="' . the_title_attribute('echo=0') . '">' . esc_attr($mh_magazine_lite_options['excerpt_more']) . '</a></div>' . "\n";
    	}
    }

    The excerpt then gets called like this:

    mh_excerpt($mh_magazine_lite_options['excerpt_length']);

    Thread Starter Julka Grodel

    (@jgrodel)

    Hello MH.

    I totally overlooked the substr bit in my patch. ??

    There are two things I’m seeing here that cause issues for our plugin
    1. The HTML escaping
    2. Doing the character trim so late via mh_excerpt

    Replacing esc_attr with wp_kses_post resolves #1

    If you remove #1 but don’t resolve #2, then these pages can end up with a broken DOM. Doing that string manipulation so late means you could be (and with our plugin, often are) cutting the excerpt in the middle of an HTML tag.

    Within wp_trim_excerpt (or mh_trim_excerpt), wp_trim_words gets called, and part of what wp_trim_words does is remove any HTML. This is the right time to do any other arbitrary string manipulation.

    Here’s my take on how to add in the character trimming at a less problematic time (as a filter on wp_trim_excerpt).

    Here’s a more thorough version that I think will give you fewer issues: https://www.dropbox.com/s/ul0xu1kxr5vxf4a/20150707_wp_theme_mh-magazine-lite.patch?dl=0

    And here’s a simplified version: https://www.dropbox.com/s/7ned5zsbbae553p/20150707_wp_theme_mh-magazine-lite_minimal.patch?dl=0

    I expect that the hard coded word length (200) in mh_trim_excerpt (which I leave in place in the simplified version) might get you into trouble if the user can customize the size of their excerpts (looking at mh_magazine_lite_theme_options suggests this) — or if another plugin comes in and shortens it through their own excerpt_length filter. This mismatch might mean that you get a string back from wp_trim_words that is unnecessarily shorter than what you’re looking for.

    Also, the only difference between your mh_trim_excerpt and wp_trim_excerpt that you can’t do with filters is swapping out strip_shortcodes for do_shortcode (I’m not sure that’s intentional?), and how you essentially remove their str_replace by making it do nothing (it replaces a string with itself).

    Note: While troubleshooting this, I found that the AddThis Sharing Buttons plugin will override your excerpt length with either patch because we’re handling things carelessly in our wp_trim_excerpt filter (basically, we’re ignoring the manipulated excerpt passed in and starting from scratch, replicating wp_trim_excerpt). I’ve got that fixed for our next release so that it will play nicer with other wp_trim_excerpt filters.

    Thanks,
    Julka

    Hi Julka,

    thanks a bunch for the detailed analysis. After looking at this I think the best thing we should do is just getting rid of the custom mh_trim_excerpt filter and then also switch from characters to words for the excerpt length.

    That probably makes more sense than coding around some stuff that doesn’t really fit here. Then we have a clean and proper solution that keeps the WP defaults intact and your plugin shouldn’t have issues anymore. ??

    swapping out strip_shortcodes for do_shortcode (I’m not sure that’s intentional?)

    Yeah, that was intentional because in the early days we had shortcodes included in the theme, for example to display dropcaps. But because of the default filter the shortcodes got stripped and the result was that the first letter of the excerpts was missing. That’s why we changed that. But now it probably can be removed anyway because we have removed these shortcodes already ages ago and there shouldn’t be any users anymore who are using them. So it’s not an issue to get rid of that. ??

    Thanks again for the nice conversation and the troubleshooting and have a great weekend!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Incompatibility with AddThis Sharing Buttons plugin’ is closed to new replies.