The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

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

  1. Peter
    Posted 9 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. 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

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

  3. Peter
    Posted 9 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
    Posted 8 years ago #

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


Topic Closed

This topic has been closed to new replies.

About this Topic