set_transient

The timeline below displays how wordpress function set_transient has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Sets/updates the value of a transient.
 *
 * You do not need to serialize values. If the value needs to be serialized,
 * then it will be serialized before it is set.
 *
 * @since 2.8.0
 *
 * @param string $transient  Transient name. Expected to not be SQL-escaped.
 *                           Must be 172 characters or fewer in length.
 * @param mixed  $value      Transient value. Must be serializable if non-scalar.
 *                           Expected to not be SQL-escaped.
 * @param int    $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
 * @return bool True if the value was set, false otherwise.
 */
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;
        if (false === get_option($transient_option)) {
            $autoload = 'yes';
            if ($expiration) {
                $autoload = 'no';
                add_option($transient_timeout, time() + $expiration, '', 'no');
            }
            $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, '', 'no');
                    $result = add_option($transient_option, $value, '', 'no');
                    $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 3.0.0
         * @since 3.6.0 The `$value` and `$expiration` parameters were added.
         *
         * @param string $transient  The name of the transient.
         * @param mixed  $value      Transient value.
         * @param int    $expiration Time until expiration in seconds.
         */
        do_action('setted_transient', $transient, $value, $expiration);
    }
    return $result;
}

WordPress Version: 9.1

/**
 * Sets/updates the value of a transient.
 *
 * You do not need to serialize values. If the value needs to be serialized,
 * then it will be serialized before it is set.
 *
 * @since 2.8.0
 *
 * @param string $transient  Transient name. Expected to not be SQL-escaped.
 *                           Must be 172 characters or fewer in length.
 * @param mixed  $value      Transient value. Must be serializable if non-scalar.
 *                           Expected to not be SQL-escaped.
 * @param int    $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
 * @return bool True if the value was set, false otherwise.
 */
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;
        if (false === get_option($transient_option)) {
            $autoload = 'yes';
            if ($expiration) {
                $autoload = 'no';
                add_option($transient_timeout, time() + $expiration, '', 'no');
            }
            $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, '', 'no');
                    $result = add_option($transient_option, $value, '', 'no');
                    $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 3.0.0
         * @since 3.6.0 The `$value` and `$expiration` parameters were added.
         *
         * @param string $transient  The name of the transient.
         * @param mixed  $value      Transient value.
         * @param int    $expiration Time until expiration in seconds.
         */
        do_action('setted_transient', $transient, $value, $expiration);
    }
    return $result;
}

WordPress Version: 5.5

/**
 * Sets/updates the value of a transient.
 *
 * You do not need to serialize values. If the value needs to be serialized,
 * then it will be serialized before it is set.
 *
 * @since 2.8.0
 *
 * @param string $transient  Transient name. Expected to not be SQL-escaped.
 *                           Must be 172 characters or fewer in length.
 * @param mixed  $value      Transient value. Must be serializable if non-scalar.
 *                           Expected to not be SQL-escaped.
 * @param int    $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
 * @return bool True if the value was set, false otherwise.
 */
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()) {
        $result = wp_cache_set($transient, $value, 'transient', $expiration);
    } else {
        $transient_timeout = '_transient_timeout_' . $transient;
        $transient_option = '_transient_' . $transient;
        if (false === get_option($transient_option)) {
            $autoload = 'yes';
            if ($expiration) {
                $autoload = 'no';
                add_option($transient_timeout, time() + $expiration, '', 'no');
            }
            $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, '', 'no');
                    $result = add_option($transient_option, $value, '', 'no');
                    $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 3.0.0
         * @since 3.6.0 The `$value` and `$expiration` parameters were added.
         *
         * @param string $transient  The name of the transient.
         * @param mixed  $value      Transient value.
         * @param int    $expiration Time until expiration in seconds.
         */
        do_action('setted_transient', $transient, $value, $expiration);
    }
    return $result;
}

WordPress Version: 5.4

/**
 * Sets/updates the value of a transient.
 *
 * You do not need to serialize values. If the value needs to be serialized,
 * then it will be serialized before it is set.
 *
 * @since 2.8.0
 *
 * @param string $transient  Transient name. Expected to not be SQL-escaped. Must be
 *                           172 characters or fewer in length.
 * @param mixed  $value      Transient value. Must be serializable if non-scalar.
 *                           Expected to not be SQL-escaped.
 * @param int    $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
 * @return bool False if value was not set and true if value was set.
 */
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()) {
        $result = wp_cache_set($transient, $value, 'transient', $expiration);
    } else {
        $transient_timeout = '_transient_timeout_' . $transient;
        $transient_option = '_transient_' . $transient;
        if (false === get_option($transient_option)) {
            $autoload = 'yes';
            if ($expiration) {
                $autoload = 'no';
                add_option($transient_timeout, time() + $expiration, '', 'no');
            }
            $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, '', 'no');
                    $result = add_option($transient_option, $value, '', 'no');
                    $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 3.0.0
         * @since 3.6.0 The `$value` and `$expiration` parameters were added.
         *
         * @param string $transient  The name of the transient.
         * @param mixed  $value      Transient value.
         * @param int    $expiration Time until expiration in seconds.
         */
        do_action('setted_transient', $transient, $value, $expiration);
    }
    return $result;
}

WordPress Version: 4.7

/**
 * Set/update the value of a transient.
 *
 * You do not need to serialize values. If the value needs to be serialized, then
 * it will be serialized before it is set.
 *
 * @since 2.8.0
 *
 * @param string $transient  Transient name. Expected to not be SQL-escaped. Must be
 *                           172 characters or fewer in length.
 * @param mixed  $value      Transient value. Must be serializable if non-scalar.
 *                           Expected to not be SQL-escaped.
 * @param int    $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
 * @return bool False if value was not set and true if value was set.
 */
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()) {
        $result = wp_cache_set($transient, $value, 'transient', $expiration);
    } else {
        $transient_timeout = '_transient_timeout_' . $transient;
        $transient_option = '_transient_' . $transient;
        if (false === get_option($transient_option)) {
            $autoload = 'yes';
            if ($expiration) {
                $autoload = 'no';
                add_option($transient_timeout, time() + $expiration, '', 'no');
            }
            $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, '', 'no');
                    $result = add_option($transient_option, $value, '', 'no');
                    $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 3.0.0
         * @since 3.6.0 The `$value` and `$expiration` parameters were added.
         *
         * @param string $transient  The name of the transient.
         * @param mixed  $value      Transient value.
         * @param int    $expiration Time until expiration in seconds.
         */
        do_action('setted_transient', $transient, $value, $expiration);
    }
    return $result;
}

WordPress Version: 4.6

/**
 * Set/update the value of a transient.
 *
 * You do not need to serialize values. If the value needs to be serialized, then
 * it will be serialized before it is set.
 *
 * @since 2.8.0
 *
 * @param string $transient  Transient name. Expected to not be SQL-escaped. Must be
 *                           172 characters or fewer in length.
 * @param mixed  $value      Transient value. Must be serializable if non-scalar.
 *                           Expected to not be SQL-escaped.
 * @param int    $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
 * @return bool False if value was not set and true if value was set.
 */
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()) {
        $result = wp_cache_set($transient, $value, 'transient', $expiration);
    } else {
        $transient_timeout = '_transient_timeout_' . $transient;
        $transient_option = '_transient_' . $transient;
        if (false === get_option($transient_option)) {
            $autoload = 'yes';
            if ($expiration) {
                $autoload = 'no';
                add_option($transient_timeout, time() + $expiration, '', 'no');
            }
            $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, '', 'no');
                    $result = add_option($transient_option, $value, '', 'no');
                    $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 3.0.0
         * @since 3.6.0 The `$value` and `$expiration` parameters were added.
         *
         * @param string $transient  The name of the transient.
         * @param mixed  $value      Transient value.
         * @param int    $expiration Time until expiration in seconds.
         */
        do_action('setted_transient', $transient, $value, $expiration);
    }
    return $result;
}

