返回介绍

delete_transient()

发布于 2017-09-10 22:08:22 字数 3423 浏览 1303 评论 0 收藏 0

delete_transient( string $transient )

Delete a transient.


description


参数

$transient

(string) (Required) Transient name. Expected to not be SQL-escaped.


返回值

(bool) true if successful, false otherwise


源代码

File: wp-includes/option.php

function delete_transient( $transient ) {

	/**
	 * Fires immediately before a specific transient is deleted.
	 *
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
	 *
	 * @since 3.0.0
	 *
	 * @param string $transient Transient name.
	 */
	do_action( "delete_transient_{$transient}", $transient );

	if ( wp_using_ext_object_cache() ) {
		$result = wp_cache_delete( $transient, 'transient' );
	} else {
		$option_timeout = '_transient_timeout_' . $transient;
		$option = '_transient_' . $transient;
		$result = delete_option( $option );
		if ( $result )
			delete_option( $option_timeout );
	}

	if ( $result ) {

		/**
		 * Fires after a transient is deleted.
		 *
		 * @since 3.0.0
		 *
		 * @param string $transient Deleted transient name.
		 */
		do_action( 'deleted_transient', $transient );
	}

	return $result;
}

更新日志

Versiondescription
2.8.0Introduced.

相关函数

Uses

  • wp-includes/cache.php: wp_cache_delete()
  • wp-includes/load.php: wp_using_ext_object_cache()
  • wp-includes/plugin.php: do_action()
  • wp-includes/option.php: deleted_transient
  • wp-includes/option.php: delete_option()
  • wp-includes/option.php: delete_transient_{$transient}
  • Show 1 more use Hide more uses

Used By

  • wp-admin/includes/file.php: _wp_handle_upload()
  • wp-admin/includes/dashboard.php: wp_dashboard_rss_control()
  • wp-admin/includes/template.php: get_settings_errors()
  • wp-includes/class-wp-feed-cache-transient.php: WP_Feed_Cache_Transient::unlink()
  • wp-includes/media.php: wp_maybe_generate_attachment_metadata()
  • wp-includes/post.php: wp_delete_attachment()
  • wp-includes/author-template.php: __clear_multi_author_cache()
  • Show 2 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Clearing our transient via the edit_term hook

    
    // Create a simple function to delete our transient
    function wpdocs_edit_term_delete_transient() {
         delete_transient( 'special_query_results' );
    }
    // Add the function to the edit_term hook so it runs when categories/tags are edited
    add_action( 'edit_term', 'wpdocs_edit_term_delete_transient' );
    

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

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

发布评论

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