WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: WP Content Filter] Apply the filter outside the comment's post?

[Resolved] [Plugin: WP Content Filter] Apply the filter outside the comment's post?

  • WP Content Filter does great on the post’s comments, asterisks the naughty words out, but when I call the comments from elsewhere, no asterisks just the swearing. (I call the latest (approved) comment from the latest post on the homepage of my site.)

    Any ideas about how to apply the filter outside the comment’s post?

    http://wordpress.org/extend/plugins/wp-content-filter/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author gwycon

    @gwycon

    Can you give me some extra information before I can figure out how easy it is to implement your request? The way the WP Content Filter handles comment text is via the ‘comment_text’ WordPress filter.

    I assume you have some custom PHP code to grab the latest approved comment from the latest post? Can you show me the code that you are using for this?

    Sure,

    <div id=”lastcomment”>
    <?php
    $args = array(
    ‘status’ => ‘approve’,
    ‘number’ => ‘1’,
    ‘post_id’ => $post->ID, // use post_id, not post_ID
    );
    $comments = get_comments($args);
    foreach($comments as $comm) :
    echo(‘<span style=”font-weight:bold;”>’ . $comm->comment_author . ‘</span> said:
    ‘ . $comm->comment_content);
    endforeach;
    ?>
    </div>

    Plugin Author David Gwyer

    @dgwyer

    OK, I will take a look and get back to you.

    Plugin Author David Gwyer

    @dgwyer

    OK, after a bit of digging around it seems that get_comments() does not have any hooks at all and just grabs the raw comments. However, a quick fix is that you can manually pass any content through the wpcf_filter() function with the raw comment text (so long as the WP Content Filter Plugin is active). 🙂

    I have tested this modified code and it works on my local install. It should give you what you need:

    <div id="lastcomment">
      <?php
      $args = array(
      'status' => 'approve',
      'number' => '1',
      'post_id' => $post->ID(), // use post_id, not post_ID
      );
      $comments = get_comments($args);
      foreach($comments as $comm) :
        $comment_author = $comm->comment_author;
        $comment_content = $comm->comment_content;
        if (function_exists('wpcf_filter')) { // make sure the WP Content Filter Plugin is still active, and available!
          $comment_author = wpcf_filter($comment_author);
          $comment_content = wpcf_filter($comment_content);
        }
        echo('<span style="font-weight:bold;">' . $comment_author . '</span> said: ' . $comment_content);
      endforeach;
    ?>
    </div>

    Just what I was looking for. Worked great. Thanks so much!

    Plugin Author David Gwyer

    @dgwyer

    Your welcome.. 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] [Plugin: WP Content Filter] Apply the filter outside the comment's post?’ is closed to new replies.