wp_get_post_revisions_url() WordPress Function

The wp_get_post_revisions_url() function retrieves the URL for a post's revision history.

wp_get_post_revisions_url( int|WP_Post $post_id ) #

Returns the url for viewing and potentially restoring revisions of a given post.


Parameters

$post_id

(int|WP_Post)(Optional) Post ID or WP_Post object. Default is global $post.


Top ↑

Return

(null|string) The URL for editing revisions on the given post, otherwise null.


Top ↑

Source

File: wp-includes/revision.php

function wp_get_post_revisions_url( $post_id = 0 ) {
	$post = get_post( $post_id );

	if ( ! $post instanceof WP_Post ) {
		return null;
	}

	// If the post is a revision, return early.
	if ( 'revision' === $post->post_type ) {
		return get_edit_post_link( $post );
	}

	if ( ! wp_revisions_enabled( $post ) ) {
		return null;
	}

	$revisions = wp_get_post_revisions( $post->ID, array( 'posts_per_page' => 1 ) );

	if ( 0 === count( $revisions ) ) {
		return null;
	}

	$revision = reset( $revisions );
	return get_edit_post_link( $revision );
}


Top ↑

Changelog

Changelog
VersionDescription
5.9.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.