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