The Code Cave

November 1, 2006

TCC’s Moderate Specific Posts plugin

Filed under: My WordPress Plugins — Brian @ 12:14 am

Louie Alfred Gomez asked a question on the WordPress Hacker’s list yesterday about the best way to moderate all comments on specific blog posts. He was hacking the core WordPress code, which all of you who have just updated know is a bad idea.

I whipped out this plugin to show him an alternate solution. If anyone else finds they might need this, I’ll add a configuration screen and turn it into a zip file
Here’s the source as is:

PHP:
  1. <?php
  2. /*
  3. Plugin Name: TCC’s Moderate Specific Posts
  4. Plugin URI: http://www.thecodecave.com/articlecategory/plugins/
  5. Plugin File Name: TCC_ModeratedPosts.php
  6. Description: Throw the comments on specific posts into moderation.
  7. Author: Brian Layman
  8. Version: 0.1
  9. Author URI: http://www.thecodecave.com/
  10. */
  11.  
  12. // **********************************************************************
  13. //  Defined Constants
  14. // **********************************************************************
  15.  
  16. // This define would be replaced if a UI was added to the plugin.  (See v.0.2)
  17.     define(‘MODERATED_POSTS’, ‘32,84′);
  18. // If you don’t want spam to be filtered out with Akismet, change the this to 1.
  19.     define(‘MODERATION_PRIORITY’, 0);
  20.  
  21.  
  22. // **********************************************************************
  23. //  Pluggable Function replacements
  24. // **********************************************************************
  25.  
  26. function tcc_premoderate_specific_posts($commentdata) {
  27.     global $auto_comment_approved;
  28.  
  29.     $blacklist = split(“,”, MODERATED_POSTS);
  30.     if( in_array( $commentdata[‘comment_post_ID’], $blacklist ) )
  31.         $auto_comment_approved = ‘moderated_post’;
  32.     return $commentdata;
  33. }
  34.  
  35. function tcc_moderate_specific_posts($approved) {
  36.     // Called from within wp_allow_comment
  37.     global $auto_comment_approved;
  38.     if ( ‘moderated_post’ == $auto_comment_approved )
  39.         $approved = 0;
  40.     return $approved;
  41. }
  42.  
  43. // **********************************************************************
  44. //  Initialization
  45. // **********************************************************************
  46.  
  47. // Sets the timing of the action to either before or after Akismet add_action(’preprocess_comment’, ‘tcc_premoderate_specific_posts’, MODERATION_PRIORITY);
  48.  
  49. // Does the actual deletion and triggers the subsequent notification of the moderators add_filter(’pre_comment_approved’, ‘tcc_moderate_specific_posts’, 1);
  50.  
  51. ?>

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress