1

I want to polyfill some functions before object-cache.php runs. I have PHP7 and APCu installed. However, W3 Total Cache is using apc_* functions, not apcu_* functions. W3 Total Cache's object cache runs using object-cache.php, which is loaded before any plugins run.

How can I run custom code before W3 Total Cache runs without modifying WordPress core? I also can't use PHP's auto_prepend_file because WordFence is using it.

Here is the code I want to run:

if (function_exists('apcu_add') && !function_exists('apc_add')) {
    function apc_add() {
        return call_user_func_array('apcu_add', func_get_args());
    }

    function apc_cache_info() {
        return call_user_func_array('apcu_cache_info', func_get_args());
    }

    function apc_cas() {
        return call_user_func_array('apcu_cas', func_get_args());
    }

    ...
}

I might just paste it into wp-config.php.

  • not 100% sure for this case but /wp-content/mu-plugins/ directory is typically best for things like this. – majick Jul 30 '16 at 9:46
  • In wp-settings.php, the object cache is initialized before multisite is initialized. – Leo Jiang Jul 30 '16 at 18:03
  • I suppose you could put it in advanced-cache.php but that may be overwritten by w3c anyway, so I guess your best bet is probably wp-config.php after all. – majick Aug 1 '16 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.