[wp-hackers] wp_new_comment($commentdata) ignores timestamp?

Mark Jaquith markjaquith at gmail.com
Fri Jul 9 15:31:29 UTC 2010


On Wed, Jul 7, 2010 at 1:57 PM, John Eckman <eckman.john at gmail.com> wrote:
> Is there a way to use wp_new_comment() but force it to accept a timestamp if one is passed in?

Not currently. wp_new_comment() sets comment_date and
comment_date_gmt, ignoring anything you've passed in. Open a Trac
ticket for that and then e-mail me privately and I'll look into it
when we start 3.1 development in September. I'm of the opinion that it
should work like several of the other fields do (set it to the current
time only if it isn't already set).

For now, I recommend that you use the comment_post hook to alter the
date after it has been inserted. Do a just-in-time
registration/unregistration of that hook, wrapped around your
wp_new_comment() call.

// Stick your FB-originated comment_date and comment_date_gmt values somewhere
add_action( 'comment_post', 'your_callback' );
wp_new_comment( $data );
remove_action( 'comment_post', 'your_callback' );

// [...]

function your_callback( $comment_id ) {
	// grab the desired date/date_gmt you saved earlier
	// update the comment using wp_update_comment()
	// no need to fetch the comment, wp_update_comment() will merge data,
so just pass in the date columns
}

-- 
Mark Jaquith
• http://markjaquith.com/http://coveredwebservices.com/


More information about the wp-hackers mailing list