Custom cloudflare url filter
-
Oh hi. We are trying to implement two functionalities using the “cloudflare_purge_by_url” function.
- Modify urls to be purge
- Add some new ones to the list
Couldn’t find much documentation on this function. Is this the way? Is it necessary to add the condition so that the additional urls are added only for the ‘post’ post_type or that would be a default behaviour?
// workaround for cloudflare APO to be able to invalidate cache being the WP admin WP_HOME and the site PUBLIC_API_URL // also solves issues related to flexible SSL usage and the cache invalidation function custom_cloudflare_url_filter($urls, $post_id) { foreach ($urls as &$url) { $url = str_replace('http://', 'https://', $url); $url = str_replace(WP_HOME, PUBLIC_API_URL, $url); } $current_post_type = get_post_type($post_id); if ($current_post_type === 'post') { $additional_urls = [ PUBLIC_API_URL . '/populaire', PUBLIC_API_URL . '/tendance', PUBLIC_API_URL . '/hot', PUBLIC_API_URL . '/la-team', get_permalink($post_id) . '/amp' ]; $urls = array_merge($urls, $additional_urls); } $urls = array_merge($urls, $additional_urls); return $urls; } add_filter('cloudflare_purge_by_url', 'custom_cloudflare_url_filter', 10, 2);
The topic ‘Custom cloudflare url filter’ is closed to new replies.