返回介绍

set_site_transient()

发布于 2017-09-11 10:22:26 字数 5588 浏览 1005 评论 0 收藏 0

set_site_transient( string $transient,  mixed $value,  int $expiration )

Set/update the value of a site transient.


description

You do not need to serialize values, if the value needs to be serialize, then it will be serialized before it is set.


参数

$transient

(string) (Required) Transient name. Expected to not be SQL-escaped. Must be 167 characters or fewer in length.

$value

(mixed) (Required) Transient value. Expected to not be SQL-escaped.

$expiration

(int) (Optional) Time until expiration in seconds. Default 0 (no expiration).


返回值

(bool) False if value was not set and true if value was set.


源代码

File: wp-includes/option.php

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

	/**
	 * Filters the value of a specific site transient before it is set.
	 *
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
	 *
	 * @since 3.0.0
	 * @since 4.4.0 The `$transient` parameter was added.
	 *
	 * @param mixed  $value     New value of site transient.
	 * @param string $transient Transient name.
	 */
	$value = apply_filters( "pre_set_site_transient_{$transient}", $value, $transient );

	$expiration = (int) $expiration;

	/**
	 * Filters the expiration for a site 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 site transient.
	 * @param string $transient  Transient name.
	 */
	$expiration = apply_filters( "expiration_of_site_transient_{$transient}", $expiration, $value, $transient );

	if ( wp_using_ext_object_cache() ) {
		$result = wp_cache_set( $transient, $value, 'site-transient', $expiration );
	} else {
		$transient_timeout = '_site_transient_timeout_' . $transient;
		$option = '_site_transient_' . $transient;
		if ( false === get_site_option( $option ) ) {
			if ( $expiration )
				add_site_option( $transient_timeout, time() + $expiration );
			$result = add_site_option( $option, $value );
		} else {
			if ( $expiration )
				update_site_option( $transient_timeout, time() + $expiration );
			$result = update_site_option( $option, $value );
		}
	}
	if ( $result ) {

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

		/**
		 * Fires after the value for a site transient has been set.
		 *
		 * @since 3.0.0
		 *
		 * @param string $transient  The name of the site transient.
		 * @param mixed  $value      Site transient value.
		 * @param int    $expiration Time until expiration in seconds.
		 */
		do_action( 'setted_site_transient', $transient, $value, $expiration );
	}
	return $result;
}

更新日志

Versiondescription
2.9.0Introduced.

相关函数

Uses

  • wp-includes/option.php: expiration_of_site_transient_{$transient}
  • wp-includes/cache.php: wp_cache_set()
  • wp-includes/load.php: wp_using_ext_object_cache()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/plugin.php: do_action()
  • wp-includes/option.php: pre_set_site_transient_{$transient}
  • wp-includes/option.php: set_site_transient_{$transient}
  • wp-includes/option.php: setted_site_transient
  • wp-includes/option.php: add_site_option()
  • wp-includes/option.php: update_site_option()
  • wp-includes/option.php: get_site_option()
  • Show 6 more uses Hide more uses

Used By

  • wp-admin/includes/class-wp-community-events.php: WP_Community_Events::cache_events()
  • wp-admin/includes/translation-install.php: wp_get_available_translations()
  • wp-admin/includes/theme.php: get_theme_feature_list()
  • wp-admin/includes/dashboard.php: wp_check_browser_version()
  • wp-admin/includes/plugin-install.php: install_popular_tags()
  • wp-admin/includes/plugin.php: delete_plugins()
  • wp-admin/includes/import.php: wp_get_popular_importers()
  • wp-admin/includes/credits.php: wp_credits()
  • wp-includes/theme.php: search_theme_directories()
  • wp-includes/update.php: wp_version_check()
  • wp-includes/update.php: wp_update_plugins()
  • wp-includes/update.php: wp_update_themes()
  • Show 7 more used by Hide more used by

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文