wp_load_alloptions( bool $force_cache = false ): array
- Since
- 2.2.0, 5.3.1
- Source
wp-includes/option.php:600
Compatibility
- WordPress
- since 5.3.1
- PHP
- 7.4–8.6-dev
- 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.6-dev.
Parameters
$force_cachebooloptional- Whether to force an update of the local cache from the persistent cache. Default false.Default:
false
Return value
array- List of all options.
Performance profile
How much work a call to wp_load_alloptions() 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 11–79
- Plugin surface
- 3 hooks
- Called by
- 12
Reaches the database via ->get_results().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 86.
Third-party callbacks on 'pre_wp_load_alloptions', 'pre_cache_alloptions', 'alloptions' run inside this call, and their cost is not bounded by anything here.
12 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()called directly - sqldatabase query
->get_results()called directly
What one call costs · 22 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_load_alloptions() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
is_array($alloptions) | 11 | apply_filters() |
!is_array($alloptions) && wp_installing() && is_multisite() | 23 | apply_filters(), wp_installing(), is_multisite(), apply_filters() |
!is_array($alloptions) && !wp_installing() | 26 | apply_filters(), wp_installing(), wp_cache_get(), apply_filters() |
!is_array($alloptions) && wp_installing() && !is_multisite() | 29 | apply_filters(), wp_installing(), is_multisite(), wp_cache_get(), apply_filters() |
!is_array($alloptions) && wp_installing() && is_multisite() | 56–57 | apply_filters(), wp_installing(), is_multisite(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->suppress_errors(), wp_installing(), is_multisite(), apply_filters() |
!is_array($alloptions) && is_multisite() | 59–60 | apply_filters(), wp_installing(), wp_cache_get(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->suppress_errors(), wp_installing(), is_multisite(), apply_filters() |
!is_array($alloptions) && wp_installing() && is_multisite() | 62–63 | apply_filters(), wp_installing(), is_multisite(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->get_results(), ->suppress_errors(), wp_installing(), is_multisite(), apply_filters() |
!is_array($alloptions) && wp_installing() | 62–63 | apply_filters(), wp_installing(), is_multisite(), wp_cache_get(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->suppress_errors(), wp_installing(), is_multisite(), apply_filters() |
!is_array($alloptions) && is_multisite() | 63–64 | apply_filters(), wp_installing(), is_multisite(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->suppress_errors(), wp_installing(), apply_filters(), wp_cache_add(), apply_filters() |
!is_array($alloptions) && is_multisite() | 65–66 | apply_filters(), wp_installing(), wp_cache_get(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->get_results(), ->suppress_errors(), wp_installing(), is_multisite(), apply_filters() |
!is_array($alloptions) && !wp_installing() | 66–67 | apply_filters(), wp_installing(), wp_cache_get(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->suppress_errors(), wp_installing(), apply_filters(), wp_cache_add(), apply_filters() |
!is_array($alloptions) && wp_installing() | 66–67 | apply_filters(), wp_installing(), is_multisite(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->suppress_errors(), wp_installing(), is_multisite(), apply_filters(), wp_cache_add(), apply_filters() |
10 further outcomes, up to 79 instructions
!is_array($alloptions) && wp_installing() | 68–69 | apply_filters(), wp_installing(), is_multisite(), wp_cache_get(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->get_results(), ->suppress_errors(), wp_installing(), is_multisite(), apply_filters() |
!is_array($alloptions) && !is_multisite() | 69–70 | apply_filters(), wp_installing(), wp_cache_get(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->suppress_errors(), wp_installing(), is_multisite(), apply_filters(), wp_cache_add(), apply_filters() |
!is_array($alloptions) && is_multisite() | 69–70 | apply_filters(), wp_installing(), is_multisite(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->get_results(), ->suppress_errors(), wp_installing(), apply_filters(), wp_cache_add(), apply_filters() |
!is_array($alloptions) && !is_multisite() | 69–70 | apply_filters(), wp_installing(), is_multisite(), wp_cache_get(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->suppress_errors(), wp_installing(), apply_filters(), wp_cache_add(), apply_filters() |
!is_array($alloptions) && !wp_installing() | 72–73 | apply_filters(), wp_installing(), wp_cache_get(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->get_results(), ->suppress_errors(), wp_installing(), apply_filters(), wp_cache_add(), apply_filters() |
!is_array($alloptions) && wp_installing() | 72–73 | apply_filters(), wp_installing(), is_multisite(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->get_results(), ->suppress_errors(), wp_installing(), is_multisite(), apply_filters(), wp_cache_add(), apply_filters() |
!is_array($alloptions) && wp_installing() && !is_multisite() | 72–73 | apply_filters(), wp_installing(), is_multisite(), wp_cache_get(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->suppress_errors(), wp_installing(), is_multisite(), apply_filters(), wp_cache_add(), apply_filters() |
!is_array($alloptions) && !is_multisite() | 75–76 | apply_filters(), wp_installing(), wp_cache_get(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->get_results(), ->suppress_errors(), wp_installing(), is_multisite(), apply_filters(), wp_cache_add(), apply_filters() |
!is_array($alloptions) && !is_multisite() | 75–76 | apply_filters(), wp_installing(), is_multisite(), wp_cache_get(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->get_results(), ->suppress_errors(), wp_installing(), apply_filters(), wp_cache_add(), apply_filters() |
!is_array($alloptions) && wp_installing() && !is_multisite() | 78–79 | apply_filters(), wp_installing(), is_multisite(), wp_cache_get(), ->suppress_errors(), wp_autoload_values_to_autoload(), esc_sql(), ->get_results(), ->get_results(), ->suppress_errors(), wp_installing(), is_multisite(), apply_filters(), wp_cache_add(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 86 | 11–79 | 9 | |
| 8.5 | 86 | 11–79 | 9 | |
| 8.4 | 86 | 11–79 | 9 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 89 | 11–82 | 9 | |
| 8.2 | 89 | 11–82 | 9 | |
| 8.1 | 89 | 11–82 | 9 | |
| 7.4 | 89 | 11–82 | 9 |
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 · 3
3 hooks fire while wp_load_alloptions() runs, in this order:
- apply_filters( pre_wp_load_alloptions )filterline 614 (+14 into the body)
Filters the array of alloptions before it is populated.
- apply_filters( pre_cache_alloptions )filterline 647 (+47 into the body)
Filters all options before caching them.
- apply_filters( alloptions )filterline 660 (+60 into the body)
Filters all options after retrieving them.
Uses · 7
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_installing()Checks or sets whether WordPress is in "installation" mode.
- is_multisite()Determines whether Multisite is enabled.
- wp_cache_get()Retrieves the cache contents from the cache by key and group.
- esc_sql()Escapes data for use in a MySQL query.
- wp_autoload_values_to_autoload()Returns the values that trigger autoloading from the options table.
- wp_cache_add()Adds data to the cache, if the cache key doesn't already exist.
Used by · 12
- WP_Site_Health::get_autoloaded_options_size()Calculates total amount of autoloaded data.
- WP_Site_Health::get_test_autoloaded_options()Tests the number of autoloaded options.
- WP_Site_Health::should_suggest_persistent_object_cache()Determines whether to suggest using a persistent object cache.
- add_option()Adds a new option.
- delete_option()Removes an option by name. Prevents removal of protected WordPress options.
- get_alloptions()Retrieve all autoload options, or all options if no autoloaded ones exist.
- get_option()Retrieves an option value based on an option name.
- get_transient()Retrieves the value of a transient.
- is_blog_installed()Determines whether WordPress is already installed.
- update_option()Updates the value of an option that was already added.
- wp_prime_option_caches()Primes specific options into the cache with a single database query.
- wp_set_option_autoload_values()Sets the autoload values for multiple options in the database.
Source code
function wp_load_alloptions( $force_cache = false ) { global $wpdb; /** * Filters the array of alloptions before it is populated. * * Returning an array from the filter will effectively short circuit * wp_load_alloptions(), returning that value instead. * * @since 6.2.0 * * @param array|null $alloptions An array of alloptions. Default null. * @param bool $force_cache Whether to force an update of the local cache from the persistent cache. Default false. */ $alloptions = apply_filters( 'pre_wp_load_alloptions', null, $force_cache ); if ( is_array( $alloptions ) ) { return $alloptions; } if ( ! wp_installing() || ! is_multisite() ) { $alloptions = wp_cache_get( 'alloptions', 'options', $force_cache ); } else { $alloptions = false; } if ( ! $alloptions ) { $suppress = $wpdb->suppress_errors(); $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload IN ( '" . implode( "', '", esc_sql( wp_autoload_values_to_autoload() ) ) . "' )" ); if ( ! $alloptions_db ) { $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ); } $wpdb->suppress_errors( $suppress ); $alloptions = array(); foreach ( (array) $alloptions_db as $o ) { $alloptions[ $o->option_name ] = $o->option_value; } if ( ! wp_installing() || ! is_multisite() ) { /** * Filters all options before caching them. * * @since 4.9.0 * * @param array $alloptions Array with all options. */ $alloptions = apply_filters( 'pre_cache_alloptions', $alloptions ); wp_cache_add( 'alloptions', $alloptions, 'options' ); } } /** * Filters all options after retrieving them. * * @since 4.9.0 * * @param array $alloptions Array with all options. */ return apply_filters( 'alloptions', $alloptions );}Changelog
Introduced in 2.2.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$force_cache parameter was added.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.