Make WordPress Core

#56279 closed enhancement (fixed)

Use wp_get_latest_revision_id_and_total_count() where appropriate

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.1 Priority: normal
Severity: normal Version: 6.1
Component: Revisions Keywords: has-patch
Focuses: Cc:

Description (last modified by SergeyBiryukov)

Background: #55857

A new function wp_get_latest_revision_id_and_total_count(), with an optimized query to get the last revision ID and total count, was introduced in [53759], [53769], and [53778].

As noted in comment:4:ticket:55857, there are a few other places in core that could use it.

Attachments (3)

56279.diff (2.1 KB) - added by SergeyBiryukov 22 months ago.
56279.2.diff (1.7 KB) - added by SergeyBiryukov 22 months ago.
56279.3.diff (2.2 KB) - added by SergeyBiryukov 22 months ago.

Download all attachments as: .zip

Change History (9)

#1 @mukesh27
22 months ago

  • Keywords needs-refresh added

One extra semicolon is added in the patch, file wp-includes\revision.php. Can you please remove it?

#2 follow-up: @peterwilsoncc
22 months ago

I've reopened #55857 to rename the function to wp_get_latest_revision_id_and_total_count() so the function follows the conventional term used for getting latest posts, comments, etc.

Please hold of committing this change until the rename is complete.

#3 in reply to: ↑ 2 @SergeyBiryukov
22 months ago

  • Keywords needs-refresh removed

Replying to peterwilsoncc:

I've reopened #55857 to rename the function to wp_get_latest_revision_id_and_total_count() so the function follows the conventional term used for getting latest posts, comments, etc.

Thanks! 56279.2.diff switches to "latest" and removes the extra semicolon from the previous patch.

There may be more instances where the function can be used, these are just the ones I found at a glance.

#4 @SergeyBiryukov
22 months ago

  • Description modified (diff)
  • Summary changed from Use wp_get_last_revision_id_and_total_count() where appropriate to Use wp_get_latest_revision_id_and_total_count() where appropriate

#5 @SergeyBiryukov
22 months ago

Refreshed after [53841]. Found one more place to use this in wp_update_custom_css_post().

#6 @SergeyBiryukov
22 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 53842:

Revisions: Use wp_get_latest_revision_id_and_total_count() where appropriate.

The function executes an optimized query to get the last revision ID and total count. It was originally introduced for WP_REST_Posts_Controller::prepare_links(), and is now used in a few more places in core:

  • register_and_do_post_meta_boxes()
  • wp_get_post_revisions_url()
  • wp_update_custom_css_post()

Follow-up to [53759], [53769], [53778], [53779], [53841].

Props peterwilsoncc, mukesh27, SergeyBiryukov.
Fixes #56279.

Note: See TracTickets for help on using tickets.