| | 437 | * Return the count of revisions for a given post. |
| | 438 | * |
| | 439 | * @since 4.5.0 |
| | 440 | * |
| | 441 | * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. |
| | 442 | * @return int The count of revisions for this post, false if post invalid. |
| | 443 | */ |
| | 444 | function wp_get_post_revision_count( $post_id = 0 ) { |
| | 445 | global $wpdb; |
| | 446 | |
| | 447 | $post = get_post( $post_id ); |
| | 448 | if ( ! $post || empty( $post->ID ) ) { |
| | 449 | return false; |
| | 450 | } |
| | 451 | |
| | 452 | $revision_count = intval( |
| | 453 | $wpdb->get_var( |
| | 454 | $wpdb->prepare( " |
| | 455 | SELECT COUNT(1) |
| | 456 | FROM $wpdb->posts |
| | 457 | WHERE post_parent = %d |
| | 458 | AND post_type = 'revision' |
| | 459 | AND post_status = 'inherit'", |
| | 460 | $post->ID |
| | 461 | ) |
| | 462 | ) |
| | 463 | ); |
| | 464 | return $revision_count; |
| | 465 | } |
| | 466 | |
| | 467 | /** |
| | 468 | * Return the id of the last stored revision. |
| | 469 | * |
| | 470 | * @since 4.5.0 |
| | 471 | * |
| | 472 | * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. |
| | 473 | * @return int The id of the last stored revision for this post, false if post invalid. |
| | 474 | */ |
| | 475 | function wp_get_last_revision_id( $post_id = 0 ) { |
| | 476 | global $wpdb; |
| | 477 | |
| | 478 | $post = get_post( $post_id ); |
| | 479 | if ( ! $post || empty( $post->ID ) ) { |
| | 480 | return false; |
| | 481 | } |
| | 482 | |
| | 483 | $last_revision_id = intval( |
| | 484 | $wpdb->get_var( |
| | 485 | $wpdb->prepare( " |
| | 486 | SELECT ID, post_date |
| | 487 | FROM $wpdb->posts |
| | 488 | WHERE post_parent = %d |
| | 489 | AND post_type = 'revision' |
| | 490 | AND post_status = 'inherit' |
| | 491 | ORDER BY post_date DESC, ID DESC |
| | 492 | LIMIT 1", |
| | 493 | $post->ID |
| | 494 | ) |
| | 495 | ) |
| | 496 | ); |
| | 497 | return $last_revision_id; |
| | 498 | } |
| | 499 | |
| | 500 | /** |