[wp-hackers] Modifying wp-comments-post.php to accept new custom fields

Casey Bisson casey.bisson at gmail.com
Wed Sep 24 22:11:31 GMT 2008


You might hook to preprocess_comment and then to comment_post. At  
least that worked when I wrote a plugin to allow private comments  
(haven't used or updated it recently). Here's the relevant function:

class bsuite_privatecomments {
	function preprocess_comment( $comment ) {
		$comment['privatecomment'] = !is_null( $_REQUEST['privatecomment'] );
		if($comment['privatecomment'])
			add_filter('pre_comment_approved', create_function('$a', 'return  
\'private\';'), 1);
			if($this->options['notify'])
				add_action('comment_post', array(&$this, 'notify'));
	
		return( $comment );
	}
}
add_action('preprocess_comment', array(&$this, 'preprocess_comment'),  
1);

Inside a function like that you could probably do an

add_action('comment_post', create_function('$comment_id, $approved',  
'do stuff with the $_REQUEST['var'] and $comment_id'));

That'd give you both the comment ID and your request vars without  
having to modify any core files.


Here's that old plugin:

http://maisonbisson.com/bsuite/private-comments

--Casey

http://about.Scriblio.net/
http://MaisonBisson.com/


On Sep 23, 2008, at 10:01 PM, DD32 wrote:

> rather than modifying core files, you should probably use the  
> 'preprocess_comment' filter inside wp_new_comment() and check for a  
> $_POST variable that you've added
>
> However:
> compact() takes a list of variables and compacts them into an array,  
> As well as adding to that line, you need to also add the actual  
> variable, eg, something similar to:
> $comment_author_url   = trim($_POST['url']);
> $comment_content      = trim($_POST['comment']);
>
> So i miught use
> $d_plugin = trim($_POST['d_plugin']);
>
> compact('comment_post_ID', ...., 'd_plugin');
>
> On Wed, 24 Sep 2008 11:53:47 +1000, MLR <mlrichard at gmail.com> wrote:
>
>> Hi,
>>
>> I have created new columns in wp_comments and new input fields in a  
>> blog to
>> gather more data along with the comments (Gender, Age, etc.)
>>
>> I have modified wp-comments-post.php to gather these new POST  
>> variables and
>> added the column names to  the $commentdata = compact() line
>>
>> Currently my mods are not causing an error but obviously the new  
>> fields are
>> empty on save.
>>
>> What else should I tweak beyond that? I have looked in the Codex  
>> and on the
>> Web for an answer but the search results are overwhelmed with generic
>> unrelated info.
>>
>> Thanks for pointing me in the right direction,
>>
>> Marie-Lynn
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list