Zapomeňte na spam Comment in WordPress 😎

Stáhnout: Zapomeňte na spamový komentář Plugin

Jedná se o bezplatný antispamový plugin určený výhradně pro výchozí komentářový systém WordPress.

Jak to funguje

Alternativou pro pokročilé uživatele je níže uvedená ruční metoda.

Výchozí systém komentářů ve WordPressu má dva hlavní problémy.

  1. Přilákání nevyžádaných komentářů.
  2. Neodesílání následného e-mailu autorovi komentáře (Za chvíli se o tom bude diskutovat).

Promluvme si o jeho řešení.

Prevence spamu Comments

Namísto toho, aby přímo umožňoval komukoli POST request at /wp-comments-post.php můžeme přidat nějakou logiku, aby se zabránilo spam komentáře 100%.

Krok1. Restrict Comment POST request Path over Query Parameter

Podělím se o tři způsoby, použijte jednu metodu.

Apache

  • Yoast > Go to Tools > File Editor
  • RankMath > Go to General Settings > Edit .htaccess
  • FTP/SSH > Check /var/www/html
# If Query string doesn't matches return 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>

If you’re on LiteSpeed, it also support .htaccess file. You must restart after implementation.

NGINX

location = /wp-comments-post.php {

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

Cloudflare

prevent spam comments
  • Login to Cloudflare Dashboard
  • Go to Firewall > Firewall Rules
  • Create a new firewall rule with below expression
FieldOperatorValue
URIcontainswp-comments-post.phpAnd
URL Query Stringdoes not equal45jpfAY9RcNeFP
  • Choose Action: Block

Na konci uvidíte výraz

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

Krok 2. Correct the Comment POST URL on Scroll event

  • Přidejte níže uvedenou funkci pomocí pluginu Code Snippets nebo tématu functions.php
  • Ujistěte se, že používáte správné domain and form ID.
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);

Pokud jste uživatelem tématu GeneratePress Premium, můžete výše uvedenou JS část přidat přímo pomocí modulu 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>
  • Přidat a new hook
  • New Hook Title: Change Comment URL on the Fly
  • Hook: WP Footer
  • Priority: 99
  • Location: Posts – All posts
  • Zveřejnit

Jak zkontrolovat, zda funguje?

  • Obecně WordPress vrátí 405 odpověď pro GET požadavek na /wp-comments-post.php
  • Po výše uvedeném nastavení by se však měl zobrazit text Access Denied.
  • A adresa URL by se měla načíst pouze za přítomnosti speciálního řetězce dotazu 45jpfAY9RcNeFP, který jsme přidali pro zabránění spamovým komentářům. Tento řetězec dotazů můžete změnit na jiný ve všech výše uvedených konfiguracích.
  • Zdrojový kód obvykle zobrazuje cestu wp-comments-post.php, ale pokud si po rolování prohlédnete prvek, všimnete si přidaného řetězce dotazů.

Výsledek #1: Žádný spam

no spam

Výsledek #2: Blokování spammerů

log

Bonusový tip pro ještě lepší výchozí systém komentářů

  • Ve výchozím nastavení komentářový systém WordPress neodesílá autorovi komentáře následný e-mail. Chcete-li tento problém vyřešit, můžete použít Comment Reply Email Notification plugin by Arno Welzel.

Pokud se vám tyto informace líbí, předejte je prosím svým přátelům. 🙏

Napsat komentář

20 komentářů u „Zapomeňte na spam Comment in WordPress 😎“

    • 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!

      Odpovědět
  1. 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.

    Odpovědět
  2. 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)?

    Odpovědět
  3. 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?

    Odpovědět
  4. 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.

    Odpovědět