WordPress函数:get_site_transient 获取站点的临时值

江河/ 2023年09月28日/ WordPress/ 浏览 435

函数原型:


get_site_transient( string $transient ): mixed


获取站点的临时值


如果临时值不存在、没有值或已过期,则返回值将为false。


参数说明:


$transient,临时值名称


函数源码:


function get_site_transient( $transient ) {
	$pre = apply_filters( "pre_site_transient_{$transient}", false, $transient );

	if ( false !== $pre ) {
		return $pre;
	}

	if ( wp_using_ext_object_cache() || wp_installing() ) {
		$value = wp_cache_get( $transient, 'site-transient' );
	} else {
		// Core transients that do not have a timeout. Listed here so querying timeouts can be avoided.
		$no_timeout       = array( 'update_core', 'update_plugins', 'update_themes' );
		$transient_option = '_site_transient_' . $transient;
		if ( ! in_array( $transient, $no_timeout, true ) ) {
			$transient_timeout = '_site_transient_timeout_' . $transient;
			$timeout           = get_site_option( $transient_timeout );
			if ( false !== $timeout && $timeout < time() ) {
				delete_site_option( $transient_option );
				delete_site_option( $transient_timeout );
				$value = false;
			}
		}

		if ( ! isset( $value ) ) {
			$value = get_site_option( $transient_option );
		}
	}

	return apply_filters( "site_transient_{$transient}", $value, $transient );
}


包含钩子:


apply_filters( "pre_site_transient_{$transient}", mixed $pre_site_transient, string $transient )

apply_filters( "site_transient_{$transient}", mixed $value, string $transient )


发表评论

暂无评论,抢个沙发...

客服 工单