ACF\Pro\Datastore

REST_Save::save_post_rest │ public │ ACF 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().

Метод класса: REST_Save{}

Хуков нет.

Возвращает

void. Ничего (null).

Использование

$REST_Save = new REST_Save();
$REST_Save->save_post_rest( $post, $request );
$post(WP_Post) (обязательный)
The post object.
$request(WP_REST_Request) (обязательный)
The REST request.

Список изменений

С версии 6.8.1 Введена.

Код REST_Save::save_post_rest() ACF 6.8.11

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;
	}

	$allowed = $this->restrict_values( $post, $values, $meta['_acf'] );

	// Values come from the request meta, never from uploads.
	acf_discard_uploaded_field_values();

	// Keep dropped values out of the stored blob too, which WordPress copies to the revision.
	if ( count( $allowed ) !== count( $values ) ) {
		update_metadata( 'post', $post->ID, '_acf', wp_slash( wp_json_encode( (object) $allowed ) ) );
	}

	$values = $allowed;

	if ( empty( $values ) ) {
		// Nothing to save, but the transport blob still needs removing once the revision system has run.
		$this->pending_cleanup_post_id = $post->ID;
		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;
}