wp_update_comment() – Updates an existing comment in the database.

You appear to be a bot. Output may be restricted

Description

Updates an existing comment in the database.

Filters the comment and makes sure certain fields are valid before updating.

Usage

$int|false|WP_Error = wp_update_comment( $commentarr, $wp_error );

Parameters

$commentarr
( array ) required – Contains information on the comment.
$wp_error
( bool ) optional – Optional. Whether to return a WP_Error on failure. Default false.

Returns

int|false|WP_Error The value 1 if the comment was updated, 0 if not updated. False or a WP_Error object on failure.

Source

File name: wordpress/wp-includes/comment.php
Lines:

101 to 153 of 153
    'comment_author_IP',
    'comment_date',
    'comment_date_gmt',
    'comment_content',
    'comment_karma',
    'comment_approved',
    'comment_agent',
    'comment_type',
    'comment_parent',
    'user_id',
  );

  $data = wp_array_slice_assoc( $data, $keys );

  $result = $wpdb->update( $wpdb->comments, $data, array( 'comment_ID' => $comment_id ) );

  if ( false === $result ) {
    if ( $wp_error ) {
      return new WP_Error( 'db_update_error', __( 'Could not update comment in the database.' ), $wpdb->last_error );
    } else {
      return false;
    }
  }

  // If metadata is provided, store it.
  if ( isset( $commentarr['comment_meta'] ) && is_array( $commentarr['comment_meta'] ) ) {
    foreach ( $commentarr['comment_meta'] as $meta_key => $meta_value ) {
      update_comment_meta( $comment_id, $meta_key, $meta_value );
    }
  }

  clean_comment_cache( $comment_id );
  wp_update_comment_count( $comment_post_id );

  
/**
 * Fires immediately after a comment is updated in the database.
 *
 * The hook also fires immediately before comment status transition hooks are fired.
 *
 * @since 1.2.0
 * @since 4.6.0 Added the `$data` parameter.
 *
 * @param int   $comment_id The comment ID.
 * @param array $data       Comment data.
 */
  do_action( 'edit_comment', $comment_id, $data );

  $comment = get_comment( $comment_id );

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

  return $result;
}
 

 View on GitHub View on Trac