Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save partageit/24f58accfa50167343db to your computer and use it in GitHub Desktop.
Save partageit/24f58accfa50167343db to your computer and use it in GitHub Desktop.
Partage-it.com : système anti spambot de commentaire pour WordPress
<?php
// Ajout le nouveau 'vrai' champ et change celui qui existe en leurre à spambot
function addAntiSpambotField($fields) {
$newUrlFieldName = "url2";
$fields["url2"] = str_replace(array("for=\"url\"", "id=\"url\"", "name=\"url\""), array("for=\"$newUrlFieldName\"", "id=\"$newUrlFieldName\"", "name=\"$newUrlFieldName\""), $fields["url"]);
$fields["url"] = '<input type="url" id="url" name="url" value="">';
return $fields;
}
add_filter("comment_form_default_fields", "addAntiSpambotField");
// Vérification du leurre au moment de l'ajout du commentaire
function checkAntiSpambotField($commentId) {
if ($_POST["url"] !== "")
wp_die("<strong>ERREUR</strong>: Vous devez passer par le formulaire de commentaire du site. Si c'est le cas, et que vous voyez ce message, je vous remercie de prévenir l'administrateur par la page de contact.");
}
add_action("pre_comment_on_post", "checkAntiSpambotField");
// Remet les informations dans l'ordre pour la validation
function preprocessAntiSpambotField($commentdata) {
if (!$commentdata["comment_type"] && isset($_POST["url2"])) {
$commentdata["comment_author_url"] = $_POST["url2"];
}
return $commentdata;
}
add_action("preprocess_comment", "preprocessAntiSpambotField");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment