Ora dimenticate i commenti di spam in WordPress 😎

Scaricare: Forget Spam Comment Plugin

Si tratta di un plugin gratuito anti-spam esclusivamente per il sistema di commenti predefinito di WordPress.

Alternatively, for advanced user below is the manual method

Il sistema di commenti predefinito di WordPress presenta due problemi principali.

  1. Attirare commenti di spam.
  2. Non invio di e-mail di follow-up all’autore del commento (ne discuteremo tra qualche tempo).

Parliamo delle sue soluzioni.

Preventing Spam Comments

Invece di permettere direttamente a chiunque di fare una richiesta POST a /wp-comments-post.php, possiamo aggiungere una logica per prevenire al 100% i commenti di spam.

Passo 1. Limitare il percorso della richiesta POST di commento in base al parametro della query

Condividerò tre modi per utilizzare un metodo.

Apache

  • Yoast > Vai a Strumenti > File Editor
  • RankMath > Vai alle Impostazioni generali > Modifica .htaccess
  • FTP/SSH > Check /var/www/html
# Se la stringa di query non corrisponde, restituisce 404
<IfModule mod_rewrite.c>
	RewriteEngine On
        RewriteCond %{REQUEST_URI} .wp-comments-post\.php
        # You may change 45jpfAY9RcNeFP to something else
        RewriteCond %{QUERY_STRING} !^45jpfAY9RcNeFP
	RewriteRule (.*) - [R=404,L]
</IfModule>

Se si utilizza LiteSpeed, supporta anche il file .htaccess. È necessario riavviare dopo l’implementazione.

NGINX

location = /wp-comments-post.php {

 if ($query_string !~ "45jpfAY9RcNeFP") {
     return 404;
  }
}

Cloudflare

prevent spam comments
  • Accesso al cruscotto di Cloudflare
  • Go to Firewall > Firewall Rules
  • Creare una nuova regola del firewall con la seguente espressione
FieldOperatorValue
URIcontainswp-comments-post.phpAnd
URL Query Stringdoes not equal45jpfAY9RcNeFP
  • Choose Action: Block

Alla fine, si vedrà l’espressione

(http.request.uri contains "wp-comments-post.php" and http.request.uri.query ne "45jpfAY9RcNeFP")

Passo 2. Correggere l’URL POST del commento sull’evento Scroll

  • Aggiungere la funzione sottostante utilizzando il plugin Code Snippets o il file functions.php del tema.
  • Assicurarsi di utilizzare il dominio e l’ID del modulo corretti.
function correct_comment_url_on_scroll() {
// Check if Comment is enabled
if(comments_open()) echo '<script>
let commentForm = document.querySelector("#commentform, #ast-commentform, #ht-commentform");

// Load new comment path on the scroll event
document.onscroll = function () {
    commentForm.action = "https://www.example.com/wp-comments-post.php?45jpfAY9RcNeFP";
};
</script>';
}
add_action('wp_footer', 'correct_comment_url_on_scroll', 99);

In alternativa, se siete utenti del tema GeneratePress Premium, potete aggiungere la parte JS di cui sopra direttamente con il modulo Elements.

<script>
let commentForm = document.querySelector("#commentform");

commentForm.action = "https://www.example.com/wp-comments-post.php";
// Load new comment path on the scroll event
document.onscroll = function () {
    commentForm.action = "https://www.example.com/wp-comments-post.php?45jpfAY9RcNeFP";
};
</script>
  • Add a new hook
  • New Hook Title: Change Comment URL on the Fly
  • Hook: WP Footer
  • Priority: 99
  • Location: Posts – All posts
  • Publish

Come verificare se funziona?

  • Generalmente WordPress restituisce una risposta 405 per la richiesta GET a /wp-comments-post.php
  • Ma dopo la configurazione di cui sopra, si dovrebbe vedere Accesso negato.
  • Inoltre, l’URL deve essere caricato solo in presenza della stringa di query speciale 45jpfAY9RcNeFP che abbiamo aggiunto per prevenire i commenti di spam. È possibile cambiare questa stringa di query con un’altra in tutte le configurazioni di cui sopra.
  • Il codice sorgente mostra in genere il percorso wp-comments-post.php, ma se si ispeziona l’elemento dopo lo scorrimento si noterà l’aggiunta di una stringa di query.

Risultato #1: niente spam

no spam

Risultato n. 2: gli spammer vengono bloccati

log

Suggerimento per rendere il sistema di commenti predefinito ancora migliore

  • Per impostazione predefinita, il sistema di commenti di WordPress non invia un’e-mail di risposta all’autore del commento. Per risolvere questo problema, è possibile utilizzare il plugin Comment Reply Email Notification di Arno Welzel.

Se vi piacciono queste informazioni, fatele avere ai vostri amici. 🙏

Lascia un commento

20 commenti su “Ora dimenticate i commenti di spam in WordPress 😎”

  1. Thank you so much Sir Gulshan Kumar! I really appreciate your guide, and this has saved me tons of headache. Implemented via Cloudflare WAF plus Generatepress Elements Module.

    Rispondi
  2. By the way, how do you know if legit users won’t get blocked? Before this, I’ve been using a CF firewall rules that will blocks or challenge anyone who visit wp-comments-post.php but actually by doing so, legit users also got blocked. How this one different? Is it because of the string “45jpfAY9RcNeFP” that will differentiate which request is from bot and which request is from legit users? If legit users, they should’ve the string, if it’s spam, they don’t have that string. Am I understand it correctly?

    Rispondi
  3. Does this plugin / method will stop website from having spam comments once and for all or do we still receive it but it’s automatically filtered from the real comments (like Akismet)?

    Rispondi
  4. Hi Gulshan.

    I just wanted to let you know that I’ve been using your plugin for a few weeks now and it is brilliant. Genuine comments still get through but all of the spam, and I mean ALL of it, is filtered out. Excellent job!

    Well done and thank you so much for sharing it for free so that hobby bloggers like me can make use of it.

    Rispondi
    • Hi,
      I am also using plugin at this blog. It works perfectly fine here.
      If you want to me look into this issue, please provide your actual site URL where I can see live.
      Thanks!

      Rispondi