wp_autosave_post_revisioned_meta_fields( array $new_autosave )
- Since
- 6.4.0
- Source
wp-admin/includes/post.php:2029
Description
Iterates through the revisioned meta fields and checks each to see if they are set, and have a changed value. If so, the meta value is saved and attached to the autosave.
Compatibility
- WordPress
- since 6.4.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
$new_autosavearray- The new post data being autosaved.
Performance profile
How much work a call to wp_autosave_post_revisioned_meta_fields() 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
- 18–20
- Plugin surface
- None
- 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 56.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_post()one call below wp_autosave_post_revisioned_meta_fields() - hookthird-party callbacks
apply_filters()one call below wp_autosave_post_revisioned_meta_fields() - serializeserialisation
maybe_serialize()one call below wp_autosave_post_revisioned_meta_fields() - cacheobject cache
wp_cache_delete_multiple()one call below wp_autosave_post_revisioned_meta_fields()
Further down the call graph this can also reach option 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 · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_autosave_post_revisioned_meta_fields() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 18–20 | get_post_type(), wp_post_revision_meta_keys() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 56 | 18–20 | 6 | |
| 8.5 | 56 | 18–20 | 6 | |
| 8.4 | 56 | 18–20 | 6 | |
| 8.3 | 56 | 18–20 | 6 | |
| 8.2 | 56 | 18–20 | 6 | |
| 8.1 | 56 | 18–20 | 6 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 57 | 18–21 | 6 |
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.
Uses · 6
- get_post_type()Retrieves the post type of the current post or of a given post.
- wp_post_revision_meta_keys()Determine which post meta fields should be revisioned.
- get_post_meta()Retrieves a post meta field for the given post ID.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- delete_metadata()Deletes metadata for the specified object.
- add_metadata()Adds metadata for the specified object.
Source code
function wp_autosave_post_revisioned_meta_fields( $new_autosave ) { /* * The post data arrives as either $_POST['data']['wp_autosave'] or the $_POST * itself. This sets $posted_data to the correct variable. * * Ignoring sanitization to avoid altering meta. Ignoring the nonce check because * this is hooked on inner core hooks where a valid nonce was already checked. */ $posted_data = $_POST['data']['wp_autosave'] ?? $_POST; $post_type = get_post_type( $new_autosave['post_parent'] ); /* * Go through the revisioned meta keys and save them as part of the autosave, * if the meta key is part of the posted data, the meta value is not blank, * and the meta value has changes from the last autosaved value. */ foreach ( wp_post_revision_meta_keys( $post_type ) as $meta_key ) { if ( isset( $posted_data[ $meta_key ] ) && get_post_meta( $new_autosave['ID'], $meta_key, true ) !== wp_unslash( $posted_data[ $meta_key ] ) ) { /* * Use the underlying delete_metadata() and add_metadata() functions * vs delete_post_meta() and add_post_meta() to make sure we're working * with the actual revision meta. */ delete_metadata( 'post', $new_autosave['ID'], $meta_key ); // One last check to ensure meta value is not empty. if ( ! empty( $posted_data[ $meta_key ] ) ) { // Add the revisions meta data to the autosave. add_metadata( 'post', $new_autosave['ID'], $meta_key, $posted_data[ $meta_key ] ); } } }}Changelog
Introduced in 6.4.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/post.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.