# _wp_keep_alive_customize_changeset_dependent_auto_drafts()

URL: https://chugunov.pro/api-wordpress/functions/_wp_keep_alive_customize_changeset_dependent_auto_drafts/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 4.8.0.

## Сигнатура

```php
_wp_keep_alive_customize_changeset_dependent_auto_drafts( string $new_status, string $old_status, WP_Post $post )
```

## Описание

Когда набор изменений обновляется, но остаётся авточерновиком, post_date авточерновиков записей сохраняется прежним, чтобы они были удалены сборщиком мусора одновременно через wp_delete_auto_drafts(). Иначе, если набор изменений переводится в черновик, записям задаётся post_date в далёком будущем, чтобы они никогда не удалялись сборщиком мусора, пока не будет удалена сама запись набора изменений.
Когда набор изменений переводится в постоянный черновик или ставится в расписание на публикацию, все зависимые авточерновики переводятся в статус «черновик», чтобы их также не удалял сборщик мусора и чтобы их можно было редактировать в админке перед публикацией, поскольку в Настройщике пока нет процесса редактирования записей/страниц. См. #39752.
См. alsowp_delete_auto_drafts()

## Параметры

- `$new_status` `string` — обязательный. Переход в этот статус записи.
- `$old_status` `string` — обязательный. Предыдущий статус записи.
- `$post` `WP_Post` — обязательный. Данные записи.

## Исходный код

Файл: `wp-includes/theme.php:3863`

```php
function _wp_keep_alive_customize_changeset_dependent_auto_drafts( $new_status, $old_status, $post ) {
	global $wpdb;
	unset( $old_status );

	// Short-circuit if not a changeset or if the changeset was published.
	if ( 'customize_changeset' !== $post->post_type || 'publish' === $new_status ) {
		return;
	}

	$data = json_decode( $post->post_content, true );
	if ( empty( $data['nav_menus_created_posts']['value'] ) ) {
		return;
	}

	/*
	 * Actually, in lieu of keeping alive, trash any customization drafts here if the changeset itself is
	 * getting trashed. This is needed because when a changeset transitions to a draft, then any of the
	 * dependent auto-draft post/page stubs will also get transitioned to customization drafts which
	 * are then visible in the WP Admin. We cannot wait for the deletion of the changeset in which
	 * _wp_delete_customize_changeset_dependent_auto_drafts() will be called, since they need to be
	 * trashed to remove from visibility immediately.
	 */
	if ( 'trash' === $new_status ) {
		foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
			if ( ! empty( $post_id ) && 'draft' === get_post_status( $post_id ) ) {
				wp_trash_post( $post_id );
			}
		}
		return;
	}

	$post_args = array();
	if ( 'auto-draft' === $new_status ) {
		/*
		 * Keep the post date for the post matching the changeset
		 * so that it will not be garbage-collected before the changeset.
		 */
		$post_args['post_date'] = $post->post_date; // Note wp_delete_auto_drafts() only looks at this date.
	} else {
		/*
		 * Since the changeset no longer has an auto-draft (and it is not published)
		 * it is now a persistent changeset, a long-lived draft, and so any
		 * associated auto-draft posts should likewise transition into having a draft
		 * status. These drafts will be treated differently than regular drafts in
		 * that they will be tied to the given changeset. The publish meta box is
		 * replaced with a notice about how the post is part of a set of customized changes
		 * which will be published when the changeset is published.
		 */
		$post_args['post_status'] = 'draft';
	}

	foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
		if ( empty( $post_id ) || 'auto-draft' !== get_post_status( $post_id ) ) {
			continue;
		}
		$wpdb->update(
			$wpdb->posts,
			$post_args,
			array( 'ID' => $post_id )
		);
		clean_post_cache( $post_id );
	}
}
```

## История изменений

- 4.8.0 — Introduced.

## Связанные

Использует: [`clean_post_cache`](https://chugunov.pro/api-wordpress/functions/clean_post_cache/), [`wp_trash_post`](https://chugunov.pro/api-wordpress/functions/wp_trash_post/), [`get_post_status`](https://chugunov.pro/api-wordpress/functions/get_post_status/), `wpdb::update`.

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/_wp_keep_alive_customize_changeset_dependent_auto_drafts/
