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
wp_update_comment_count_now
Definition:
function wp_update_comment_count_now($post_id) {}
Parameters
Return values
returns:False on ‘0’ $post_id or if post with ID does not exist. True on success.
Defined actions
do_action('wp_update_comment_count', $post_id, $new, $old);do_action('edit_post', $post_id, $post);Source code
function wp_update_comment_count_now($post_id) { global $wpdb; $post_id = (int) $post_id; if ( !$post_id ) return false; if ( !$post = get_post($post_id) ) return false; $old = (int) $post->comment_count; $new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id) ); $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) ); if ( 'page' == $post->post_type ) clean_page_cache( $post_id ); else clean_post_cache( $post_id ); do_action('wp_update_comment_count', $post_id, $new, $old); do_action('edit_post', $post_id, $post); return true; }4219