• Hi guys,

    I am using your free version of Restrict Content, and I believe I found a bug. When restricting a post to certain members, and showing the excerpt, sometimes the post will be cut before an HTML tag is closed. For example, see here the strong tag: https://i.imgur.com/I5b3JIj.png

    That causes all sorts of styling issues, so what I did is the following.

    1) Edited the file /wp-content/plugins/restrict-content/core/includes/content-filters.php

    2) Added this function, taken from here:

    function fix_html($html) {
        $dom = new DOMDocument();
        $dom->loadHTML( mb_convert_encoding( $html, 'HTML-ENTITIES', 'UTF-8' ) );
        $return = '';
        foreach ( $dom->getElementsByTagName( 'body' )->item(0)->childNodes as $v ) {
            $return .= $dom->saveHTML( $v );
        }
        return $return;
    }

    3) Added this line…

    $excerpt = fix_html($excerpt);

    …after this other line:

    $excerpt        = rcp_excerpt_by_id( $post, $excerpt_length );

    I know just the basics of PHP, so I’m not sure if this is the best solution to this problem, but at least you have something it works.

    Anyway, could you please fix the bug in next versions?

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • I reported this bug back in August 2021!

    It should really be fixed in the plugin, but I ended up adding this filter:

    add_filter( 'rcp_excerpt_tags', function ( $tags ) {
        return ''; // strip_tags() 2nd arg. Remove all HTML tags from excerpt.
    });
    Thread Starter Gerard Blanco

    (@sixaxis)

    @jamieburchell But doesn’t that remove the format of the excerpt (bold, italics, links…)?

    @sixaxis Yes, it effectively converts the excerpt to plain text which was fine for my use case and the only reliable way to prevent this issue.

    Plugin Contributor Israel Barragan

    (@reedyseth)

    Hi @sixaxis could you please share if this solution worked for you? Otherwise we can take a look at it.

    Best regards!

    Thread Starter Gerard Blanco

    (@sixaxis)

    Hi Israel,

    Not sure what “solution” you mean. If you mean what I personally wrote in the first, yes, it works. If you mean what jamieburchell wrote, it works but it effectively converts the excerpt to plain text, so it is not 100% good.

    Either way, you have to fix this in your code. It’s not about making it work for me. It’s about fixing a bug in your code for everybody.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Bug report with restricted message’ is closed to new replies.