set_transient

Definition:
function set_transient( $transient, $value, $expiration = 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.

Parameters

  • string $transient: Transient name. Expected to not be SQL-escaped.
  • mixed $value: Transient value. Expected to not be SQL-escaped.
  • int $expiration: Time until expiration in seconds, default 0

Return values

returns:False if value was not set and true if value was set.

Defined filters

  • pre_set_transient_$transient
    apply_filters( 'pre_set_transient_' . $transient, $value )

Defined actions

  • set_transient_’.$transient
    do_action( 'set_transient_' . $transient );
  • setted_transient
    do_action( 'setted_transient', $transient );

Source code

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

	global $_wp_using_ext_object_cache;



	$value = apply_filters( 'pre_set_transient_' . $transient, $value );



	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 );

		do_action( 'setted_transient', $transient );

	}

	return $result;

}

2857

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: