_acf_preserve_internal_post_content() │ ACF 6.8.11

Private callback for the "wp_insert_post_data" filter.

Restores the unsanitized post_content ACF's internal posts when it's the content being saved by acf_insert_or_update_internal_post(), or when an update leaves the content unchanged, such as trashing or restoring. Both values are slashed at this point. Follows WP_Customize_Manager::preserve_insert_changeset_post_content().

Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.

Хуков нет.

Возвращает

array.

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

_acf_preserve_internal_post_content( $data, $postarr, $unsanitized_postarr, $update );
$data(массив) (обязательный)
An array of slashed, sanitized post data.
$postarr(массив) (обязательный)
An array of sanitized post data.
$unsanitized_postarr(массив) (обязательный)
An array of slashed yet unsanitized post data.
$update(true|false)
Whether this is an existing post being updated.
По умолчанию: false

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

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

Код _acf_preserve_internal_post_content() ACF 6.8.11

function _acf_preserve_internal_post_content( $data, $postarr, $unsanitized_postarr, $update = false ) {
	$internal_post_types = array_merge( array( 'acf-field' ), acf_get_internal_post_types() );

	if ( ! isset( $data['post_type'], $unsanitized_postarr['post_content'] ) || ! in_array( $data['post_type'], $internal_post_types, true ) ) {
		return $data;
	}

	$expected = acf_get_data( 'saving_internal_post_content' );
	$preserve = null !== $expected && $expected === $unsanitized_postarr['post_content'];

	// Updates that only change the status, like trashing or restoring, resave the stored content.
	if ( ! $preserve && $update && ! empty( $postarr['ID'] ) ) {
		$stored   = wp_slash( get_post_field( 'post_content', $postarr['ID'], 'raw' ) );
		$preserve = $stored === $unsanitized_postarr['post_content'];
	}

	if ( $preserve ) {
		$data['post_content'] = $unsanitized_postarr['post_content'];
	}

	return $data;
}