WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 3 months ago

#44412 new enhancement

'pre_cache_alloptions' filter in wp_load_alloptions() in option.php cannot be hooked

Reported by: redsnowcompany Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Cache API Keywords: needs-docs
Focuses: Cc:

Description

Whenever wordpress loads, it fetches all options with the wp_load_alloptions() function in the option.php file. There is a filter in the function before sending it to the cache: {{{#!php
<?php
$alloptions = apply_filters( 'pre_cache_alloptions', $alloptions );
}}}.

However, there is no way to hook into this filter in the theme or plugin because the theme or plugin are loaded afterwards.

So the full array is always send to the cache.

We were having trouble with a site that loaded all of the options with autoload 'yes' and it crashed with a memory limit exhausted error because there were too many options.

An action needs to be added to hook into this filter or move the calling of this function some steps further after a theme or plugin is loaded.

Change History (2)

#1 @sabernhardt
12 months ago

  • Component changed from General to Cache API

#2 @azaozz
3 months ago

  • Keywords needs-docs added
  • Milestone changed from Awaiting Review to Future Release
  • Severity changed from major to normal
  • Type changed from defect (bug) to enhancement

Thanks @redsnowcompany for opening this ticket. You're right, the pre_cache_alloptions filter is unusable from plugins and themes. Seems it can only be used from cli or from one of the caching "drop-in" plugins. Don't think that can be changed.

Best would be to update the docs. A similar "too early" filter is enable_loading_advanced_cache_dropin, see https://developer.wordpress.org/reference/hooks/enable_loading_advanced_cache_dropin/.

We were having trouble with a site that loaded all of the options with autoload 'yes' and it crashed with a memory limit exhausted error because there were too many options.

That's usually caused by old or buggy plugin(s). Best would be to fix or replace the plugin. Having a huge options table is no good :)

Note: See TracTickets for help on using tickets.