Allow editing cache rule conditions.

7hemech

New member
Hey, I we went over this on the wordpress forum, but I was thinking on the other hand it's a bit too much to ask for every extension to edit your rules in order for guest page caching to work, so maybe an option to edit the rule conditions or add exceptions from the dashboard would be nice.
 
Maybe… although things like that are a balance between “easy to use” and functionality. If every possible thing was added, the settings/UI would become an overload of things that 99% aren’t going to use.

One thing about the cache rule for guest page caching is it’s written to Cloudflare Cache Rules only when guest page caching is enabled. Given that, I’m not sure it’s any easier with real-world use to edit it in the normal Cloudflare dashboard vs WordPress admin. In fact it might even make it a little more kludgey doing it in WordPress admin. Specifically, people are probably not going to edit the rule before they edit guest page caching… so then they would need to disable guest page caching, edit the rule, then re-enable guest page caching to write the rule to Cloudflare. Seems it’s less work (and more flexible if they wanted to enable secondary options) to just edit the rule in Cloudflare dashboard to start with? Then you don’t need to temporarily disable guest page caching to change the rule.
 
Maybe… although things like that are a balance between “easy to use” and functionality. If every possible thing was added, the settings/UI would become an overload of things that 99% aren’t going to use.

One thing about the cache rule for guest page caching is it’s written to Cloudflare Cache Rules only when guest page caching is enabled. Given that, I’m not sure it’s any easier with real-world use to edit it in the normal Cloudflare dashboard vs WordPress admin. In fact it might even make it a little more kludgey doing it in WordPress admin. Specifically, people are probably not going to edit the rule before they edit guest page caching… so then they would need to disable guest page caching, edit the rule, then re-enable guest page caching to write the rule to Cloudflare. Seems it’s less work (and more flexible if they wanted to enable secondary options) to just edit the rule in Cloudflare dashboard to start with? Then you don’t need to temporarily disable guest page caching to change the rule.
Hm, maybe it can be in the guest caching page itself under maybe advanced button or small text.
 
I'm not going to absolutely say no, but it would be very far down the priority list. It really would be better situated within the filter mechanism. It would be trivially easy for any third-party plugin to add whatever the custom cookie they are using and not relying on their users to write custom code to do it.

That being said, an easy middle-ground (for now) is to utilize the Code Snippets plugin, and create a new snippet to Run everywhere with the following code:

PHP:
add_filter('cloudflare_guest_page_cacheable', function($guestPageCacheable) {
    $guestPageCacheable[] = 'not http.cookie contains "my-special-cookie="';
    return $guestPageCacheable;
});

...again it's better if that code existed in the plugin that is creating whatever unique cookie you want to treat as a non-cacheable user, but if they aren't willing to do that, you can add the code yourself with that plugin.

There's more internal moving parts than just the Cache Rule in Cloudflare. Using the filter will also allow the server-side (your server) logic to know when to flag something as cacheable or not.
 
I'm not going to absolutely say no, but it would be very far down the priority list. It really would be better situated within the filter mechanism. It would be trivially easy for any third-party plugin to add whatever the custom cookie they are using and not relying on their users to write custom code to do it.

That being said, an easy middle-ground (for now) is to utilize the Code Snippets plugin, and create a new snippet to Run everywhere with the following code:

PHP:
add_filter('cloudflare_guest_page_cacheable', function($guestPageCacheable) {
    $guestPageCacheable[] = 'not http.cookie contains "my-special-cookie="';
    return $guestPageCacheable;
});

...again it's better if that code existed in the plugin that is creating whatever unique cookie you want to treat as a non-cacheable user, but if they aren't willing to do that, you can add the code yourself with that plugin.

There's more internal moving parts than just the Cache Rule in Cloudflare. Using the filter will also allow the server-side (your server) logic to know when to flag something as cacheable or not.
Wait, so how exactly does that work, does it replace all rules the plugin currently applies, because I just want to get rid of the wp- one
 
You can do whatever you want really... that's why I was saying it's the best way to do it because it's not only flexible, you can literally do whatever you want with it. So whatever situation is unique to you, you can do. That particular example adds another cookie to the Cache Rule, but say you wanted to remove the wp-* cookie(s) portion of the existing rule, the code would look like so:

PHP:
add_filter('cloudflare_guest_page_cacheable', function($guestPageCacheable) {
    unset($guestPageCacheable[array_search('not http.cookie contains "wp-"', $guestPageCacheable)]);
    return $guestPageCacheable;
});

The appropraite place for something like that is the third-party plugin that needs that change made (that way it's automatic/transparent for their users), however I'm going to see if there's a way we could do it with a wp-config.php edit (without needing the Code Snippets plugin). But giving people a UI to make free-form code changes is really asking for problems (a support nightmare and user confusion).
 
Okay, so the next version also has a new mechanism so you can optionally define filters by using a PHP closure within your standard wp-config.php file.

This will allow you to leverage your own filter code, but without cluttering/adding complexity to the standard UI. It still would be more appropriate to have the filter code in the third-party plugins that need it, but in case that's not an option for whatever reason, this allows you to do it without needing to install the Code Snippets plugin.

For example to remove the wp-* cookie from the Cache Rule, you can put this in your wp-config.php file:

PHP:
$GLOBALS['app_for_cf_guest_page_cacheable'] = function($guestPageCacheable) {
    unset($guestPageCacheable[array_search('not http.cookie contains "wp-"', $guestPageCacheable)]);
    return $guestPageCacheable;
};

...just to be clear, this does not work as of this instant, it *will* work when the next version of the App for Cloudflare plugin is pushed out to wordpress.org.
 
Back
Top