Revisions: Introduce `wp_get_post_revisions_url()` to get URL for editing revisions.
There's now a way to get a link to a given post's revisions. Introducing `wp_get_post_revisions_url()` and its unit tests. Props adamsilverstein, audrasjb, costdev, davidbaumwald, garrett-eclipse, georgestephanis, hellofromTonya, iaaxpage. Fixes #39062. Built from https://develop.svn.wordpress.org/trunk@52095 git-svn-id: http://core.svn.wordpress.org/trunk@51687 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
37c02eb5fe
commit
d9d820660f
|
@ -516,6 +516,40 @@ function wp_get_post_revisions( $post_id = 0, $args = null ) {
|
||||||
return $revisions;
|
return $revisions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the url for viewing and potentially restoring revisions of a given post.
|
||||||
|
*
|
||||||
|
* @since 5.9.0
|
||||||
|
*
|
||||||
|
* @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
|
||||||
|
* @return null|string The URL for editing revisions on the given post, otherwise null.
|
||||||
|
*/
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if revisions are enabled for a given post.
|
* Determine if revisions are enabled for a given post.
|
||||||
*
|
*
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.9-alpha-52094';
|
$wp_version = '5.9-alpha-52095';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue