Forums

There is a SERIOUS problem in strip_shortcodes (6 posts)

  1. dejudicibus
    Member
    Posted 5 months ago #

    strip_shortcodes is used in get_the_excerpt to strip shortcodes from content before generating the excerpt. This is ok, but that function is based on

    return preg_replace('/'.$pattern.'/s', '$1$6', $content);

    The result is that it does NOT strip ONLY the shortcode, but also ITS CONTENT! So, if you have a shortcode that is embedding the whole post as

    [translate_this]my post content[\translate_this]

    you have an EMPTY excerpt. Is there any hope to change that statement to

    return preg_replace('/'.$pattern.'/s', '$1$4$6', $content);

  2. dejudicibus
    Member
    Posted 5 months ago #

    For the moment I find the following solution that strips selected shortcodes PRESERVING the content.

    [code moderated - please use the pastebin for any code over 10 lines long]

    I use it as follows:

    function get_safe_excerpt($max_length=350,$min_lenght=300) {
    	$cnt = get_the_content();
    	$cnt = strip_tags($cnt);
    	$cnt = strip_selected_shortcodes($cnt);
    	return utf8_truncate($cnt,$max_length,TRUE,BRACKETED_ELLIPSIS,$min_lenght);
    }

    where utf8_truncate is my unicode-safe function to truncate a text.

  3. dejudicibus
    Member
    Posted 5 months ago #

    For the moment I find the following solution that strips selected shortcodes PRESERVING the content.

    <script src="http://pastebin.com/embed_js.php?i=5CJKL5id"></script>

    I use it as follows:

    function get_safe_excerpt($max_length=350,$min_lenght=300) {
    	$cnt = get_the_content();
    	$cnt = strip_tags($cnt);
    	$cnt = strip_selected_shortcodes($cnt);
    	return utf8_truncate($cnt,$max_length,TRUE,BRACKETED_ELLIPSIS,$min_lenght);
    }

    where utf8_truncate is my unicode-safe function to truncate a text.

  4. dejudicibus
    Member
    Posted 5 months ago #

    I really cannot understand how to SHOW the code by pastebin here!!!!

  5. dejudicibus
    Member
    Posted 5 months ago #

    ...and how to remove duplicated posts... sigh....

  6. Rev. Voodoo
    Volunteer Moderator
    Posted 5 months ago #

    you don't embed or 'show' the pastebin here, just give the link to the pastebin page, we go look over there

Reply

You must log in to post.

About this Topic