Cookies for Comments - Version 0.4

Version Description

Download this release

Release Info

Developer donncha
Plugin Icon wp plugin Cookies for Comments
Version 0.4
Comparing to
See all releases

Code changes from version 0.3 to 0.4

Files changed (2) hide show
  1. cookies-for-comments.php +48 -5
  2. readme.txt +2 -2
cookies-for-comments.php CHANGED
@@ -3,11 +3,13 @@
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.3
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
@@ -38,8 +40,10 @@ function cfc_set_comment_style_cookie() {
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
 
@@ -49,12 +53,51 @@ function cfc_check_comment_style_cookie( $comment ) {
49
  return $comment;
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
  ?>
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.4
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
 
10
  CHANGES
11
+ 2008-07-15 - User can delete spam comments now, http://wordpress.org/support/topic/187810?replies=2
12
+ Check that Akismet functions exist.
13
  2008-07-07 - Make it work in sub directories too.
14
  Mark spam comments with a "Blocked by CFC" message.
15
  2008-03-06 - First release
40
  echo " ";
41
  die();
42
  }
43
+ if( function_exists( 'akismet_auto_check_comment' ) ) {
44
+ remove_filter( 'preprocess_comment', 'akismet_auto_check_comment', 1 );
45
+ add_filter( 'preprocess_comment', 'akismet_auto_check_comment', 10 );
46
+ }
47
  }
48
  add_action( 'init', 'cfc_set_comment_style_cookie' );
49
 
53
  return $comment;
54
 
55
  if( $comment[ 'comment_type' ] != 'trackback' && $comment[ 'comment_type' ] != 'pingback' && !isset( $_COOKIE[ $cfc_key ] ) ) {
56
+ if( get_option( 'cfc_spam' ) == 'delete' ) {
57
+ wp_die( 'Sorry, your comment has not been accepted.' );
58
+ } else {
59
+ add_filter('pre_comment_approved', create_function('$a', 'return \'spam\';')); // thanks Akismet
60
+ }
61
+ if( function_exists( 'akismet_auto_check_comment' ) )
62
+ remove_filter( 'preprocess_comment', 'akismet_auto_check_comment', 10 ); // remove Akismet, comment is spam!
63
  $comment[ 'comment_author' ] = '[Blocked by CFC] ' . $comment[ 'comment_author' ];
64
  }
65
  return $comment;
66
  }
67
  add_filter('preprocess_comment', 'cfc_check_comment_style_cookie', 1);
68
 
69
+ function cfc_config_page() {
70
+ add_options_page('Cookies for Comments', 'Cookies for Comments', 'manage_options', 'cfc_config', 'cfc_conf');
71
+ }
72
+ add_action('admin_menu', 'cfc_config_page');
73
+
74
+ function cfc_conf() {
75
+
76
+ if ( isset($_POST['submit']) ) {
77
+ if ( function_exists('current_user_can') && !current_user_can('manage_options') )
78
+ die(__('Cheatin’ uh?'));
79
+
80
+ check_admin_referer( 'cfc' );
81
+ if( $_POST[ 'cfc_spam' ] == 'spam' || $_POST[ 'cfc_spam' ] == 'delete' ) {
82
+ update_option( 'cfc_spam', $_POST[ 'cfc_spam' ] );
83
+ }
84
+ }
85
+ if( !get_option( 'cfc_spam' ) )
86
+ update_option( 'cfc_spam', 'spam' );
87
+
88
+ if ( !empty($_POST ) ) { ?>
89
+ <div id="message" class="updated fade"><p><strong><?php _e('Options saved.') ?></strong></p></div>
90
+ <?php } ?>
91
+ <div class="wrap">
92
+ <h2><?php _e('Comments for Cookies Configuration'); ?></h2>
93
+ <div class="narrow">
94
+ <form action="" method="post" id="cfc-conf" style="margin: auto; width: 400px; ">
95
+ <?php wp_nonce_field('cfc') ?>
96
+ <label><h3>What should happen to comments caught by CFC?</h3> <select name='cfc_spam'><option value='delete' <?php echo ( get_option( 'cfc_spam' ) == 'delete' ? 'selected' : '' ); ?> /> Delete <option value='spam' <?php echo ( get_option( 'cfc_spam' ) == 'spam' ? 'selected' : '' ); ?> /> Spam</select></label>
97
+ <input type='submit' name='submit' value='Save Options' />
98
+ </form>
99
+ </div>
100
+ </div>
101
+ <?php
102
+ }
103
  ?>
readme.txt CHANGED
@@ -1,8 +1,8 @@
1
  === Comments For Cookies ===
2
  Contributors: donncha
3
  Tags: cookies, comments, spam
4
- Tested up to: 2.5.1
5
- Stable tag: 0.3
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
 
1
  === Comments For Cookies ===
2
  Contributors: donncha
3
  Tags: cookies, comments, spam
4
+ Tested up to: 2.6
5
+ Stable tag: 0.4
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