wp_prepare_revisions_for_js( WP_Post|int $post, int $selected_revision_id, int $from = null ): array
- Since
- 3.6.0
- Source
wp-admin/includes/revision.php:176
Compatibility
- WordPress
- since 3.6.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$postWP_Post|int- The post object or post ID.
$selected_revision_idint- The selected revision ID.
$fromintoptional- The revision ID to compare from.Default:
null
Return value
array- An associative array of revision data and related settings.
Performance profile
How much work a call to wp_prepare_revisions_for_js() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 91–202
- Plugin surface
- 1 hook
- Called by
- 0
Reaches the database via get_post().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 359.
Third-party callbacks on 'wp_prepare_revision_for_js' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_post()called directly - optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()one call below wp_prepare_revisions_for_js() - serializeserialisation
maybe_unserialize()one call below wp_prepare_revisions_for_js()
Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 12 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_prepare_revisions_for_js() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$from | 91–108 | get_post(), time(), wp_get_post_revisions(), wp_revisions_enabled(), get_option(), update_post_author_caches(), current_user_can(), absint(), wp_get_revision_ui_diff(), wp_create_nonce(), array_values(), admin_url(), parse_url(), absint(), array_keys() |
!$from | 102–119 | get_post(), time(), wp_get_post_revisions(), wp_revisions_enabled(), get_option(), update_post_author_caches(), current_user_can(), array_keys(), array_search(), absint(), wp_get_revision_ui_diff(), wp_create_nonce(), array_values(), admin_url(), parse_url(), absint(), array_keys() |
empty($current_id) && !$revision && $from | 108–116 | get_post(), time(), wp_get_post_revisions(), wp_revisions_enabled(), get_option(), update_post_author_caches(), current_user_can(), end(), absint(), wp_get_revision_ui_diff(), wp_create_nonce(), array_values(), admin_url(), parse_url(), absint(), array_keys() |
!$from | 117–134 | get_post(), time(), wp_get_post_revisions(), wp_revisions_enabled(), get_option(), update_post_author_caches(), current_user_can(), array_keys(), array_search(), array_slice(), array_keys(), reset(), absint(), wp_get_revision_ui_diff(), wp_create_nonce(), array_values(), admin_url(), parse_url(), absint(), array_keys() |
empty($current_id) && !$revision && !$from | 119–127 | get_post(), time(), wp_get_post_revisions(), wp_revisions_enabled(), get_option(), update_post_author_caches(), current_user_can(), end(), array_keys(), array_search(), absint(), wp_get_revision_ui_diff(), wp_create_nonce(), array_values(), admin_url(), parse_url(), absint(), array_keys() |
empty($current_id) && !$revision && !$from | 134–142 | get_post(), time(), wp_get_post_revisions(), wp_revisions_enabled(), get_option(), update_post_author_caches(), current_user_can(), end(), array_keys(), array_search(), array_slice(), array_keys(), reset(), absint(), wp_get_revision_ui_diff(), wp_create_nonce(), array_values(), admin_url(), parse_url(), absint(), array_keys() |
$from | 151–168 | get_post(), time(), wp_get_post_revisions(), wp_revisions_enabled(), get_option(), update_post_author_caches(), current_user_can(), get_the_title(), __(), strtotime(), date_i18n(), _x(), strtotime(), date_i18n(), __(), strtotime(), human_time_diff(), sprintf(), absint(), wp_get_revision_ui_diff(), wp_create_nonce(), array_values(), admin_url(), parse_url(), absint(), array_keys() |
!$from | 162–179 | get_post(), time(), wp_get_post_revisions(), wp_revisions_enabled(), get_option(), update_post_author_caches(), current_user_can(), get_the_title(), __(), strtotime(), date_i18n(), _x(), strtotime(), date_i18n(), __(), strtotime(), human_time_diff(), sprintf(), array_keys(), array_search(), absint(), wp_get_revision_ui_diff(), wp_create_nonce(), array_values(), admin_url(), parse_url(), absint(), array_keys() |
empty($current_id) && !$revision && $from | 168–176 | get_post(), time(), wp_get_post_revisions(), wp_revisions_enabled(), get_option(), update_post_author_caches(), current_user_can(), get_the_title(), __(), strtotime(), date_i18n(), _x(), strtotime(), date_i18n(), __(), strtotime(), human_time_diff(), sprintf(), end(), absint(), wp_get_revision_ui_diff(), wp_create_nonce(), array_values(), admin_url(), parse_url(), absint(), array_keys() |
!$from | 177–194 | get_post(), time(), wp_get_post_revisions(), wp_revisions_enabled(), get_option(), update_post_author_caches(), current_user_can(), get_the_title(), __(), strtotime(), date_i18n(), _x(), strtotime(), date_i18n(), __(), strtotime(), human_time_diff(), sprintf(), array_keys(), array_search(), array_slice(), array_keys(), reset(), absint(), wp_get_revision_ui_diff(), wp_create_nonce(), array_values(), admin_url(), parse_url(), absint(), array_keys() |
empty($current_id) && !$revision && !$from | 179–187 | get_post(), time(), wp_get_post_revisions(), wp_revisions_enabled(), get_option(), update_post_author_caches(), current_user_can(), get_the_title(), __(), strtotime(), date_i18n(), _x(), strtotime(), date_i18n(), __(), strtotime(), human_time_diff(), sprintf(), end(), array_keys(), array_search(), absint(), wp_get_revision_ui_diff(), wp_create_nonce(), array_values(), admin_url(), parse_url(), absint(), array_keys() |
empty($current_id) && !$revision && !$from | 194–202 | get_post(), time(), wp_get_post_revisions(), wp_revisions_enabled(), get_option(), update_post_author_caches(), current_user_can(), get_the_title(), __(), strtotime(), date_i18n(), _x(), strtotime(), date_i18n(), __(), strtotime(), human_time_diff(), sprintf(), end(), array_keys(), array_search(), array_slice(), array_keys(), reset(), absint(), wp_get_revision_ui_diff(), wp_create_nonce(), array_values(), admin_url(), parse_url(), absint(), array_keys() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 358 | 91–202 | 21 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 359 | 91–202 | 21 | |
| 8.4 | 359 | 91–202 | 21 | 5 fewer instructions than PHP 8.3 |
| 8.3 | 364 | 93–204 | 21 | |
| 8.2 | 364 | 93–204 | 21 | |
| 8.1 | 364 | 93–204 | 21 | |
| 7.4 | 364 | 93–204 | 21 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while wp_prepare_revisions_for_js() runs, in this order:
- apply_filters( wp_prepare_revision_for_js )filterline 282 (+106 into the body)
Filters the array of revisions used on the revisions screen.
Uses · 21
- get_post()Retrieves post data given a post ID or post object.
- wp_get_post_revisions()Returns all revisions of specified post.
- wp_revisions_enabled()Determines whether revisions are enabled for a given post.
- wp_is_post_autosave()Determines if the specified post is an autosave.
- get_option()Retrieves an option value based on an option name.
- update_post_author_caches()Updates post author user caches for a list of post objects.
- current_user_can()Returns whether the current user has the specified capability.
- wp_nonce_url()Retrieves URL with nonce added to URL query.
- add_query_arg()Retrieves a modified URL query string.
- admin_url()Retrieves the URL to the admin area for the current site.
- get_avatar()Retrieves the avatar `` tag for a user, email address, MD5 hash, comment, or post.
- get_the_author_meta()Retrieves the requested data of the author of the current post.
Show all 21
- get_the_title()Retrieves the post title.
- date_i18n()Retrieves the date in localized format, based on a sum of Unix timestamp and timezone offset in seconds.
- __()Retrieves the translation of $text.
- _x()Retrieves translated string with gettext context.
- human_time_diff()Determines the difference between two timestamps.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- absint()Converts a value to non-negative integer.
- wp_get_revision_ui_diff()Get the revision UI diff.
- wp_create_nonce()Creates a cryptographic token tied to a specific action, user, user session, and window of time.
Source code
function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) { $post = get_post( $post ); $authors = array(); $now_gmt = time(); $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false, ) ); // If revisions are disabled, we only want autosaves and the current post. if ( ! wp_revisions_enabled( $post ) ) { foreach ( $revisions as $revision_id => $revision ) { if ( ! wp_is_post_autosave( $revision ) ) { unset( $revisions[ $revision_id ] ); } } $revisions = array( $post->ID => $post ) + $revisions; } $show_avatars = get_option( 'show_avatars' ); update_post_author_caches( $revisions ); $can_restore = current_user_can( 'edit_post', $post->ID ); $current_id = false; foreach ( $revisions as $revision ) { $modified = strtotime( $revision->post_modified ); $modified_gmt = strtotime( $revision->post_modified_gmt . ' +0000' ); if ( $can_restore ) { $restore_link = str_replace( '&', '&', wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'action' => 'restore', ), admin_url( 'revision.php' ) ), "restore-post_{$revision->ID}" ) ); } if ( ! isset( $authors[ $revision->post_author ] ) ) { $authors[ $revision->post_author ] = array( 'id' => (int) $revision->post_author, 'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '', 'name' => get_the_author_meta( 'display_name', $revision->post_author ), ); } $autosave = (bool) wp_is_post_autosave( $revision ); $current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt; if ( $current && ! empty( $current_id ) ) { // If multiple revisions have the same post_modified_gmt, highest ID is current. if ( $current_id < $revision->ID ) { $revisions[ $current_id ]['current'] = false; $current_id = $revision->ID; } else { $current = false; } } elseif ( $current ) { $current_id = $revision->ID; } $revisions_data = array( 'id' => $revision->ID, 'title' => get_the_title( $post->ID ), 'author' => $authors[ $revision->post_author ], 'date' => date_i18n( __( 'M j, Y @ H:i' ), $modified ), 'dateShort' => date_i18n( _x( 'j M Y @ H:i', 'revision date short format' ), $modified ), /* translators: %s: Human-readable time difference. */ 'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ), 'autosave' => $autosave,Changelog
Introduced in 3.6.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-admin/includes/revision.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.