Created
June 16, 2014 08:26
-
-
Save partageit/24f58accfa50167343db to your computer and use it in GitHub Desktop.
Partage-it.com : système anti spambot de commentaire pour WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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