Version Description
Download this release
Release Info
| Developer | donncha |
| Plugin | |
| Version | 0.2 |
| Comparing to | |
| See all releases | |
Version 0.2
- cookies-for-comments.php +60 -0
- readme.txt +13 -0
cookies-for-comments.php
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
Plugin Name: Cookies for Comments
|
| 4 |
+
Plugin URI: http://ocaoimh.ie/cookies-for-comments/
|
| 5 |
+
Description: Sets a cookie that must exist for a comment to be allowed through
|
| 6 |
+
Version: 0.2
|
| 7 |
+
Author: Donncha O Caoimh
|
| 8 |
+
Author URI: http://ocaoimh.ie/
|
| 9 |
+
|
| 10 |
+
CHANGES
|
| 11 |
+
2008-07-07 - Make it work in sub directories too.
|
| 12 |
+
Mark spam comments with a "Blocked by CFC" message.
|
| 13 |
+
2008-03-06 - First release
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
function cfc_stylesheet_html() {
|
| 17 |
+
$cfc_key = get_option( 'cfc_key' );
|
| 18 |
+
if( !$cfc_key )
|
| 19 |
+
if( current_user_can('edit_plugins') ) {
|
| 20 |
+
$cfc_key = md5( time() );
|
| 21 |
+
add_option( 'cfc_key', $cfc_key );
|
| 22 |
+
} else {
|
| 23 |
+
return;
|
| 24 |
+
}
|
| 25 |
+
?><link rel="stylesheet" href="<?php echo trailingslashit( get_option( 'siteurl' ) ) . $cfc_key . '.css'; ?>" type="text/css" media="screen" /><?php
|
| 26 |
+
}
|
| 27 |
+
add_action( 'wp_head', 'cfc_stylesheet_html' );
|
| 28 |
+
|
| 29 |
+
function cfc_set_comment_style_cookie() {
|
| 30 |
+
$cfc_key = get_option( 'cfc_key' );
|
| 31 |
+
if( !$cfc_key )
|
| 32 |
+
return;
|
| 33 |
+
|
| 34 |
+
if( strpos( $_SERVER[ 'REQUEST_URI' ], $cfc_key . '.css' ) ) {
|
| 35 |
+
if( !isset( $_COOKIE[ $cfc_key ] ) )
|
| 36 |
+
@setcookie( $cfc_key, 1, time()+3600, '/' );
|
| 37 |
+
header("Content-type: text/css");
|
| 38 |
+
echo " ";
|
| 39 |
+
die();
|
| 40 |
+
}
|
| 41 |
+
remove_filter( 'preprocess_comment', 'akismet_auto_check_comment', 1 );
|
| 42 |
+
add_filter( 'preprocess_comment', 'akismet_auto_check_comment', 10 );
|
| 43 |
+
}
|
| 44 |
+
add_action( 'init', 'cfc_set_comment_style_cookie' );
|
| 45 |
+
|
| 46 |
+
function cfc_check_comment_style_cookie( $comment ) {
|
| 47 |
+
$cfc_key = get_option( 'cfc_key' );
|
| 48 |
+
if( !$cfc_key )
|
| 49 |
+
return;
|
| 50 |
+
|
| 51 |
+
if( $comment[ 'comment_type' ] != 'trackback' && $comment[ 'comment_type' ] != 'pingback' && !isset( $_COOKIE[ $cfc_key ] ) ) {
|
| 52 |
+
add_filter('pre_comment_approved', create_function('$a', 'return \'spam\';')); // thanks Akismet
|
| 53 |
+
remove_filter( 'preprocess_comment', 'akismet_auto_check_comment', 10 ); // remove Akismet, it's spam!
|
| 54 |
+
$comment[ 'comment_author' ] = '[Blocked by CFC] ' . $comment[ 'comment_author' ];
|
| 55 |
+
}
|
| 56 |
+
return $comment;
|
| 57 |
+
}
|
| 58 |
+
add_filter('preprocess_comment', 'cfc_check_comment_style_cookie', 1);
|
| 59 |
+
|
| 60 |
+
?>
|
readme.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
=== Comments For Cookies ===
|
| 2 |
+
Contributors: donncha
|
| 3 |
+
Tags: cookies, comments, spam
|
| 4 |
+
Tested up to: 2.5.1
|
| 5 |
+
Stable tag: 0.2
|
| 6 |
+
|
| 7 |
+
Sets a cookie on a random URL that is then checked when a comment is posted. If the cookie is missing the comment is marked as spam.
|
| 8 |
+
|
| 9 |
+
== Description ==
|
| 10 |
+
This plugin adds a stylesheet to your blog's html source code. When a browser loads that stylesheet a cookie is dropped. If that user then leaves a comment the cookie is checked. If it doesn't exist the comment is marked as spam.
|
| 11 |
+
|
| 12 |
+
== Installation ==
|
| 13 |
+
Copy into your plugins folder and activate. If you are using a caching plugin such as [WP Super Cache](http://ocaoimh.ie/wp-super-cache/) make sure you clear the cache after enabling this plugin.
|
