wppaste
WordPress

wp_autosave_post_revisioned_meta_fields( array $new_autosave )

Since
6.4.0
Source
wp-admin/includes/post.php:2029
Autosaves the revisioned meta fields.

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

Reaches the database via get_post().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
18–20

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 56.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • querycontent queryget_post()one call below wp_autosave_post_revisioned_meta_fields()
  • hookthird-party callbacksapply_filters()one call below wp_autosave_post_revisioned_meta_fields()
  • serializeserialisationmaybe_serialize()one call below wp_autosave_post_revisioned_meta_fields()
  • cacheobject cachewp_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.

WhenInstructionsCalls it makes
always18–20get_post_type(), wp_post_revision_meta_keys()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev5618–206
8.55618–206
8.45618–206
8.35618–206
8.25618–206
8.15618–2061 fewer instruction than PHP 7.4
7.45718–216

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

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.