wppaste
WordPress

wp_untrash_post_comments( int|WP_Post|null $post = null ): true|void

Since
2.9.0
Source
wp-includes/post.php:4129
Restores comments for a post from the Trash.

Compatibility

WordPress
since 2.9.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$postint|WP_Post|nulloptional
Post ID or post object. Defaults to global $post.Default: null

Return value

true|void

Performance profile

How much work a call to wp_untrash_post_comments() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_post().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
8–41

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 72.

Plugin surface
2 hooks

Third-party callbacks on 'untrash_post_comments', 'untrashed_post_comments' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksdo_action()called directly
  • cacheobject cachewp_cache_delete_multiple()one call below wp_untrash_post_comments()

Further down the call graph this can also reach serialize, option and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 3 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_untrash_post_comments() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always8get_post()
always16get_post(), get_post_meta()
always39–41get_post(), get_post_meta(), do_action(), array_keys(), clean_comment_cache(), delete_post_meta(), do_action()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev728–417
8.5728–417
8.4728–4173 fewer instructions than PHP 8.3
8.3758–417
8.2758–417
8.1758–417
7.4758–417

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 2

2 hooks fire while wp_untrash_post_comments() runs, in this order:

  1. do_action( untrash_post_comments )actionline 4153 (+24 into the body)

    Fires before comments are restored for a post from the Trash.

  2. do_action( untrashed_post_comments )actionline 4181 (+52 into the body)

    Fires after comments are restored for a post from the Trash.

Uses · 5

Used by · 1

Source code

function wp_untrash_post_comments( $post = null ) {	global $wpdb; 	$post = get_post( $post ); 	if ( ! $post ) {		return;	} 	$post_id = $post->ID; 	$statuses = get_post_meta( $post_id, '_wp_trash_meta_comments_status', true ); 	if ( ! $statuses ) {		return true;	} 	/**	 * Fires before comments are restored for a post from the Trash.	 *	 * @since 2.9.0	 *	 * @param int $post_id Post ID.	 */	do_action( 'untrash_post_comments', $post_id ); 	// Restore each comment to its original status.	$group_by_status = array();	foreach ( $statuses as $comment_id => $comment_status ) {		$group_by_status[ $comment_status ][] = $comment_id;	} 	foreach ( $group_by_status as $status => $comments ) {		// Confidence check. This shouldn't happen.		if ( 'post-trashed' === $status ) {			$status = '0';		}		$comments_in = implode( ', ', array_map( 'intval', $comments ) );		$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->comments SET comment_approved = %s WHERE comment_ID IN ($comments_in)", $status ) );	} 	clean_comment_cache( array_keys( $statuses ) ); 	delete_post_meta( $post_id, '_wp_trash_meta_comments_status' ); 	/**	 * Fires after comments are restored for a post from the Trash.	 *	 * @since 2.9.0	 *	 * @param int $post_id Post ID.	 */	do_action( 'untrashed_post_comments', $post_id );}

Changelog

Introduced in 2.9.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.1.0
Return type changed from true|void to true|null.verified against source
2.9.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.