wp_delete_post_revision() WordPress Function

The wp_delete_post_revision() function is used to delete a revision for a post. The function takes the post ID as the first parameter and the revision ID as the second parameter.

wp_delete_post_revision( int|WP_Post $revision_id ) #

Deletes a revision.


Description

Deletes the row from the posts table corresponding to the specified revision.


Top ↑

Parameters

$revision_id

(int|WP_Post)(Required)Revision ID or revision object.


Top ↑

Return

(WP_Post|false|null) Null or false if error, deleted post object if success.


Top ↑

Source

File: wp-includes/revision.php

function wp_delete_post_revision( $revision_id ) {
	$revision = wp_get_post_revision( $revision_id );
	if ( ! $revision ) {
		return $revision;
	}

	$delete = wp_delete_post( $revision->ID );
	if ( $delete ) {
		/**
		 * Fires once a post revision has been deleted.
		 *
		 * @since 2.6.0
		 *
		 * @param int     $revision_id Post revision ID.
		 * @param WP_Post $revision    Post revision object.
		 */
		do_action( 'wp_delete_post_revision', $revision->ID, $revision );
	}

	return $delete;
}


Top ↑

Changelog

Changelog
VersionDescription
2.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.