delete_transient()删除某个保留在数据库的临时值

目录

描述

Delete a transient. If the specified transient does not exist then no action will be taken.

delete_transient() 描述

用法

<?php delete_transient$transient ); ?>

delete_transient() 用法

参数

$transient

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

默认值: None

delete_transient() 参数

返回值

(boolean) 

True if successful, false otherwise.

delete_transient() 返回值

示例

Clearing our transient via the edit_term hook

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<?php
// Create a simple function to delete our transient
function 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', 'edit_term_delete_transient' );
?>

delete_transient() 示例

历史

添加于 版本: 2.8

delete_transient() 历史

源文件

delete_transient() 函数的代码位于 wp-includes/option.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Delete a transient.
 *
 * @since 2.8.0
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped.
 * @return bool true if successful, false otherwise
 */
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;
}

delete_transient() 源文件

相关