LiteSpeed Cache + Flamingo
-
I use the Flamingo plugin, every time a form is submitted, records with post_type flamingo_contact and flamingo_inbound are saved in _post, the LiteSpeed Cache auto-purge function is activated.
How to avoid auto-purge when these Flamingo records are saved?
-
function lscwp_suppress_purge_update( $new_status, $old_status, $post ) {
if ( $post->post_type != 'flamingo_inbound' ) {
return;
}
ob_start( function($buffer) use ($post) {
@header("X-LiteSpeed-Purge: " . LSWCP_TAG_PREFIX . "_Po." . $post->ID );
return $buffer;
} );
}
add_action( 'transition_post_status', 'lscwp_suppress_purge_update', 10, 3 );please try this code snippet
Flamingo in addition to flamingo_inbound also writes the flamingo_contact record in pairs, so the code should also include flamingo_contact.
I will then save this code in mu-plugins (PHP file with Plugin Name and Description, in plugin style), or is that not good?
Thanks!
well , be hoenst I am not sure , the mu-plugin fires at very early stage, but since it is using
transition_post_status, so I think it should workyes, please add others if you see fit , that was code snippet I have had from/with another user who uses flamingo , your use case might be different , so need some adaption
I’m not very good at coding, the line
if ( $post->post_type != 'flamingo_inbound' ) {
how would it be adding flamingo_contact too?if ( $post->post_type != 'flamingo_inbound' && $post->post_type != 'flamingo_contact' ) {
return;
}please try this one
I inserted the following code in functions.php:
function lscwp_suppress_purge_update( $new_status, $old_status, $post ) {
// Debug log: indicate function entry
error_log( "[LSCache Debug] lscwp_suppress_purge_update called for post #{$post->ID}, type {$post->post_type}, status {$old_status}→{$new_status}" );
if ( $post->post_type != 'flamingo_inbound' && $post->post_type != 'flamingo_contact' ) {
// Debug log: post type not excluded
error_log( "[LSCache Debug] Post type {$post->post_type} not excluded, exiting." );
return;
}
// Debug log: post type is excluded
error_log( "[LSCache Debug] Post type {$post->post_type} is excluded, starting ob_start()." );
ob_start( function($buffer) use ($post) {
// Debug log: inside buffer callback
error_log( "[LSCache Debug] Inside ob_start callback for post #{$post->ID}, sending override header." );
@header("X-LiteSpeed-Purge: " . LSWCP_TAG_PREFIX . "_Po." . $post->ID );
return $buffer;
} );
}
add_action( 'transition_post_status', 'lscwp_suppress_purge_update', 10, 3 );Unfortunately the auto purge happened, debug.log gives me this:
[20-May-2025 07:41:30 UTC] [LSCache Debug] lscwp_suppress_purge_update called for post #29503, type flamingo_contact, status new→publish
[20-May-2025 07:41:30 UTC] [LSCache Debug] Post type flamingo_contact is excluded, starting ob_start().
[20-May-2025 07:41:31 UTC] [LSCache Debug] lscwp_suppress_purge_update called for post #29504, type flamingo_inbound, status new→publish
[20-May-2025 07:41:31 UTC] [LSCache Debug] Post type flamingo_inbound is excluded, starting ob_start().
[20-May-2025 07:41:31 UTC] [LSCache Debug] Inside ob_start callback for post #29504, sending override header.
[20-May-2025 07:41:31 UTC] [LSCache Debug] Inside ob_start callback for post #29503, sending override header.I need to clarify something… I don’t need to prevent the purge of the post_type flamingo_inbound and flamingo_contact when a form is submitted.
I need to prevent the entire site from auto-purge when a form is submitted and Flamingo writes the post_type flamingo_inbound and flamingo_contact to the DB.
the code snippet , if it works , then it will only purge the page itself where the form is placed , while suppress purge for all other pages
yes , this `
@header("X-LiteSpeed-Purge: " . LSWCP_TAG_PREFIX . "_Po." . $post->ID );code will NOT modify plugin’s log , it will still show what it was
you may need to verify it from server side debug log to see what header php sends out
or verify few pages that you see it was purged before , and see if they are purged now with code snippet
-
This reply was modified 1 year ago by
qtwrk.
Unfortunately with the code provided, as soon as a form is submitted, and therefore Flamingo creates 2 records, the purge-all occurs.
Can you verify the code better, also based on the log provided?
We need to block purge-all, we could also hook to post_author = 0 because Flamingo inserts records with post_author = 0.
Thanks!
So… the code works on a staging site with Twenty Twenty-Five theme, but it doesn’t work with Divi theme. Maybe there is some problem intercepting the submissions because Divi uses a lot of Ajax?
please try enable the debug purge log
see if there is any other action (ajax, rest …etc) that called purge besides the main request , the code snippet probably only works on main request
Here is the debug.log (2 sends):
[27-May-2025 12:14:04 UTC] [LSCache Debug] lscwp_suppress_purge_update called for post #19698, type flamingo_contact, status publish→publish
[27-May-2025 12:14:04 UTC] [LSCache Debug] Post type flamingo_contact is excluded, starting ob_start().
[27-May-2025 12:14:04 UTC] [LSCache Debug] lscwp_suppress_purge_update called for post #29568, type flamingo_inbound, status new→publish
[27-May-2025 12:14:04 UTC] [LSCache Debug] Post type flamingo_inbound is excluded, starting ob_start().
[27-May-2025 12:14:05 UTC] [LSCache Debug] Inside ob_start callback for post #29568, sending override header.
[27-May-2025 12:14:05 UTC] [LSCache Debug] Inside ob_start callback for post #19698, sending override header.
[27-May-2025 12:26:32 UTC] [LSCache Debug] lscwp_suppress_purge_update called for post #29569, type flamingo_contact, status new→publish
[27-May-2025 12:26:32 UTC] [LSCache Debug] Post type flamingo_contact is excluded, starting ob_start().
[27-May-2025 12:26:32 UTC] [LSCache Debug] lscwp_suppress_purge_update called for post #29570, type flamingo_inbound, status new→publish
[27-May-2025 12:26:32 UTC] [LSCache Debug] Post type flamingo_inbound is excluded, starting ob_start().
[27-May-2025 12:26:32 UTC] [LSCache Debug] Inside ob_start callback for post #29570, sending override header.
[27-May-2025 12:26:32 UTC] [LSCache Debug] Inside ob_start callback for post #29569, sending override header.Here is the debug purge (2 sends):
05/27/25 14:14:05.353 [xxx:44916 1 RcT] 💓 ------POST HTTP/1.1 (HTTPS) /wp-json/contact-form-7/v1/contact-forms/29376/feedback
05/27/25 14:14:05.353 [xxx:44916 1 RcT] Query String:
05/27/25 14:14:05.353 [xxx:44916 1 RcT] HTTP_REFERER: https://xxx...
05/27/25 14:14:05.353 [xxx:44916 1 RcT] X-LiteSpeed-Purge: public,30d_Po.19698,30d_URL./,30d_W.recent-posts-2,30d_FD,30d_F,30d_H,30d_PGS,30d_PGSRP,30d_REST,30d_Po.29568 => LiteSpeed\LSC->send_headers()@603 => WP_Hook->apply_filters(ARRAY)@324 => WP_Hook->do_action(ARRAY)@348 =>
/home/xxx/public_html/wp-includes/load.php@517
05/27/25 14:26:32.421 [xxx:12470 1 E7a] 💓 ------POST HTTP/1.1 (HTTPS) /wp-json/contact-form-7/v1/contact-forms/28989/feedback
05/27/25 14:26:32.421 [xxx:12470 1 E7a] Query String:
05/27/25 14:26:32.421 [xxx:12470 1 E7a] HTTP_REFERER: https://xxx...
05/27/25 14:26:32.421 [xxx:12470 1 E7a] X-LiteSpeed-Purge: public,30d_Po.29569,30d_URL./,30d_W.recent-posts-2,30d_FD,30d_F,30d_H,30d_PGS,30d_PGSRP,30d_REST,30d_Po.29570 => LiteSpeed\LSC->send_headers()@603 => WP_Hook->apply_filters(ARRAY)@324 => WP_Hook->do_action(ARRAY)@348 =>
/home/xxx/public_html/wp-includes/load.php@517What’s wrong? Why does purge-all always happen?
the
@header("X-LiteSpeed-Purge: "will NOT replace the debug log from pluginyou need to hook into server-level debug log to see what is the actual header it receives
I don’t understand what I should do, I’m on a shared server, not on a server with full access.
From the published debugs, what do you see, that it’s OK, but the purge-all still happens? I need a solution, is it possible that the script can’t be improved?
no , I mean with the code snippet , it does NOT modify the plugin’s debug log , it will still shows all these tags, but it doesn’t mean all these tags are send out , it is being suppressed and repalced by that
@header()function -
This reply was modified 1 year ago by
The topic ‘LiteSpeed Cache + Flamingo’ is closed to new replies.