WordPress.org

Ready to get started?Download WordPress

Forums

Identifying pingbacks and trackbacks at the preprocess_comment level (4 posts)

  1. Peter
    Member
    Posted 7 years ago #

    I'm developing a Captcha anti-spam plugin, but don't want to do what most do, which is let the comment post, and then delete it from the database. Therefore, it acts at the preprocess_comment level.

    However, I need a way to identify pingbacks and trackbacks at the preprocess_comment level, since Captcha effectively blocks them all (and I'd want to allow them through). What variable(s) can identify pingbacks and trackbacks *before* they are posted?

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Both pingbacks and trackbacks get posted via wp_new_comment(), and so the preprocess_comment hook will get them that way. If you look at the comment_type part of the incoming array, you'll see when it's a pingback/trackback.

    function your_preprocess($incoming_comment)
    {
    if ($incoming_comment['comment_type'] == 'pingback' ||
    $incoming_comment['comment_type'] == 'trackback') {
    // allow it or something
    }
    }
    add_filter('preprocess_comment','your_preprocess');

    Not that I support Captcha's, BTW. They don't work.

  3. Peter
    Member
    Posted 7 years ago #

    Thanks, this was great. I was struggling for the longest time using code similar to what you just posted, but as it turns out I mistakenly had the called up the variable $incoming_comment with my globals. Silly, silly me.

  4. fiddyp
    Member
    Posted 6 years ago #

    brilliant!
    that solved my problem for identifying a trackback on the preprocess_comment filter

    thanks

Topic Closed

This topic has been closed to new replies.

About this Topic