set_site_transient( string $transient, mixed $value, int $expiration = 0 ): bool
- Since
- 2.9.0
- Source
wp-includes/option.php:2641
Description
You do not need to serialize values. If the value needs to be serialized, then it will be serialized before it is set.
Compatibility
- WordPress
- since 2.9.0
- PHP
- 7.4–8.4
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.4.
Parameters
$transientstring- Transient name. Expected to not be SQL-escaped. Must be 167 characters or fewer in length.
$valuemixed- Transient value. Expected to not be SQL-escaped.
$expirationintoptional- Time until expiration in seconds. Default 0 (no expiration).Default:
0
Return value
bool- True if the value was set, false otherwise.
Performance profile
How much work a call to set_site_transient() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Moderate
- Scaling
- Constant
- Instructions
- 33–76
- Plugin surface
- 5 hooks
- Called by
- 20
Reads stored settings via get_site_option(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.4, depending on the branch taken. The body compiles to 97.
Third-party callbacks on 'pre_set_site_transient_{$transient}', 'expiration_of_site_transient_{$transient}', 'set_site_transient_{$transient}' run inside this call, and their cost is not bounded by anything here.
20 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- transienttransient
set_site_transient()this function does it - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_set()called directly - optionnetwork option
get_site_option()called directly
Further down the call graph this can also reach serialize and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 12 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost set_site_transient() can have, taken from its control-flow graph on PHP 8.4.
| When | Instructions | Calls it makes |
|---|---|---|
wp_using_ext_object_cache() | 33 | apply_filters(), apply_filters(), wp_using_ext_object_cache(), wp_cache_set() |
!wp_using_ext_object_cache() && wp_installing() | 36 | apply_filters(), apply_filters(), wp_using_ext_object_cache(), wp_installing(), wp_cache_set() |
!wp_using_ext_object_cache() && !wp_installing() | 46 | apply_filters(), apply_filters(), wp_using_ext_object_cache(), wp_installing(), get_site_option(), update_site_option() |
!wp_using_ext_object_cache() && !wp_installing() | 47 | apply_filters(), apply_filters(), wp_using_ext_object_cache(), wp_installing(), get_site_option(), add_site_option() |
!wp_using_ext_object_cache() && !wp_installing() | 53 | apply_filters(), apply_filters(), wp_using_ext_object_cache(), wp_installing(), get_site_option(), time(), update_site_option(), update_site_option() |
!wp_using_ext_object_cache() && !wp_installing() | 54 | apply_filters(), apply_filters(), wp_using_ext_object_cache(), wp_installing(), get_site_option(), time(), add_site_option(), add_site_option() |
wp_using_ext_object_cache() | 55 | apply_filters(), apply_filters(), wp_using_ext_object_cache(), wp_cache_set(), do_action(), do_action() |
!wp_using_ext_object_cache() && wp_installing() | 58 | apply_filters(), apply_filters(), wp_using_ext_object_cache(), wp_installing(), wp_cache_set(), do_action(), do_action() |
!wp_using_ext_object_cache() && !wp_installing() | 68 | apply_filters(), apply_filters(), wp_using_ext_object_cache(), wp_installing(), get_site_option(), update_site_option(), do_action(), do_action() |
!wp_using_ext_object_cache() && !wp_installing() | 69 | apply_filters(), apply_filters(), wp_using_ext_object_cache(), wp_installing(), get_site_option(), add_site_option(), do_action(), do_action() |
!wp_using_ext_object_cache() && !wp_installing() | 75 | apply_filters(), apply_filters(), wp_using_ext_object_cache(), wp_installing(), get_site_option(), time(), update_site_option(), update_site_option(), do_action(), do_action() |
!wp_using_ext_object_cache() && !wp_installing() | 76 | apply_filters(), apply_filters(), wp_using_ext_object_cache(), wp_installing(), get_site_option(), time(), add_site_option(), add_site_option(), do_action(), do_action() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3 and 8.4: 97 instructions, 33–76 executed per call, 6 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 5
5 hooks fire while set_site_transient() runs, in this order:
- apply_filters( pre_set_site_transient_{$transient} )filterline 2654 (+13 into the body)
Filters the value of a specific site transient before it is set.
- apply_filters( expiration_of_site_transient_{$transient} )filterline 2669 (+28 into the body)
Filters the expiration for a site transient before its value is set.
- do_action( set_site_transient_{$transient} )actionline 2705 (+64 into the body)
Fires after the value for a specific site transient has been set.
- do_action( set_site_transient )actionline 2716 (+75 into the body)
Fires after the value for a site transient has been set.
- do_action( setted_site_transient )action_deprecatedline 2728 (+87 into the body)
Fires after the value for a site transient has been set.
Uses · 10
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_using_ext_object_cache()Toggles `$_wp_using_ext_object_cache` on and off without directly touching global.
- wp_installing()Checks or sets whether WordPress is in "installation" mode.
- wp_cache_set()Saves the data to the cache.
- wp_prime_site_option_caches()Primes specific network options for the current network into the cache with a single database query.
- get_site_option()Retrieve an option value for the current network based on name of option.
- add_site_option()Adds a new option for the current network.
- update_site_option()Updates the value of an option that was already added for the current network.
- do_action()Calls the callback functions that have been added to an action hook.
- do_action_deprecated()Fires functions attached to a deprecated action hook.
Used by · 20
- WP_Community_Events::cache_events()Caches an array of events data from the Events API.
- WP_Feed_Cache_Transient::save()Saves data to the transient.
- WP_Feed_Cache_Transient::touch()Sets mod transient.
- WP_Font_Collection::load_from_url()Loads the font collection data from a JSON file URL.
- WP_Plugin_Dependencies::get_dependency_api_data()Retrieves and stores dependency plugin data from the WordPress.org Plugin API.
- WP_REST_Pattern_Directory_Controller::get_items()Search and retrieve block patterns metadata
- WP_REST_URL_Details_Controller::set_cache()Utility function to cache a given data set at a given cache key.
- WP_Theme::set_pattern_cache()Sets block pattern cache.
- delete_plugins()Removes directory and files of a plugin for a list of plugins.
- get_theme_feature_list()Retrieves list of WordPress theme features (aka theme tags).
- install_popular_tags()Retrieves popular WordPress plugin tags.
- search_theme_directories()Searches all registered theme directories for complete and valid themes.
Show all 20
- wp_check_browser_version()Checks if the user needs a browser update.
- wp_check_php_version()Checks if the user needs to update PHP.
- wp_credits()Retrieves the contributor credits.
- wp_get_available_translations()Get available translations from the WordPress.org API.
- wp_get_popular_importers()Returns a list from WordPress.org of popular importer plugins.
- wp_update_plugins()Checks for available updates to plugins based on the latest versions hosted on WordPress.org.
- wp_update_themes()Checks for available updates to themes based on the latest versions hosted on WordPress.org.
- wp_version_check()Checks WordPress version against the newest version.
Source code
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() || wp_installing() ) { $result = wp_cache_set( $transient, $value, 'site-transient', $expiration ); } else { $transient_timeout = '_site_transient_timeout_' . $transient; $option = '_site_transient_' . $transient; wp_prime_site_option_caches( array( $option, $transient_timeout ) ); 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 6.8.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( 'set_site_transient', $transient, $value, $expiration ); /** * Fires after the value for a site transient has been set. *Changelog
Introduced in 2.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/option.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.