{"id":1361,"date":"2012-06-20T21:36:10","date_gmt":"2012-06-20T20:36:10","guid":{"rendered":"http:\/\/blog.ed.gs\/?p=1361"},"modified":"2012-06-20T21:36:10","modified_gmt":"2012-06-20T20:36:10","slug":"wordpress-comment-honeypot","status":"publish","type":"post","link":"https:\/\/ed.gs\/2012\/06\/20\/wordpress-comment-honeypot\/","title":{"rendered":"WordPress Comment HoneyPot"},"content":{"rendered":"

Thanks to Tim Whitlock<\/a> I’ve been able to modify his code and turn it into a comment honeypot plugin, catching and stopping any comment that includes a url in the comment url field. For this to be effective you will also need to hide the url field so only bots will try and fill it in, otherwise you’ll catch your visitors too if they try and include a web address.<\/p>\n

Save this in a folder called comment-honeypot in wp-admin\/plugins\/ as comment-honeypot.php:<\/p>\n

<?php\n/*\nPlugin Name: Comment HoneyPot\nDescription: Disallows any comments from users who add a url to the invisible webpage form field\nAuthor: Tim Whitlock - Mods by Ed Cooper\nAuthor URI: http://timwhitlock.info/\nVersion: 0.1\n*/\n \nfunction _tw_intercept_comment( array $data ){\n  if( empty($data['comment_author_url']) ){\n    return $data;\n  } else {\n    $message = 'Sorry, we capture spammers who add a web address to the comment form as it\\'s hidden. Try writing your comment again without including a web address this time.\n\nIf this is an error please let us know at <a href="http://yoursupportsite.com" target="_blank">Your Support Website</a>\n\n<a style="cursor:pointer"><strong>Go Back</strong></a>\n    $title = 'Spam Block';\n    $args = array('response' => 200);\n    wp_die( $message, $title, $args );\n    exit(0);\n  }\n} \n \nadd_filter('preprocess_comment','_tw_intercept_comment'); \n \n?><\/pre>\n

Also don’t forget to add your comment form url field hiding css to your themes style.css or if you’re on a WordPress Multisite installation try this plugin http:\/\/wordpress.org\/extend\/plugins\/sitewide-admin-headerfooter\/<\/a> and add it to the header of all of your sites\/blogs as a css stylesheet. <\/p>\n

I contemplated adding the stylesheet to the plugin but didn’t want to burden my sites with extra calls to files on page download; we serve a custom.css via the above plugin to all users on PrimaryBlogger, depends how optimised you want to be!<\/p>\n

#commentform #url, #commentform #url +label, .comment-form-url {\n\tdisplay:none;\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"

Thanks to Tim Whitlock I’ve been able to modify his code and turn it into a comment honeypot plugin, catching and stopping any comment that includes a url in the comment url field. For this to be effective you will also need to hide the url field so only bots will try and fill it […]<\/p>\n","protected":false},"author":2,"featured_media":3529,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false},"categories":[75,76],"tags":[],"yoast_head":"\nWordPress Comment HoneyPot - E<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ed.gs\/2012\/06\/20\/wordpress-comment-honeypot\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WordPress Comment HoneyPot - E\" \/>\n<meta property=\"og:description\" content=\"Thanks to Tim Whitlock I’ve been able to modify his code and turn it into a comment honeypot plugin, catching and stopping any comment that includes a url in the comment url field. For this to be effective you will also need to hide the url field so only bots will try and fill it […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ed.gs\/2012\/06\/20\/wordpress-comment-honeypot\/\" \/>\n<meta property=\"og:site_name\" content=\"E\" \/>\n<meta property=\"article:published_time\" content=\"2012-06-20T20:36:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/static.ed.gs\/wp-content\/uploads\/2012\/11\/207H.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2048\" \/>\n\t<meta property=\"og:image:height\" content=\"1365\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ed\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ed\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ed.gs\/2012\/06\/20\/wordpress-comment-honeypot\/\",\"url\":\"https:\/\/ed.gs\/2012\/06\/20\/wordpress-comment-honeypot\/\",\"name\":\"WordPress Comment HoneyPot - E\",\"isPartOf\":{\"@id\":\"https:\/\/ed.gs\/#website\"},\"datePublished\":\"2012-06-20T20:36:10+00:00\",\"dateModified\":\"2012-06-20T20:36:10+00:00\",\"author\":{\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ed.gs\/2012\/06\/20\/wordpress-comment-honeypot\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ed.gs\/#website\",\"url\":\"https:\/\/ed.gs\/\",\"name\":\"E\",\"description\":\"automation, consultancy, project management, web\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ed.gs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628\",\"name\":\"Ed\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g\",\"caption\":\"Ed\"},\"url\":\"https:\/\/ed.gs\/author\/ed\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WordPress Comment HoneyPot - E","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ed.gs\/2012\/06\/20\/wordpress-comment-honeypot\/","og_locale":"en_GB","og_type":"article","og_title":"WordPress Comment HoneyPot - E","og_description":"Thanks to Tim Whitlock I’ve been able to modify his code and turn it into a comment honeypot plugin, catching and stopping any comment that includes a url in the comment url field. For this to be effective you will also need to hide the url field so only bots will try and fill it […]","og_url":"https:\/\/ed.gs\/2012\/06\/20\/wordpress-comment-honeypot\/","og_site_name":"E","article_published_time":"2012-06-20T20:36:10+00:00","og_image":[{"width":2048,"height":1365,"url":"https:\/\/static.ed.gs\/wp-content\/uploads\/2012\/11\/207H.jpg","type":"image\/jpeg"}],"author":"Ed","twitter_misc":{"Written by":"Ed","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/ed.gs\/2012\/06\/20\/wordpress-comment-honeypot\/","url":"https:\/\/ed.gs\/2012\/06\/20\/wordpress-comment-honeypot\/","name":"WordPress Comment HoneyPot - E","isPartOf":{"@id":"https:\/\/ed.gs\/#website"},"datePublished":"2012-06-20T20:36:10+00:00","dateModified":"2012-06-20T20:36:10+00:00","author":{"@id":"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ed.gs\/2012\/06\/20\/wordpress-comment-honeypot\/"]}]},{"@type":"WebSite","@id":"https:\/\/ed.gs\/#website","url":"https:\/\/ed.gs\/","name":"E","description":"automation, consultancy, project management, web","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ed.gs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628","name":"Ed","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/ed.gs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g","caption":"Ed"},"url":"https:\/\/ed.gs\/author\/ed\/"}]}},"_links":{"self":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts\/1361"}],"collection":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/comments?post=1361"}],"version-history":[{"count":0,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts\/1361\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/media\/3529"}],"wp:attachment":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/media?parent=1361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/categories?post=1361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/tags?post=1361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}