wp_update_comment_count_now

Definition:
function wp_update_comment_count_now($post_id) {}

Updates the comment count for the post.

Parameters

  • int $post_id: Post ID

Return values

returns:False on ‘0’ $post_id or if post with ID does not exist. True on success.

Defined actions

  • wp_update_comment_count
    do_action('wp_update_comment_count', $post_id, $new, $old);
  • edit_post
    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

wp_update_comment_count

Definition:
function wp_update_comment_count($post_id, $do_deferred=false) {}

Updates the comment count for post(s).
When $do_deferred is false (is by default) and the comments have been set to be deferred, the post_id will be added to a queue, which will be updated at a later date and only updated once per post ID.

Parameters

  • int $post_id: Post ID
  • bool $do_deferred: Whether to process previously deferred post comment counts

Return values

returns:True on success, false on failure

Source code

function wp_update_comment_count($post_id, $do_deferred=false) {

	static $_deferred = array();



	if ( $do_deferred ) {

		$_deferred = array_unique($_deferred);

		foreach ( $_deferred as $i => $_post_id ) {

			wp_update_comment_count_now($_post_id);

			unset( $_deferred[$i] ); /** @todo Move this outside of the foreach and reset $_deferred to an array instead */

		}

	}



	if ( wp_defer_comment_counting() ) {

		$_deferred[] = $post_id;

		return true;

	}

	elseif ( $post_id ) {

		return wp_update_comment_count_now($post_id);

	}



}

4217

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

wp_update_category

Definition:
function wp_update_category($catarr) {}

Aliases wp_insert_category() with minimal args.
If you want to update only some fields of an existing category, call this function with only the new values set inside $catarr.

Parameters

  • array $catarr: The ‘cat_ID’ value is required. All other keys are optional.

Return values

returns:The ID number of the new or updated Category on success. Zero or FALSE on failure.

Source code

function wp_update_category($catarr) {

	$cat_ID = (int) $catarr['cat_ID'];



	if ( isset($catarr['category_parent']) && ($cat_ID == $catarr['category_parent']) )

		return false;



	// First, get all of the original fields

	$category = get_category($cat_ID, ARRAY_A);



	// Escape data pulled from DB.

	$category = add_magic_quotes($category);



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

	$catarr = array_merge($category, $catarr);



	return wp_insert_category($catarr);

}

4213