Title: pre_cache_alloptions
Published: November 20, 2017
Last modified: April 28, 2025

---

# apply_filters( ‘pre_cache_alloptions’, array $alloptions )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/pre_cache_alloptions/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/pre_cache_alloptions/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/pre_cache_alloptions/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/pre_cache_alloptions/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/pre_cache_alloptions/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/pre_cache_alloptions/?output_format=md#wp--skip-link--target)

Filters all options before caching them.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/pre_cache_alloptions/?output_format=md#parameters)󠁿

 `$alloptions`array

Array with all options.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/pre_cache_alloptions/?output_format=md#source)󠁿

    ```php
    $alloptions = apply_filters( 'pre_cache_alloptions', $alloptions );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/option.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/option.php#L648)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/option.php#L648-L648)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/pre_cache_alloptions/?output_format=md#related)󠁿

| Used by | Description | 
| [wp_load_alloptions()](https://developer.wordpress.org/reference/functions/wp_load_alloptions/)`wp-includes/option.php` |

Loads and caches all autoloaded options, if available or all options.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/pre_cache_alloptions/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.9.0](https://developer.wordpress.org/reference/since/4.9.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/pre_cache_alloptions/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/hooks/pre_cache_alloptions/?output_format=md#comment-content-4520)
 2.    [Nawawi Jamili](https://profiles.wordpress.org/nawawijamili/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/pre_cache_alloptions/#comment-4520)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpre_cache_alloptions%2F%23comment-4520)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpre_cache_alloptions%2F%23comment-4520)
 4.  Optimize alloptions: remove option if size more than 1MB.
 5.      ```php
         add_action( 'pre_cache_alloptions', function( $alloptions ) {
         	foreach ( $alloptions as $key => $value ) {
         		$size = strlen( maybe_serialize( $value ) );
         		if ( $size > 1000000 ) {
         			unset( $alloptions[$key] );
         		}
         	}
         	return $alloptions;
         } );
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpre_cache_alloptions%2F%3Freplytocom%3D4520%23feedback-editor-4520)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/hooks/pre_cache_alloptions/?output_format=md#comment-content-5022)
 8.    [Chengmin](https://profiles.wordpress.org/rsm0128/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/pre_cache_alloptions/#comment-5022)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpre_cache_alloptions%2F%23comment-5022)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpre_cache_alloptions%2F%23comment-5022)
 10. We can not use this hook in themes and plugins as it is fired before themes and
     plugins are loaded.
 11.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpre_cache_alloptions%2F%3Freplytocom%3D5022%23feedback-editor-5022)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpre_cache_alloptions%2F)
before being able to contribute a note or feedback.