wp_update_comment

Definition:
function wp_update_comment($commentarr) {}

Updates an existing comment in the database.
Filters the comment and makes sure certain fields are valid before updating.

Parameters

  • array $commentarr: Contains information on the comment.

Return values

returns:Comment was updated if value is 1, or was not updated if value is 0.

Defined filters

  • comment_save_pre
    apply_filters('comment_save_pre', $comment_content)

Defined actions

  • edit_comment
    do_action('edit_comment', $comment_ID);

Source code

function wp_update_comment($commentarr) {

	global $wpdb;



	// First, get all of the original fields

	$comment = get_comment($commentarr['comment_ID'], ARRAY_A);



	// Escape data pulled from DB.

	$comment = esc_sql($comment);



	$old_status = $comment['comment_approved'];



	// Merge old and new fields with new fields overwriting old ones.

	$commentarr = array_merge($comment, $commentarr);



	$commentarr = wp_filter_comment( $commentarr );



	// Now extract the merged array.

	extract(stripslashes_deep($commentarr), EXTR_SKIP);



	$comment_content = apply_filters('comment_save_pre', $comment_content);



	$comment_date_gmt = get_gmt_from_date($comment_date);



	if ( !isset($comment_approved) )

		$comment_approved = 1;

	else if ( 'hold' == $comment_approved )

		$comment_approved = 0;

	else if ( 'approve' == $comment_approved )

		$comment_approved = 1;



	$data = compact('comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt');

	$rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) );



	clean_comment_cache($comment_ID);

	wp_update_comment_count($comment_post_ID);

	do_action('edit_comment', $comment_ID);

	$comment = get_comment($comment_ID);

	wp_transition_comment_status($comment->comment_approved, $old_status, $comment);

	return $rval;

}

4215

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: