cabrerahector / wordpress-popular-posts

WordPress Popular Posts - A highly customizable WordPress widget that displays your most popular posts.
https://wordpress.org/plugins/wordpress-popular-posts/
GNU General Public License v2.0
280 stars 82 forks source link

Remove and/or parse blocks when generating excerpts #335

Closed cabrerahector closed 1 year ago

cabrerahector commented 1 year ago

The plugin should either remove and/or parse blocks before generating a post / page excerpt. Found that when there's a block on the content something like this happens when the excerpt option is enabled:

<div class="popular-posts-sr">
    <style></style>
    <ul class="wpp-list wpp-cardview">
        <li class="">
            <div class="wpp-thumbnail-container">
                <a href="..." target="_self">
                    <img src="..." srcset="..."  width="320" height="165" alt="..." class="wpp-thumbnail wpp_first_image wpp_cached_thumb" loading="lazy" />
                </a>
                <div class="taxonomies">
                    <a href="..." class="wpp-taxonomy category category-3">...</a>
                </div>
            </div>
            <div class="wpp-item-data">
                <a href="..." class="wpp-post-title" target="_self">...</a>
                <p class="wpp-excerpt"><!-- wp:image {"align":"center","id":346,"width":768,"height":521,"sizeSlug...</p>
            </div>
        </li>
        ...
    </ul>
</div>

The excerpt function is returning non parsed block HTML comments which should be converted into actual blocks before generating the excerpt itself. Otherwise all of the HTML code generated after the excerpt might be accidentally commented out (as seen on the code above), leading to the plugin not rendering popular posts properly.

We might need to do something like this to prevent this issue from happening.