• I’m having issues with comment spam. It’s pretty easy to tell which comments are spam because I removed the URL field from my theme… So any comments with a URL were clearly posted by a spambot that isn’t using the themes comment form.

    Is there a way to intercept comments in my functions.php file? I’m looking for a hook where I can do some logic like if(url exists in comment){don’t save comment}else{save comment}. It should be a simple fix, but, I’m having a hard time finding where this occurs.

    • This topic was modified 5 years, 1 month ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Moved to Fixing WordPress, this is not an Developing with WordPress topic.

    Have you tried any of these solutions?

    https://www.ads-software.com/support/article/comment-spam/

    A link alone isn’t enough to make it obvious that it’s a spam bot though yes, when you examine it it is obvious to a real person. Akismet and other spam plugins can make that determination by comparing the comment “score” to other comments left on other WordPress installations.

    Thread Starter shaunpoore

    (@shaunpoore)

    I saw it as a developing with WordPress topic because back-end code will be needed to prevent this.

    A link alone isn’t enough to make it obvious that it’s a spam bot

    On my Theme it is. I have removed the URL field. So when a user posts a name, email, comment and URL to my website… I KNOW that it is spam. THERE IS NO URL FIELD ON MY SITE so how could they have posted a URL through the form? The answer is they couldn’t. It’s spam and I’d like to hook into wherever comments are saved in functions.php and prevent the comment from being saved.

    Have you tried any of these solutions?

    Sure, I can moderate away the spam comments just fine. But, after a certain point of reading spam comments a man might ask, “Wait, why don’t I just write a line of code so I never have to do this again?”

    I surmise there is a better way than just dealing with it.

    Thread Starter shaunpoore

    (@shaunpoore)

    I figured out how to do what I was looking for. This hook should work.

    function preprocess_comment_remove_url( $commentdata ) {
        // If the user submitted the URL disallow comment..
        if (!IsNullOrEmptyString($commentdata['comment_author_url'])) {
            wp_die('Please stop spamming us!  Thanks!');
        }
        return $commentdata;
    }
    add_filter( 'preprocess_comment' , 'preprocess_comment_remove_url' );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Don’t save comments containing a URL’ is closed to new replies.