ACF\Pro\Datastore

REST_Save::save_post_restpublicACF 6.8.1

Processes ACF field values from the REST request. Decodes the _acf blob and saves individual meta keys to the post.

Revision meta is handled separately by save_revision_meta(), which fires later via _wp_put_post_revision after WordPress creates the revision inside wp_after_insert_post().

Method of the class: REST_Save{}

No Hooks.

Returns

null. Nothing (null).

Usage

$REST_Save = new REST_Save();
$REST_Save->save_post_rest( $post, $request );
$post(WP_Post) (required)
The post object.
$request(WP_REST_Request) (required)
The REST request.

Changelog

Since 6.8.1 Introduced.

REST_Save::save_post_rest() code ACF 6.8.8

public function save_post_rest( $post, $request ) {
	// Check if _acf data was included in the request.
	$meta = $request->get_param( 'meta' );
	if ( empty( $meta['_acf'] ) ) {
		return;
	}

	// Retrieve and decode the JSON.
	$acf_json = get_post_meta( $post->ID, '_acf', true );
	$values   = is_string( $acf_json ) ? json_decode( $acf_json, true ) : null;

	if ( empty( $values ) || ! is_array( $values ) ) {
		return;
	}

	// Save individual meta keys to the post.
	// Fires acf/save_post action, runs all ACF processing hooks.
	acf_save_post( $post->ID, $values );

	// Store values for save_revision_meta(), which fires later
	// via _wp_put_post_revision (after wp_after_insert_post creates
	// the revision). Don't delete _acf yet -- the revision comparison
	// needs it on the post when deciding whether to create a revision.
	// cleanup_acf_transport_meta() handles deletion after the revision
	// system finishes.
	$this->current_acf_values      = $values;
	$this->pending_cleanup_post_id = $post->ID;
}