Kategorien
WordPress

WordPress Posts mit Links autoamtisch als Spam markieren

Damit man von dn ganzen Spam Bots nicht genervt wird, deren Zie es immer ist einen Kommentar mit einem oder mehreren Links auf ener Webseite zu platzieren, habe ich ein kurzes Skript geschrieben, was in die function.php eingefügt werden muss. Das Skript markiert alle Kommentare als Spam, die einen Link enthalten.

add_action( 'comment_post', 'show_message_function', 10, 2 );
function show_message_function( $comment_ID, $comment_approved ) {
   $comment = get_comment( $comment_ID);
   if(!empty($comment)){
      $content = $comment->comment_content;
      if(!empty($content)){
         $content = strtolower($content);
         $hasLink = strpos($content, 'http') !== false || strpos($content, 'www.') !== false || strpos($content, 'href') !== false;
         if($hasLink){
            //when has link, set to spam
            $commentarr = array();
            $commentarr['comment_ID'] = $comment_ID;
            $commentarr['comment_approved'] = 'spam';
            wp_update_comment( $commentarr );
         }
      }

   }

}