I'm providing a checkbox to my plugin Settings API to enable/disable certain Rewrite rules to my plugins CPT. I want to flush the rewrite rules when the specific setting is changed. So I did the following:
function my_flush_rules_while_rewrite_changed( $old_values, $new_values ) {
if( $old_values['rewrite_url'] != $new_values['rewrite_url'] ) {
flush_rewrite_rules();
//echo "Rewrite rules flushed";
//exit();
}
}
add_action( 'update_option_my_settings', 'my_flush_rules_while_rewrite_changed', 10, 2 );
It's not flushing the rewrite rules. Though I tested without the conditions, and tested that the echo
d text is displayed if used with exit()
. So, I'm sure, the function is being called, but sad part is, it's NOT WORKING.
I thought it's the Rewrite Rules plugin's problem, but the actual rewriting isn't working without saving Permalink changes. So it's actually a problem with my code - it's not working.
But why?
false
, then tried the hard flush. FYI, I added filter topost_type_link
andrewrite_rules_array
like this QA.flush_rewrite_rules
is not flushing rules, but that your new rules aren't present when the flush occurs. I can't verify that without seeing all of your code though. A hard flush will write to .htaccess, so a simple test to see if it's actually flushing is to empty that file and see if it's rebuilt after the flush.if
conditional, have you verified it passes that test in this specific case? This issue is almost always a result of the order in which you are doing things.