acf_insert_or_update_internal_post() │ ACF 6.8.11

Inserts or updates one of ACF's internal posts (fields, field groups, post types, taxonomies and options pages), storing its serialized post_content as given.

Filters on content_save_pre convert_invalid_entities, etc.) treat the serialized settings as HTML and can change string lengths, which corrupts them. Settings must already be sanitized, see _acf_maybe_kses_internal_post_settings().

Хуков нет.

Возвращает

integer|WP_Error. The post ID on success. The value 0 or WP_Error on failure.

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

acf_insert_or_update_internal_post( $postarr );
$postarr(массив) (обязательный)
Slashed post data, as passed to wp_insert_post().

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

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

Код acf_insert_or_update_internal_post() ACF 6.8.11

function acf_insert_or_update_internal_post( $postarr ) {
	// Remember the exact content being saved, so other posts written by hooks during the save are still filtered.
	$saving = acf_get_data( 'saving_internal_post_content' );
	acf_set_data( 'saving_internal_post_content', $postarr['post_content'] ?? null );

	try {
		if ( ! empty( $postarr['ID'] ) ) {
			return wp_update_post( $postarr );
		}

		return wp_insert_post( $postarr );
	} finally {
		acf_set_data( 'saving_internal_post_content', $saving );
	}
}