I’ve created a plugin that, for its correct operation, provides a rewrite rule, a rewrite tag and a rewrite endpoint. At first I used to be including the foundations on the entry level of the plugin, the principle class that calls all different information/provides lessons, and so forth… I used to be not flushing the rewrite guidelines at that time.
Then, within the register_activation_hook()
operate that runs solely as soon as, through the plugin’s activation, the place I am additionally altering the get_option('woocommerce_permalinks')['product_base']
I am flushing the rewrite guidelines there.
The issue arose earlier at the moment once I needed to briefly deactivate/reactivate the plugin, that I seen that two customized pages for which I had written the rewrite rule have been inaccessible (returned a 404)… With the assistance of a specialised plugin, I inspected the rewrite guidelines, which reported that two (those I am including at my plugin’s predominant class) had expired…
So I additionally added a flush_rewrite_rules()
after the definition of the rewrite guidelines/tag/endpoint, and did a check deactivation/reactivation of my plugin, and the issue was gone.
However then I learn that flush_rewrite_rules()
is an costly operation, and may solely be used when mandatory so calling it light-heartily at each web page load, the place my plugin known as is a foul concept.
So my query is that this: What is the correct manner of coping with this case? The place is the correct place so as to add these rewrite guidelines? And may I be calling flush_rewrite_rules()
in my plugin’s predominant class that is referred to as on each web page load of WP?