[wp-hackers] Will this generate bug?

Brian Layman Brian at TheCodeCave.com
Tue Oct 31 17:15:54 GMT 2006


> I originally posted this one at the support forums of WordPress and  * 
> spencerp *told** me that I can ask here...

DO YOU REALLY THINK THAT GIVES YOU THE RIGHT TO POST THIS KIND OF STUFF
HERE????????????
ASKING QUESTIONS WITH YOUR FIRST POST AND ALL THAT!?!?!?

Well, yeah, it works for me... Welcome!

(And this joke would have worked better if I hadn't fallen asleep while
writing this email last night and Alan hadn't replied first...  Anyway, I'm
saying basically the same thing he is. So we must be on the right track.  I
just chose a different place to hook in.  I think mine is better since it
allows you to respect Akismet or not at your discretion. (I've not fully
tested that feature btw.) So, now back to the original email already in
progress...)

I don't see anything wrong at all with your code, but I'd rather see this as
a plugin instead of a hack of code...  You'll thank yourself later when an
update does not wipe out this "feature" because it is just a plugin.  If I
were to make this a full fledged plugin, I would toss in an edit field and
allow the posts to be entered in a config screen and separated by commas.
Maybe I'll do that tomorrow night...  

Here's the code as is....  Just save it as "TCC_ModeratedPosts.php" in your
plugin directory (Please keep the uppercase letters.) and activate it.  

(I've now tested this and it works fine and doesn't interfere with posts on
other comments.)

Enjoy! (scroll down for the code - don't forget to snip off any signature
the mailing lists adds before you safe this as a php file.)
_______________________________________________
Brian Layman
www.TheCodeCave.com
 







<?php
/*
Plugin Name: TCC's Moderate Specific Posts
Plugin URI: http://www.thecodecave.com/articlecategory/plugins/
Plugin File Name: TCC_ModeratedPosts.php
Description: Throw the comments on specific posts into moderation.
Author: Brian Layman
Version: 0.1
Author URI: http://www.thecodecave.com/
*/

//
****************************************************************************
***********
//  Defined Constants
//
****************************************************************************
***********
// This define would be replaced if a UI was added to the plugin.  (See v.
0.2)
	define('MODERATED_POSTS', '32,84');
// If you don't want spam to be filtered out with Akismet, change the this
to 1.
	define('MODERATION_PRIORITY', 0);


function tcc_premoderate_specific_posts($commentdata) {
	global $auto_comment_approved;

	$blacklist = split(",", MODERATED_POSTS);
	if( in_array( $commentdata['comment_post_ID'], $blacklist ) )
		$auto_comment_approved = 'moderated_post';
	return $commentdata;
}

//
****************************************************************************
***********
//  Pluggable Function replacements
//
****************************************************************************
***********
function tcc_moderate_specific_posts($approved) {
	// Called from within wp_allow_comment
	global $auto_comment_approved;
	if ( 'moderated_post' == $auto_comment_approved )
		$approved = 0;
	return $approved;
}

//
****************************************************************************
***********
//  Initialization
//
****************************************************************************
***********
// Sets the timing of the action to either before or after Akismet
add_action('preprocess_comment', 'tcc_premoderate_specific_posts',
MODERATION_PRIORITY);
// Does the actual deletion and triggers the subsequent notification of the
moderators
add_filter('pre_comment_approved', 'tcc_moderate_specific_posts', 1);
?>



More information about the wp-hackers mailing list