I would like to filter all the options values, but the option filters are option specific. Is there a way I could do something like

add_filter('pre_option_*', 'my_check');


2 Answers 2


I've tried the same thing and was able to hook into the pre_option_ filter by using all as filter.

add_filter('all', 'pre_option_',1,3);

function pre_option_($actionHook,$bool=false,$option_name)
    if(strpos($actionHook,'pre_option_') === FALSE){
        return $bool;

I suppose you could use wp_load_alloptions() and add a filter for each:

foreach ( array_keys( wp_load_alloptions() ) as $option ) {
    add_filter( 'pre_option_' . $option, function ( $pre ) use ( $option ) {
        // blah
        return $pre;
    } );
  • even tough this is actually an answer it would mean to add like 200+ filters which does not seem like a good idea to me
    – untore
    Commented Nov 2, 2015 at 13:31
  • No, it probably isn't. Why do you want to pre-filter all the options?
    – bonger
    Commented Nov 2, 2015 at 14:06
  • so that I can have a single configuration for all the plugins I use in a multisite setup without having to replicate all the options in all the _options tables, if all the plugins provided support for multisite with get_site_option it would have been simple but not everyone use it. Of course if this was possible I would trim out wordpress core options for each subsite which are ~100, but wordpress does not provide a general hook when getting the options
    – untore
    Commented Nov 2, 2015 at 14:37
  • Oh that's interesting - if you add that info to your question you may get better responses...
    – bonger
    Commented Nov 2, 2015 at 15:04
  • not all options are loaded from DB at that time, only the autoloading one do, and obviously you miss the options being created at the specific session Commented Jul 2, 2016 at 4:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.