gen:enable_varnish
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| gen:enable_varnish [2025/09/16 10:07] – kirtisingh | gen:enable_varnish [2025/11/08 05:55] (current) – kirtisingh | ||
|---|---|---|---|
| Line 34: | Line 34: | ||
| With WordPress you can easily use Varnish and enable auto-purging of content (when it changes), by using the [[https:// | With WordPress you can easily use Varnish and enable auto-purging of content (when it changes), by using the [[https:// | ||
| - | Now if the page you changed/ | + | **In some scenarios, Proxy Cache Purge plugin might not flush the cache or may not be of help**\\ |
| + | - If the page you changed/ | ||
| + | - If a plugin/theme is updated which is related | ||
| + | |||
| + | For those cases we advise that you append the following block of code to the functions.php file of your WordPress theme . If the functions.php file does not exist, please create one. | ||
| + | |||
| + | **Important : Please check verify the functionality after implementing it. This code snippet is provieded only as a goodwill gesture** | ||
| <code php> | <code php> | ||
| - | /* action w.r.t. save post in order to flush / URL - start */ | + | function custom2_varnish_flush_all($upgrader_object, |
| + | |||
| + | preg_match('# | ||
| + | |||
| + | $vhost_dir=$matches[1]; | ||
| + | |||
| + | $hosts=array(); | ||
| + | |||
| + | $hosts[]=preg_replace('# | ||
| + | $hosts[]=' | ||
| + | |||
| + | for($i=0; | ||
| + | |||
| + | $ch = curl_init(); | ||
| + | |||
| + | curl_setopt($ch, | ||
| + | |||
| + | curl_setopt($ch, | ||
| + | |||
| + | curl_setopt($ch, | ||
| + | 'Host: ' | ||
| + | ' | ||
| + | )); | ||
| + | |||
| + | curl_setopt($ch, | ||
| + | |||
| + | $response = curl_exec($ch); | ||
| + | |||
| + | if (curl_errno($ch)) { | ||
| + | file_put_contents($vhost_dir.' | ||
| + | } else { | ||
| + | file_put_contents($vhost_dir.'/ | ||
| + | } | ||
| + | |||
| + | curl_close($ch); | ||
| + | |||
| + | } | ||
| + | |||
| + | } | ||
| function custom2_save_post_action($post_id, | function custom2_save_post_action($post_id, | ||
| Line 83: | Line 127: | ||
| } | } | ||
| - | add_action( 'save_post', 'custom2_save_post_action', 10, 3 ); | + | add_action( 'upgrader_process_complete', 'custom2_varnish_flush_all', 10, 2 ); |
| - | /* action w.r.t. save post in order to flush / URL - end */ | + | add_action( ' |
| </ | </ | ||
gen/enable_varnish.1758017235.txt.gz · Last modified: 2025/09/16 10:07 by kirtisingh
