wp_get_revision_ui_diff( WP_Post|int $post, int $compare_from, int $compare_to ): array|false
- Since
- 3.6.0
- Source
wp-admin/includes/revision.php:21
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.
$compare_fromint- The revision ID to compare from.
$compare_toint- The revision ID to come to.
Return value
array|false- Associative array of a post's revisioned fields and their diffs.
Or, false on failure.
Performance profile
How much work a call to wp_get_revision_ui_diff() 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
- 9–79
- Plugin surface
- 3 hooks
- Called by
- 2
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 188.
Third-party callbacks on '_wp_post_revision_field_{$field}', 'revision_text_diff_options', 'wp_get_revision_ui_diff' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 13 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_revision_ui_diff() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 9 | get_post() |
| always | 15–33 | get_post(), get_post() |
| always | 20–37 | get_post(), get_post(), get_post() |
!empty($compare_to) | 36–49 | get_post(), get_post(), _wp_post_revision_fields(), apply_filters() |
!empty($compare_to) | 40–53 | get_post(), get_post(), get_post(), _wp_post_revision_fields(), apply_filters() |
empty($compare_to) | 41–54 | get_post(), get_post(), __(), _wp_post_revision_fields(), apply_filters() |
empty($compare_to) | 45–58 | get_post(), get_post(), get_post(), __(), _wp_post_revision_fields(), apply_filters() |
!empty($compare_to) | 47–65 | get_post(), get_post(), strtotime(), strtotime(), _wp_post_revision_fields(), apply_filters() |
!empty($compare_to) | 51–69 | get_post(), get_post(), get_post(), strtotime(), strtotime(), _wp_post_revision_fields(), apply_filters() |
| always | 52–70 | get_post(), get_post(), strtotime(), strtotime(), __(), _wp_post_revision_fields(), apply_filters() |
| always | 56–74 | get_post(), get_post(), get_post(), strtotime(), strtotime(), __(), _wp_post_revision_fields(), apply_filters() |
empty($compare_from) && empty($compare_to) | 59–75 | get_post(), get_post(), strtotime(), strtotime(), __(), __(), _wp_post_revision_fields(), apply_filters() |
1 further outcome, up to 79 instructions
empty($compare_from) && empty($compare_to) | 63–79 | get_post(), get_post(), get_post(), strtotime(), strtotime(), __(), __(), _wp_post_revision_fields(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 187 | 9–79 | 22 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 188 | 9–79 | 22 | |
| 8.4 | 188 | 9–79 | 22 | |
| 8.3 | 188 | 9–79 | 22 | |
| 8.2 | 188 | 9–79 | 22 | |
| 8.1 | 188 | 9–79 | 22 | |
| 7.4 | 188 | 9–79 | 22 |
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 · 4
4 hooks fire while wp_get_revision_ui_diff() runs, in this order:
- apply_filters( _wp_post_revision_field_{$field} )filterline 90 (+69 into the body)
Contextually filter a post revision field.
- apply_filters( _wp_post_revision_field_{$field} )filterline 93 (+72 into the body)
Contextually filter a post revision field.
- apply_filters( revision_text_diff_options )filterline 118 (+97 into the body)
Filters revisions text diff options.
- apply_filters( wp_get_revision_ui_diff )filterline 163 (+142 into the body)
Filters the fields displayed in the post revision diff UI.
Uses · 6
- get_post()Retrieves post data given a post ID or post object.
- __()Retrieves the translation of $text.
- _wp_post_revision_fields()Determines which fields of posts are to be saved in revisions.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_text_diff()Displays a human readable HTML representation of the difference between two strings.
- esc_html()Escaping for HTML blocks.
Used by · 2
- wp_ajax_get_revision_diffs()Handles getting revision diffs via AJAX.
- wp_prepare_revisions_for_js()Prepare revisions for JavaScript.
Source code
function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) { $post = get_post( $post ); if ( ! $post ) { return false; } if ( $compare_from ) { $compare_from = get_post( $compare_from ); if ( ! $compare_from ) { return false; } } else { // If we're dealing with the first revision... $compare_from = false; } $compare_to = get_post( $compare_to ); if ( ! $compare_to ) { return false; } /* * If comparing revisions, make sure we are dealing with the right post parent. * The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves. */ if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID ) { return false; } if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID ) { return false; } if ( $compare_from && strtotime( $compare_from->post_date_gmt ) > strtotime( $compare_to->post_date_gmt ) ) { $temp = $compare_from; $compare_from = $compare_to; $compare_to = $temp; } // Add default title if title field is empty. if ( $compare_from && empty( $compare_from->post_title ) ) { $compare_from->post_title = __( '(no title)' ); } if ( empty( $compare_to->post_title ) ) { $compare_to->post_title = __( '(no title)' ); } $return = array(); foreach ( _wp_post_revision_fields( $post ) as $field => $name ) { /** * Contextually filter a post revision field. * * The dynamic portion of the hook name, `$field`, corresponds to a name of a * field of the revision object. * * Possible hook names include: * * - `_wp_post_revision_field_post_title` * - `_wp_post_revision_field_post_content` * - `_wp_post_revision_field_post_excerpt` * * @since 3.6.0 * * @param string $revision_field The current revision field to compare to or from. * @param string $field The current revision field. * @param WP_Post $compare_from The revision post object to compare to or from. * @param string $context The context of whether the current revision is the old * or the new one. Either 'to' or 'from'. */ $content_from = $compare_from ? apply_filters( "_wp_post_revision_field_{$field}", $compare_from->$field, $field, $compare_from, 'from' ) : ''; /** This filter is documented in wp-admin/includes/revision.php */ $content_to = apply_filters( "_wp_post_revision_field_{$field}", $compare_to->$field, $field, $compare_to, 'to' ); $args = array( 'show_split_view' => true, 'title_left' => __( 'Removed' ), 'title_right' => __( 'Added' ), );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 6.7.7 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.