4

I want to create a specialized function that check certain parameters (page requested, ip of user against a list), if the user matches he will be redirected to a different site, if he doesn't match he will be allowed to continue to the original requested page.

However the website is cached using W3TC Page Cache, and I can't seem to locate the place where I should put my code to act before W3TC returns the cached page.

2
  • Have you tried adding an action on "init"? codex.wordpress.org/Plugin_API/Action_Reference/init
    – Mike
    Commented Sep 3, 2013 at 13:17
  • I thought about this, and went and had a look in the codex for the earliest hook. I believe w3tc is a standard plugin, so would building a plugin and installing is as a "must use plugin" work, they are called before other plugins, you won't be able to use an activation hook, but since you arn't rendering anything, just redirecting, you may be able to do the ip lookup and set the redirection header? This may not be the correct way, but as far as I can tell, w3tc offers no "before cache" hook codex.wordpress.org/Must_Use_Plugins
    – Matt.C
    Commented Sep 17, 2013 at 11:00

1 Answer 1

2

Since W3TC serves cached pages via htaccess before PHP can do anything, you will have to either:

  1. Do this directly in the .htaccess file before the W3TC rules.

    See for example https://stackoverflow.com/questions/293285/want-to-redirect-all-visitors-except-for-me, although that won't be possible if the list of IPs is dynamic or in a database)

  2. Disable W3 Total Cache's "page cache" but leave other cache types on (only if you're not on a shared hosting plan and have a VPS or dedicated server)

    Don't panic! You'll still get large performance improvements by leaving the "Object Cache" and the "DB Cache" on. Note that these require a memory cache module like APC or xCache installed, which, by the way, I hugely recommend).

1
  • You're basically saying there is no solution... but it's apparently the correct answer :-( Commented Oct 9, 2013 at 4:49

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