WordPress.org

Ready to get started?Download WordPress

Forums

WP Content Filter
[resolved] Apply the filter outside the comment's post? (7 posts)

  1. eoppy
    Member
    Posted 3 years ago #

    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/

  2. gwycon
    Member
    Plugin Author

    Posted 3 years ago #

    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?

  3. eoppy
    Member
    Posted 3 years ago #

    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>

  4. David Gwyer
    Member
    Plugin Author

    Posted 3 years ago #

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

  5. David Gwyer
    Member
    Plugin Author

    Posted 3 years ago #

    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>
  6. eoppy
    Member
    Posted 3 years ago #

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

  7. David Gwyer
    Member
    Plugin Author

    Posted 3 years ago #

    Your welcome.. :-)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic