Filter hook 'pre_transient_{$transient}'

in WP Core File wp-includes/option.php at line 1449

View Source

pre_transient_{$transient}

Filter Hook
Description
Filters the value of an existing transient before it is retrieved. The dynamic portion of the hook name, `$transient`, refers to the transient name. Returning a value other than false from the filter will short-circuit retrieval and return that value instead.

Hook Information

File Location wp-includes/option.php View on GitHub
Hook Type Filter
Line Number 1449

Hook Parameters

Type Name Description
mixed $pre_transient The default value to return if the transient does not exist. Any value other than false will short-circuit the retrieval of the transient, and return that value.
string $transient Transient name.

Usage Examples

Basic Usage
<?php
// Hook into pre_transient_{$transient}
add_filter('pre_transient_{$transient}', 'my_custom_filter', 10, 2);

function my_custom_filter($pre_transient, $transient) {
    // Your custom filtering logic here
    return $pre_transient;
}

Source Code Context

wp-includes/option.php:1449 - How this hook is used in WordPress core
<?php
1444  	 * @param mixed  $pre_transient The default value to return if the transient does not exist.
1445  	 *                              Any value other than false will short-circuit the retrieval
1446  	 *                              of the transient, and return that value.
1447  	 * @param string $transient     Transient name.
1448  	 */
1449  	$pre = apply_filters( "pre_transient_{$transient}", false, $transient );
1450  
1451  	if ( false !== $pre ) {
1452  		return $pre;
1453  	}
1454  

PHP Documentation

<?php
/**
	 * Filters the value of an existing transient before it is retrieved.
	 *
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
	 *
	 * Returning a value other than false from the filter will short-circuit retrieval
	 * and return that value instead.
	 *
	 * @since 2.8.0
	 * @since 4.4.0 The `$transient` parameter was added
	 *
	 * @param mixed  $pre_transient The default value to return if the transient does not exist.
	 *                              Any value other than false will short-circuit the retrieval
	 *                              of the transient, and return that value.
	 * @param string $transient     Transient name.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-includes/option.php
Related Hooks

Related hooks will be displayed here in future updates.