ACF_Internal_Post_Type::update_postpublicACF 6.1

Updates an ACF post.

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

Возвращает

Массив.

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

$ACF_Internal_Post_Type = new ACF_Internal_Post_Type();
$ACF_Internal_Post_Type->update_post( $post );
$post(массив) (обязательный)
The ACF post to update.

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

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

Код ACF_Internal_Post_Type::update_post() ACF 6.4.2

public function update_post( $post ) {
	// Validate internal post type.
	$post = $this->validate_post( $post );

	// May have been posted. Remove slashes.
	$post = wp_unslash( $post );

	// Parse types (converts string '0' to int 0).
	$post = acf_parse_types( $post );

	/**
	 * Fires before updating an ACF post in the database.
	 *
	 * @since 6.1
	 *
	 * @param array $post The main ACF post array.
	 */
	$post = apply_filters( "acf/pre_update_{$this->hook_name}", $post );

	// Make a backup of internal post type data and remove some args.
	$_post = $post;
	acf_extract_vars( $_post, array( 'ID', 'key', 'title', 'menu_order', 'fields', 'active', '_valid', '_parent' ) );

	// Create array of data to save.
	$save = array(
		'ID'             => $post['ID'],
		'post_status'    => $post['active'] ? 'publish' : 'acf-disabled',
		'post_type'      => $this->post_type,
		'post_title'     => $post['title'],
		'post_name'      => $post['key'],
		'post_excerpt'   => sanitize_title( $post['title'] ),
		'post_content'   => maybe_serialize( $_post ),
		'menu_order'     => $post['menu_order'],
		'comment_status' => 'closed',
		'ping_status'    => 'closed',
		'post_parent'    => ! empty( $post['_parent'] ) ? (int) $post['_parent'] : 0,
	);

	// Unhook wp_targeted_link_rel() filter from WP 5.1 corrupting serialized data.
	remove_filter( 'content_save_pre', 'wp_targeted_link_rel' );

	// Slash data.
	// WP expects all data to be slashed and will unslash it (fixes '\' character issues).
	$save = wp_slash( $save );

	// Update or Insert.
	if ( $post['ID'] ) {
		wp_update_post( $save );
	} else {
		$post['ID'] = wp_insert_post( $save );
	}

	$this->flush_post_cache( $post );

	/**
	 * Fires immediately after an ACF post has been updated.
	 *
	 * @since   6.1
	 *
	 * @param array $post The main ACF post array.
	 */
	do_action( "acf/update_{$this->hook_name}", $post );

	return $post;
}