WordPress Version: 4.4

/**
 * Set/update the value of a transient.
 *
 * You do not need to serialize values. If the value needs to be serialized, then
 * it will be serialized before it is set.
 *
 * @since 2.8.0
 *
 * @param string $transient  Transient name. Expected to not be SQL-escaped. Must be
 *                           172 characters or fewer in length.
 * @param mixed  $value      Transient value. Must be serializable if non-scalar.
 *                           Expected to not be SQL-escaped.
 * @param int    $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
 * @return bool False if value was not set and true if value was set.
 */
function set_transient($transient, $value, $expiration = 0)
{
    $expiration = (int) $expiration;
    /**
     * Filter 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);
    /**
     * Filter 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()) {
        $result = wp_cache_set($transient, $value, 'transient', $expiration);
    } else {
        $transient_timeout = '_transient_timeout_' . $transient;
        $transient_option = '_transient_' . $transient;
        if (false === get_option($transient_option)) {
            $autoload = 'yes';
            if ($expiration) {
                $autoload = 'no';
                add_option($transient_timeout, time() + $expiration, '', 'no');
            }
            $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, '', 'no');
                    $result = add_option($transient_option, $value, '', 'no');
                    $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 3.0.0
         * @since 3.6.0 The `$value` and `$expiration` parameters were added.
         *
         * @param string $transient  The name of the transient.
         * @param mixed  $value      Transient value.
         * @param int    $expiration Time until expiration in seconds.
         */
        do_action('setted_transient', $transient, $value, $expiration);
    }
    return $result;
}

WordPress Version: 4.2

/**
 * Set/update the value of a transient.
 *
 * You do not need to serialize values. If the value needs to be serialized, then
 * it will be serialized before it is set.
 *
 * @since 2.8.0
 *
 * @param string $transient  Transient name. Expected to not be SQL-escaped. Must be
 *                           45 characters or fewer in length.
 * @param mixed  $value      Transient value. Must be serializable if non-scalar.
 *                           Expected to not be SQL-escaped.
 * @param int    $expiration Optional. Time until expiration in seconds. Default 0.
 * @return bool False if value was not set and true if value was set.
 */
