If I understand correctly, you should simply be able to add more user agent groups if you want more unique versions of cached pages. Otherwise you can simply add a page to “never cache the following pages” option on the page cache settings tab to get the desired effect.
Thread Starter
kdoole
(@kdoole)
Yep, understand that, but I have an array with about 40 elements (very rough guess) that tests against the user agent string. So instead of having to maintain a list of every conceivable user mobile agent string (there are many) to a user agent group, i’d like to be able to use a preg_match_all and just test for some key words in the string.
My guess would be:
w3tc_add_action('w3tc_pgcache_cache_key', 'modify_page_key');
function modify_page_key($key) {
//if user agent matches any of the elements in the array of mobile-like user agent words, $key .= 'something_special';
}
I will give this a try now, but if you have a better solution, lay it on me! I think this should work though… right?
Thread Starter
kdoole
(@kdoole)
This appears to work quite nicely.
I understand how this is working and I’ve got a similar action call in place on a site but how can I be sure that this is happening? Using the action above, it doesn’t seem like W3 is calling the function it needs to … wp_die(), add_action(), echo, nothing seems to be responding.
Code I’m using is below. The constant you’re seeing is set in the template_redirect action. Still, if I add ‘wp_die()’ to the function, it doesn’t respond.
if (function_exists('w3tc_add_action')) w3tc_add_action('w3tc_pgcache_cache_key', 'proper_modify_page_key');
function proper_modify_page_key($key) {
if (constant('MOBILE_USER_AGENT_DETECTED')) $key .= '_mobile_user_agent';
return $key;
}
Thanks in advance!