{"id":34,"date":"2008-08-29T18:40:52","date_gmt":"2008-08-29T22:40:52","guid":{"rendered":"http:\/\/www.compdigitec.com\/labs\/?p=34"},"modified":"2008-08-29T18:40:52","modified_gmt":"2008-08-29T22:40:52","slug":"wordpress-author-email-blacklist-patch","status":"publish","type":"post","link":"http:\/\/www.compdigitec.com\/labs\/2008\/08\/29\/wordpress-author-email-blacklist-patch\/","title":{"rendered":"WordPress author email blacklist patch"},"content":{"rendered":"<p>If you&#8217;ve ever needed to block a single comment spammer using multiple IPs, referrers and urls, but the same email, here&#8217;s a patch for WordPress 2.5. This patch is released under the <a rel=\"nofollow\" href=\"http:\/\/www.gnu.org\/copyleft\/gpl.html\">GNU General Public License<\/a>.<\/p>\n<p>Add the following code to wp-comments-post.php after the line &#8220;$comment_content\u00a0\u00a0\u00a0\u00a0\u00a0 = trim($_POST[&#8216;comment&#8217;]);&#8221; (line 30 on v2.5):<br \/>\n<code><span style=\"color: #ff8000;\">\/\/\u00a0******\u00a0Start\u00a0of\u00a0comment\u00a0email\u00a0patch\u00a0by\u00a0Compdigitec\u00a0******<br \/>\n<\/span><span style=\"color: #0000bb;\">$name <\/span><span style=\"color: #007700;\">= <\/span><span style=\"color: #dd0000;\">'comment_author_email_blacklist.txt'<\/span><span style=\"color: #007700;\">;<br \/>\n<\/span><span style=\"color: #0000bb;\">$blacklist_email <\/span><span style=\"color: #007700;\">= <\/span><span style=\"color: #dd0000;\">''<\/span><span style=\"color: #007700;\">; <\/span><span style=\"color: #ff8000;\">\/\/ ** You can change the above blacklist file<br \/>\n<\/span><span style=\"color: #0000bb;\">$flag <\/span><span style=\"color: #007700;\">= <\/span><span style=\"color: #0000bb;\">true<\/span><span style=\"color: #007700;\">;<br \/>\nif(<\/span><span style=\"color: #0000bb;\">file_exists<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #0000bb;\">$name<\/span><span style=\"color: #007700;\">)\u00a0&amp;&amp; <\/span><span style=\"color: #0000bb;\">is_readable<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #0000bb;\">$name<\/span><span style=\"color: #007700;\">))\u00a0{<br \/>\n<\/span><span style=\"color: #0000bb;\">$ble <\/span><span style=\"color: #007700;\">= <\/span><span style=\"color: #0000bb;\">trim<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #0000bb;\">file_get_contents<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #0000bb;\">$name<\/span><span style=\"color: #007700;\">));<br \/>\n<\/span><span style=\"color: #0000bb;\">$blacklist_email <\/span><span style=\"color: #007700;\">= <\/span><span style=\"color: #0000bb;\">explode<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #dd0000;\">\"\\n\"<\/span><span style=\"color: #007700;\">,<\/span><span style=\"color: #0000bb;\">$ble<\/span><span style=\"color: #007700;\">);<br \/>\nforeach(<\/span><span style=\"color: #0000bb;\">$blacklist_email <\/span><span style=\"color: #007700;\">as <\/span><span style=\"color: #0000bb;\">$value<\/span><span style=\"color: #007700;\">)\u00a0{<br \/>\nif(<\/span><span style=\"color: #0000bb;\">$comment_author_email <\/span><span style=\"color: #007700;\">== <\/span><span style=\"color: #0000bb;\">$value<\/span><span style=\"color: #007700;\">)\u00a0{<br \/>\n<\/span><span style=\"color: #0000bb;\">$flag <\/span><span style=\"color: #007700;\">= <\/span><span style=\"color: #0000bb;\">false<\/span><span style=\"color: #007700;\">;<br \/>\n}<br \/>\n}<br \/>\nif(<\/span><span style=\"color: #0000bb;\">$flag <\/span><span style=\"color: #007700;\">=== <\/span><span style=\"color: #0000bb;\">false<\/span><span style=\"color: #007700;\">)\u00a0{<br \/>\n<\/span><span style=\"color: #0000bb;\">wp_die<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #0000bb;\">__<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #dd0000;\">'Sorry,\u00a0you\u00a0are\u00a0on\u00a0our\u00a0spam\u00a0blacklist\u00a0and\u00a0therefore\u00a0can\u00a0not\u00a0post\u00a0comments.'<\/span><span style=\"color: #007700;\">));<br \/>\n}<br \/>\n}\u00a0else\u00a0{<br \/>\n<\/span><span style=\"color: #ff8000;\">\/\/\u00a0Not\u00a0readable.<br \/>\n<\/span><span style=\"color: #007700;\">echo <\/span><span style=\"color: #0000bb;\">__<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #dd0000;\">\"&lt;!--\u00a0Warning:\u00a0Comment\u00a0Email\u00a0Blacklist\u00a0could\u00a0not\u00a0be\u00a0read.\u00a0--&gt;\"<\/span><span style=\"color: #007700;\">);<br \/>\n}<br \/>\n<\/span><span style=\"color: #ff8000;\">\/\/\u00a0******\u00a0End\u00a0of\u00a0comment\u00a0email\u00a0patch\u00a0by\u00a0Compdigitec\u00a0******<\/span><\/code><\/p>\n<p>Next, create a file called comment_author_email_blacklist.txt (or your custom filename if you changed it above). In the file, add your email addresses to blacklist, one per line. Don&#8217;t forget to add testblacklist@example.com to test it.<\/p>\n<p>If the patch has been installed, log out if you are logged in as the site admin. Then go to any post and try to post a comment (make sure there is some content, even if it is nonsense) with the email as &#8220;testblacklist@example.com&#8221; (without the quotes). You should be confronted with the following dialog:<br \/>\n<img decoding=\"async\" title=\"WordPress 2.5 with email blacklist patch denying comment posintg to a spammer\" src=\"\/images\/labs\/wp25-patch-deny.png\" alt=\"WordPress 2.5 with email blacklist patch denying comment posintg to a spammer\" \/><br \/>\nIf you do, congratulations! You have successfully installed the WordPress author email patch by Compdigitec. You can now proceed to adding more blacklist emails to your blacklist.<\/p>\n<p><strong>Troubleshooting<\/strong><\/p>\n<ul>\n<li>&#8220;&lt;!&#8211; Warning: Comment Email Blacklist could not be read. &#8211;&gt;&#8221; appears when you view the source every time you post a comment. Self-explaining &#8211; you need to create your blacklist file or make your blacklist file readable.<\/li>\n<\/ul>\n<p>If you found the patch for WordPress helpful or useful, please help Compdigitec by spreading the word. Also, please also take a look at our <a href=\"http:\/\/www.compdigitec.com\/\">main site<\/a>, <a href=\"http:\/\/www.compdigitec.com\/wiki\/Main_Page\">our wiki<\/a> and <a href=\"http:\/\/www.compdigitec.com\/forums\/index.php\">our forums<\/a>. Don&#8217;t forget to <a href=\"\/labs\/feed\/\">subscribe<\/a> to Compdigitec Labs for more intersting articles!<\/p>","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve ever needed to block a single comment spammer using multiple IPs, referrers and urls, but the same email, here&#8217;s a patch for WordPress 2.5. This patch is released under the GNU General Public License. Add the following code to wp-comments-post.php after the line &#8220;$comment_content\u00a0\u00a0\u00a0\u00a0\u00a0 = trim($_POST[&#8216;comment&#8217;]);&#8221; (line 30 on v2.5): \/\/\u00a0******\u00a0Start\u00a0of\u00a0comment\u00a0email\u00a0patch\u00a0by\u00a0Compdigitec\u00a0****** $name = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14],"tags":[153,154,156,157,155,71,159,160,158,152],"_links":{"self":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/34"}],"collection":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/comments?post=34"}],"version-history":[{"count":0,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/34\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/media?parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/categories?post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/tags?post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}