Ticket #39062: 39062.diff
File 39062.diff, 2.6 KB (added by , 8 years ago) |
---|
-
src/wp-includes/revision.php
457 457 } 458 458 459 459 /** 460 * Get the url for viewing and potentially restoring revisions of a given post. 461 * 462 * @param int $post_id The Post ID that you'd like to get a revision for. If omitted, will use the global post. 463 * @return null|string The URL for editing revisions on the given post. Returns null if none found. 464 */ 465 function wp_get_post_revisions_url( $post_id = 0 ) { 466 $post = get_post( $post_id ); 467 468 if ( ! $post instanceof WP_Post ) { 469 return null; 470 } 471 472 // If we were passed in a Revision, return early. 473 if ( 'revision' === $post->post_type ) { 474 return get_edit_post_link( $post ); 475 } 476 477 if ( ! wp_revisions_enabled( $post ) ) { 478 return null; 479 } 480 481 $revisions = wp_get_post_revisions( $post->ID, array( 482 'posts_per_page' => 1 483 ) ); 484 485 if ( 0 === sizeof( $revisions ) ) { 486 return null; 487 } 488 489 $revision = reset( $revisions ); 490 return get_edit_post_link( $revision ); 491 } 492 493 /** 460 494 * Determine if revisions are enabled for a given post. 461 495 * 462 496 * @since 3.6.0 -
tests/phpunit/tests/post/revisions.php
382 382 383 383 $this->assertEquals( $revision_ids, array_values( wp_list_pluck( $revisions, 'ID' ) ) ); 384 384 } 385 386 /** 387 * Test fetching the revision urls of a given post. 388 */ 389 function test_wp_get_post_revisions_url() { 390 $u = self::factory()->user->create( array( 391 'role' => 'administrator' 392 ) ); 393 wp_set_current_user( $u ); 394 395 $post = self::factory()->post->create_and_get( array( 396 'post_title' => 'Some Post', 397 ) ); 398 399 wp_update_post( array( 400 'ID' => $post->ID, 401 'post_title' => 'Some Post 2', 402 ) ); 403 404 $latest_revision_id = key( wp_get_post_revisions( $post, array( 'posts_per_page' => 1 ) ) ); 405 $this->assertEquals( admin_url( 'revision.php?revision=' . $latest_revision_id ), wp_get_post_revisions_url( $post ) ); 406 407 wp_update_post( array( 408 'ID' => $post->ID, 409 'post_title' => 'Some Post 3', 410 ) ); 411 412 $latest_revision_id = key( wp_get_post_revisions( $post, array( 'posts_per_page' => 1 ) ) ); 413 $this->assertEquals( admin_url( 'revision.php?revision=' . $latest_revision_id ), wp_get_post_revisions_url( $post ) ); 414 $this->assertEquals( admin_url( 'revision.php?revision=' . $latest_revision_id ), wp_get_post_revisions_url( $latest_revision_id ) ); 415 } 385 416 }