function set_transient($transient, $value, $expiration = 0)
{
    $expiration = (int) $expiration;
    /**
     * Filter 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 Added `$expiration` parameter.
     *
     * @param mixed $value      New value of transient.
     * @param int   $expiration Time until expiration in seconds.
     */
    $value = apply_filters('pre_set_transient_' . $transient, $value, $expiration);
    if (wp_using_ext_object_cache()) {
        $result = wp_cache_set($transient, $value, 'transient', $expiration);
    } else {
        $transient_timeout = '_transient_timeout_' . $transient;
        $transient = '_transient_' . $transient;
        if (false === get_option($transient)) {
            $autoload = 'yes';
            if ($expiration) {
                $autoload = 'no';
                add_option($transient_timeout, time() + $expiration, '', 'no');
            }
            $result = add_option($transient, $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);
                    add_option($transient_timeout, time() + $expiration, '', 'no');
                    $result = add_option($transient, $value, '', 'no');
                    $update = false;
                } else {
                    update_option($transient_timeout, time() + $expiration);
                }
            }
            if ($update) {
                $result = update_option($transient, $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
         *
         * @param mixed $value      Transient value.
         * @param int   $expiration Time until expiration in seconds. Default 0.
         */
        do_action('set_transient_' . $transient, $value, $expiration);
        /**
         * Fires after the value for a transient has been set.
         *
         * @since 3.0.0
         *
         * @param string $transient  The name of the transient.
         * @param mixed  $value      Transient value.
         * @param int    $expiration Time until expiration in seconds. Default 0.
         */
        do_action('setted_transient', $transient, $value, $expiration);
    }
    return $result;
}

WordPress Version: 4.1

/**
 * Set/update the value of a transient.
 *
 * You do not need to serialize values. If the value needs to be serialized, then
 * it will be serialized before it is set.
 *
 * @since 2.8.0
 *
 * @param string $transient  Transient name. Expected to not be SQL-escaped. Must be
 *                           45 characters or fewer in length.
 * @param mixed  $value      Transient value. Must be serializable if non-scalar.
 *                           Expected to not be SQL-escaped.
 * @param int    $expiration Optional. Time until expiration in seconds. Default 0.
 * @return bool False if value was not set and true if value was set.
 */
function set_transient($transient, $value, $expiration = 0)
{
    /**
     * Filter 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
     *
     * @param mixed $value New value of transient.
     */
    $value = apply_filters('pre_set_transient_' . $transient, $value);
    $expiration = (int) $expiration;
    if (wp_using_ext_object_cache()) {
        $result = wp_cache_set($transient, $value, 'transient', $expiration);
    } else {
        $transient_timeout = '_transient_timeout_' . $transient;
        $transient = '_transient_' . $transient;
        if (false === get_option($transient)) {
            $autoload = 'yes';
            if ($expiration) {
                $autoload = 'no';
                add_option($transient_timeout, time() + $expiration, '', 'no');
            }
            $result = add_option($transient, $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);
                    add_option($transient_timeout, time() + $expiration, '', 'no');
                    $result = add_option($transient, $value, '', 'no');
                    $update = false;
                } else {
                    update_option($transient_timeout, time() + $expiration);
                }
            }
            if ($update) {
                $result = update_option($transient, $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
         *
         * @param mixed $value      Transient value.
         * @param int   $expiration Time until expiration in seconds. Default 0.
         */
        do_action('set_transient_' . $transient, $value, $expiration);
        /**
         * Fires after the value for a transient has been set.
         *
         * @since 3.0.0
         *
         * @param string $transient  The name of the transient.
         * @param mixed  $value      Transient value.
         * @param int    $expiration Time until expiration in seconds. Default 0.
         */
        do_action('setted_transient', $transient, $value, $expiration);
    }
    return $result;
}

WordPress Version: 4.0

/**
 * Set/update the value of a transient.
 *
 * You do not need to serialize values. If the value needs to be serialized, then
 * it will be serialized before it is set.
 *
 * @since 2.8.0
 *
 * @param string $transient  Transient name. Expected to not be SQL-escaped. Must be
 *                           45 characters or fewer in length.
 * @param mixed  $value      Transient value. Must be serializable if non-scalar.
 *                           Expected to not be SQL-escaped.
 * @param int    $expiration Optional. Time until expiration in seconds. Default 0.
 * @return bool False if value was not set and true if value was set.
 */
function set_transient($transient, $value, $expiration = 0)
{
    /**
     * Filter 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
     *
     * @param mixed $value New value of transient.
     */
    $value = apply_filters('pre_set_transient_' . $transient, $value);
    $expiration = (int) $expiration;
    if (wp_using_ext_object_cache()) {
        $result = wp_cache_set($transient, $value, 'transient', $expiration);
    } else {
        $transient_timeout = '_transient_timeout_' . $transient;
        $transient = '_transient_' . $transient;
        if (false === get_option($transient)) {
            $autoload = 'yes';
            if ($expiration) {
                $autoload = 'no';
                add_option($transient_timeout, time() + $expiration, '', 'no');
            }
            $result = add_option($transient, $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);
                    add_option($transient_timeout, time() + $expiration, '', 'no');
                    $result = add_option($transient, $value, '', 'no');
                    $update = false;
                } else {
                    update_option($transient_timeout, time() + $expiration);
                }
            }
            if ($update) {
                $result = update_option($transient, $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
         *
         * @param mixed $value      Transient value.
         * @param int   $expiration Time until expiration in seconds. Default 0.
         */
        do_action('set_transient_' . $transient, $value, $expiration);
        /**
         * Fires after the value for a transient has been set.
         *
         * @since 3.0.0
         *
         * @param string $transient  The name of the transient.
         * @param mixed  $value      Transient value.
         * @param int    $expiration Time until expiration in seconds. Default 0.
         */
        do_action('setted_transient', $transient, $value, $expiration);
    }
    return $result;
}

WordPress Version: 3.9

/**
 * Set/update the value of a transient.
 *
 * You do not need to serialize values. If the value needs to be serialized, then
 * it will be serialized before it is set.
 *
 * @since 2.8.0
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped.
 * @param mixed $value Transient value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
 * @param int $expiration Time until expiration in seconds, default 0
 * @return bool False if value was not set and true if value was set.
 */
function set_transient($transient, $value, $expiration = 0)
{
    /**
     * Filter 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
     *
     * @param mixed $value New value of transient.
     */
    $value = apply_filters('pre_set_transient_' . $transient, $value);
    $expiration = (int) $expiration;
    if (wp_using_ext_object_cache()) {
        $result = wp_cache_set($transient, $value, 'transient', $expiration);
    } else {
        $transient_timeout = '_transient_timeout_' . $transient;
        $transient = '_transient_' . $transient;
        if (false === get_option($transient)) {
            $autoload = 'yes';
            if ($expiration) {
                $autoload = 'no';
                add_option($transient_timeout, time() + $expiration, '', 'no');
            }
            $result = add_option($transient, $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);
                    add_option($transient_timeout, time() + $expiration, '', 'no');
                    $result = add_option($transient, $value, '', 'no');
                    $update = false;
                } else {
                    update_option($transient_timeout, time() + $expiration);
                }
            }
            if ($update) {
                $result = update_option($transient, $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
         *
         * @param mixed $value      Transient value.
         * @param int   $expiration Time until expiration in seconds. Default 0.
         */
        do_action('set_transient_' . $transient, $value, $expiration);
        /**
         * Fires after the value for a transient has been set.
         *
         * @since 3.0.0
         *
         * @param string $transient  The name of the transient.
         * @param mixed  $value      Transient value.
         * @param int    $expiration Time until expiration in seconds. Default 0.
         */
        do_action('setted_transient', $transient, $value, $expiration);
    }
    return $result;
}

WordPress Version: 3.7

/**
 * Set/update the value of a transient.
 *
 * You do not need to serialize values. If the value needs to be serialized, then
 * it will be serialized before it is set.
 *
 * @since 2.8.0
 * @package WordPress
 * @subpackage Transient
 *
 * @uses apply_filters() Calls 'pre_set_transient_$transient' hook to allow overwriting the
 * 	transient value to be stored.
 * @uses do_action() Calls 'set_transient_$transient' and 'setted_transient' hooks on success.
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped.
 * @param mixed $value Transient value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
 * @param int $expiration Time until expiration in seconds, default 0
 * @return bool False if value was not set and true if value was set.
 */
function set_transient($transient, $value, $expiration = 0)
{
    $value = apply_filters('pre_set_transient_' . $transient, $value);
    $expiration = (int) $expiration;
    if (wp_using_ext_object_cache()) {
        $result = wp_cache_set($transient, $value, 'transient', $expiration);
    } else {
        $transient_timeout = '_transient_timeout_' . $transient;
        $transient = '_transient_' . $transient;
        if (false === get_option($transient)) {
            $autoload = 'yes';
            if ($expiration) {
                $autoload = 'no';
                add_option($transient_timeout, time() + $expiration, '', 'no');
            }
            $result = add_option($transient, $value, '', $autoload);
        } else {
            if ($expiration) {
                update_option($transient_timeout, time() + $expiration);
            }
            $result = update_option($transient, $value);
        }
    }
    if ($result) {
        do_action('set_transient_' . $transient, $value, $expiration);
        do_action('setted_transient', $transient, $value, $expiration);
    }
    return $result;
}