# set_transient()

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

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

## Сигнатура

```php
set_transient( string $transient, mixed $value, int $expiration ): bool
```

## Описание

Сериализовать значения не нужно. Если значение требует сериализации, оно будет сериализовано перед установкой.

## Параметры

- `$transient` `string` — обязательный. Имя транзиента. Ожидается, что не экранировано для SQL.
  
  Длина не должна превышать 172 символа.
- `$value` `mixed` — обязательный. Значение транзиента. Должно быть сериализуемым, если нескалярное.
  
  Ожидается, что не экранировано для SQL.
- `$expiration` `int` — необязательный. Время до истечения срока в секундах. Значение по умолчанию 0 (без истечения).

## Возвращаемое значение

`bool`

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

Файл: `wp-includes/option.php:1507`

```php
function set_transient( $transient, $value, $expiration = 0 ) {

	$expiration = (int) $expiration;

	/**
	 * Filters a specific transient before its value is set.
	 *
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
	 *
	 * @since 3.0.0
	 * @since 4.2.0 The `$expiration` parameter was added.
	 * @since 4.4.0 The `$transient` parameter was added.
	 *
	 * @param mixed  $value      New value of transient.
	 * @param int    $expiration Time until expiration in seconds.
	 * @param string $transient  Transient name.
	 */
	$value = apply_filters( "pre_set_transient_{$transient}", $value, $expiration, $transient );

	/**
	 * Filters the expiration for a transient before its value is set.
	 *
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
	 *
	 * @since 4.4.0
	 *
	 * @param int    $expiration Time until expiration in seconds. Use 0 for no expiration.
	 * @param mixed  $value      New value of transient.
	 * @param string $transient  Transient name.
	 */
	$expiration = apply_filters( "expiration_of_transient_{$transient}", $expiration, $value, $transient );

	if ( wp_using_ext_object_cache() || wp_installing() ) {
		$result = wp_cache_set( $transient, $value, 'transient', $expiration );
	} else {
		$transient_timeout = '_transient_timeout_' . $transient;
		$transient_option  = '_transient_' . $transient;
		wp_prime_option_caches( array( $transient_option, $transient_timeout ) );

		if ( false === get_option( $transient_option ) ) {
			$autoload = true;
			if ( $expiration ) {
				$autoload = false;
				add_option( $transient_timeout, time() + $expiration, '', false );
			}
			$result = add_option( $transient_option, $value, '', $autoload );
		} else {
			/*
			 * If expiration is requested, but the transient has no timeout option,
			 * delete, then re-create transient rather than update.
			 */
			$update = true;

			if ( $expiration ) {
				if ( false === get_option( $transient_timeout ) ) {
					delete_option( $transient_option );
					add_option( $transient_timeout, time() + $expiration, '', false );
					$result = add_option( $transient_option, $value, '', false );
					$update = false;
				} else {
					update_option( $transient_timeout, time() + $expiration );
				}
			}

			if ( $update ) {
				$result = update_option( $transient_option, $value );
			}
		}
	}

	if ( $result ) {

		/**
		 * Fires after the value for a specific transient has been set.
		 *
		 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
		 *
		 * @since 3.0.0
		 * @since 3.6.0 The `$value` and `$expiration` parameters were added.
		 * @since 4.4.0 The `$transient` parameter was added.
		 *
		 * @param mixed  $value      Transient value.
		 * @param int    $expiration Time until expiration in seconds.
		 * @param string $transient  The name of the transient.
		 */
		do_action( "set_transient_{$transient}", $value, $expiration, $transient );

		/**
		 * Fires after the value for a transient has been set.
		 *
		 * @since 6.8.0
		 *
		 * @param string $transient  The name of the transient.
		 * @param mixed  $value      Transient value.
		 * @param int    $expiration Time until expiration in seconds.
		 */
		do_action( 'set_transient', $transient, $value, $expiration );

		/**
		 * Fires after the transient is set.
		 *
		 * @since 3.0.0
		 * @since 3.6.0 The `$value` and `$expiration` parameters were added.
		 * @deprecated 6.8.0 Use 'set_transient' instead.
		 *
		 * @param string $transient  The name of the transient.
		 * @param mixed  $value      Transient value.
		 * @param int    $expiration Time until expiration in seconds.
		 */
		do_action_deprecated( 'setted_transient', array( $transient, $value, $expiration ), '6.8.0', 'set_transient' );
	}

	return $result;
}
```

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

- 2.8.0 — Introduced.

## Связанные

Использует: [`wp_prime_option_caches`](https://chugunov.pro/api-wordpress/functions/wp_prime_option_caches/), [`do_action_deprecated`](https://chugunov.pro/api-wordpress/functions/do_action_deprecated/), [`wp_installing`](https://chugunov.pro/api-wordpress/functions/wp_installing/), [`wp_cache_set`](https://chugunov.pro/api-wordpress/functions/wp_cache_set/), [`wp_using_ext_object_cache`](https://chugunov.pro/api-wordpress/functions/wp_using_ext_object_cache/), [`add_option`](https://chugunov.pro/api-wordpress/functions/add_option/), [`delete_option`](https://chugunov.pro/api-wordpress/functions/delete_option/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`do_action`](https://chugunov.pro/api-wordpress/functions/do_action/), [`update_option`](https://chugunov.pro/api-wordpress/functions/update_option/), [`get_option`](https://chugunov.pro/api-wordpress/functions/get_option/).
Используется в: `WP_Automatic_Updater::has_fatal_error`, [`wp_add_global_styles_for_blocks`](https://chugunov.pro/api-wordpress/functions/wp_add_global_styles_for_blocks/), [`clean_dirsize_cache`](https://chugunov.pro/api-wordpress/functions/clean_dirsize_cache/), [`recurse_dirsize`](https://chugunov.pro/api-wordpress/functions/recurse_dirsize/), `WP_Site_Health::wp_cron_scheduled_check`, [`wp_ajax_health_check_site_status_result`](https://chugunov.pro/api-wordpress/functions/wp_ajax_health_check_site_status_result/), [`wp_edit_theme_plugin_file`](https://chugunov.pro/api-wordpress/functions/wp_edit_theme_plugin_file/), `WP_oEmbed_Controller::get_proxy_item`, [`install_themes_feature_list`](https://chugunov.pro/api-wordpress/functions/install_themes_feature_list/), [`wp_dashboard_cached_rss_widget`](https://chugunov.pro/api-wordpress/functions/wp_dashboard_cached_rss_widget/), [`wp_dashboard_plugins_output`](https://chugunov.pro/api-wordpress/functions/wp_dashboard_plugins_output/), [`spawn_cron`](https://chugunov.pro/api-wordpress/functions/spawn_cron/), [`wp_rand`](https://chugunov.pro/api-wordpress/functions/wp_rand/), [`wp_maybe_generate_attachment_metadata`](https://chugunov.pro/api-wordpress/functions/wp_maybe_generate_attachment_metadata/), [`is_multi_author`](https://chugunov.pro/api-wordpress/functions/is_multi_author/), `RSSCache::set`.

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