Advertisements

set_site_transient

Definition:
function set_site_transient( $transient, $value, $expiration = 0 ) {}

Set/update the value of a site transient.
You do not need to serialize values, if the value needs to be serialize, 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_site_transient_$transient
    apply_filters( 'pre_set_site_transient_' . $transient, $value )

Defined actions

  • set_site_transient_’.$transient
    do_action( 'set_site_transient_' . $transient );
  • setted_site_transient
    do_action( 'setted_site_transient', $transient );

Source code

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

	global $_wp_using_ext_object_cache;



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



	if ( $_wp_using_ext_object_cache ) {

		$result = wp_cache_set( $transient, $value, 'site-transient', $expiration );

	} else {

		$transient_timeout = '_site_transient_timeout_' . $transient;

		$transient = '_site_transient_' . $transient;

		if ( false === get_site_option( $transient ) ) {

			if ( $expiration )

				add_site_option( $transient_timeout, time() + $expiration );

			$result = add_site_option( $transient, $value );

		} else {

			if ( $expiration )

				update_site_option( $transient_timeout, time() + $expiration );

			$result = update_site_option( $transient, $value );

		}

	}

	if ( $result ) {

		do_action( 'set_site_transient_' . $transient );

		do_action( 'setted_site_transient', $transient );

	}

	return $result;

}

2853

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: