| | 437 | * Returns the revision details of specified post. |
| | 438 | * |
| | 439 | * Data includes details about each revision on a post. Includes ID, post_author, |
| | 440 | * post_date, post_date_gmt, post_title, post_status, post_parent, and post_modified. |
| | 441 | * |
| | 442 | * @since 4.5.0 |
| | 443 | * |
| | 444 | * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. |
| | 445 | * @return array An array of revision details, or an empty array if post invalid. |
| | 446 | */ |
| | 447 | function wp_get_post_revisions_details( $post_id = 0, $args = null ) { |
| | 448 | global $wpdb; |
| | 449 | |
| | 450 | $post = get_post( $post_id ); |
| | 451 | if ( ! $post || empty( $post->ID ) ) { |
| | 452 | return array(); |
| | 453 | } |
| | 454 | |
| | 455 | $revision_details = $wpdb->get_results( |
| | 456 | $wpdb->prepare( " |
| | 457 | SELECT ID, post_author, post_date, post_date_gmt, post_title, post_status, post_parent, post_modified |
| | 458 | FROM $wpdb->posts |
| | 459 | WHERE post_parent = %d |
| | 460 | AND post_type = 'revision' |
| | 461 | AND post_status = 'inherit' |
| | 462 | ORDER BY post_date DESC, ID DESC", |
| | 463 | $post->ID |
| | 464 | ) |
| | 465 | ); |
| | 466 | |
| | 467 | return $revision_details; |
| | 468 | } |
| | 469 | |
| | 470 | /** |
| | 471 | * Return the count of revisions for a given post. |
| | 472 | * |
| | 473 | * @since 4.5.0 |
| | 474 | * |
| | 475 | * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. |
| | 476 | * @return int The count of revisions for this post, false if post invalid. |
| | 477 | */ |
| | 478 | function wp_get_post_revision_count( $post_id = 0 ) { |
| | 479 | global $wpdb; |
| | 480 | |
| | 481 | $post = get_post( $post_id ); |
| | 482 | if ( ! $post || empty( $post->ID ) ) { |
| | 483 | return false; |
| | 484 | } |
| | 485 | |
| | 486 | $revision_count = intval( |
| | 487 | $wpdb->get_var( |
| | 488 | $wpdb->prepare( " |
| | 489 | SELECT COUNT(*) |
| | 490 | FROM $wpdb->posts |
| | 491 | WHERE post_parent = %d |
| | 492 | AND post_type = 'revision' |
| | 493 | AND post_status = 'inherit'", |
| | 494 | $post->ID |
| | 495 | ) |
| | 496 | ) |
| | 497 | ); |
| | 498 | return $revision_count; |
| | 499 | } |
| | 500 | |
| | 501 | /** |
| | 502 | * Return the id of the last stored revision. |
| | 503 | * |
| | 504 | * @since 4.5.0 |
| | 505 | * |
| | 506 | * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. |
| | 507 | * @return int The id of the last stored revision for this post, false if post invalid. |
| | 508 | */ |
| | 509 | function wp_get_last_revision_id( $post_id = 0 ) { |
| | 510 | global $wpdb; |
| | 511 | |
| | 512 | $post = get_post( $post_id ); |
| | 513 | if ( ! $post || empty( $post->ID ) ) { |
| | 514 | return false; |
| | 515 | } |
| | 516 | |
| | 517 | $last_revision_id = intval( |
| | 518 | $wpdb->get_var( |
| | 519 | $wpdb->prepare( " |
| | 520 | SELECT ID, post_date |
| | 521 | FROM $wpdb->posts |
| | 522 | WHERE post_parent = %d |
| | 523 | AND post_type = 'revision' |
| | 524 | AND post_status = 'inherit' |
| | 525 | ORDER BY post_date DESC, ID DESC |
| | 526 | LIMIT 1", |
| | 527 | $post->ID |
| | 528 | ) |
| | 529 | ) |
| | 530 | ); |
| | 531 | return $last_revision_id; |
| | 532 | } |
| | 533 | |
| | 534 | /** |