get_site_transient

Get the value of a site transient.

Description

get_site_transient( (string) $transient ); 

If the transient does not exist, does not have a value, or has expired, then the return value will be false.

Parameters (1)

0. $transient (string)
Transient name. Expected to not be SQL-escaped.

Usage

  1. if ( !function_exists( 'get_site_transient' ) ) { 
  2. require_once ABSPATH . WPINC . '/option.php'; 
  3.  
  4. // Transient name. Expected to not be SQL-escaped. 
  5. $transient = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_site_transient($transient); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/option.php  
  1. function get_site_transient( $transient ) { 
  2.  
  3. /** 
  4. * Filters the value of an existing site transient. 
  5. * The dynamic portion of the hook name, `$transient`, refers to the transient name. 
  6. * Passing a truthy value to the filter will effectively short-circuit retrieval,  
  7. * returning the passed value instead. 
  8. * @since 2.9.0 
  9. * @since 4.4.0 The `$transient` parameter was added. 
  10. * @param mixed $pre_site_transient The default value to return if the site transient does not exist. 
  11. * Any value other than false will short-circuit the retrieval 
  12. * of the transient, and return the returned value. 
  13. * @param string $transient Transient name. 
  14. */ 
  15. $pre = apply_filters( "pre_site_transient_{$transient}", false, $transient ); 
  16.  
  17. if ( false !== $pre ) 
  18. return $pre; 
  19.  
  20. $value = wp_cache_get( $transient, 'site-transient' ); 
  21. } else { 
  22. // Core transients that do not have a timeout. Listed here so querying timeouts can be avoided. 
  23. $no_timeout = array('update_core', 'update_plugins', 'update_themes'); 
  24. $transient_option = '_site_transient_' . $transient; 
  25. if ( ! in_array( $transient, $no_timeout ) ) { 
  26. $transient_timeout = '_site_transient_timeout_' . $transient; 
  27. $timeout = get_site_option( $transient_timeout ); 
  28. if ( false !== $timeout && $timeout < time() ) { 
  29. delete_site_option( $transient_option ); 
  30. delete_site_option( $transient_timeout ); 
  31. $value = false; 
  32.  
  33. if ( ! isset( $value ) ) 
  34. $value = get_site_option( $transient_option ); 
  35.  
  36. /** 
  37. * Filters the value of an existing site transient. 
  38. * The dynamic portion of the hook name, `$transient`, refers to the transient name. 
  39. * @since 2.9.0 
  40. * @since 4.4.0 The `$transient` parameter was added. 
  41. * @param mixed $value Value of site transient. 
  42. * @param string $transient Transient name. 
  43. */ 
  44. return apply_filters( "site_transient_{$transient}", $value, $transient );