Flushing of the rewrite rules on every page load

Hi @giuse,

Thank you for your detailed feedback. You are absolutely right in noting that flushing rewrite rules on every page load can negatively affect site performance. Flushing rewrite rules is a heavy operation and should only be performed when necessary, such as during plugin activation or deactivation, or at specific times when the rules are actually changed.

Why was flush added on wp_loaded?
I added this call to fix a problem reported by some users on certain types of hosting, where rewrite rules were not being properly updated without this operation. However, this was a temporary solution and it is not optimal to run it on every page load.

Solution Proposed in the next update in a few hours
To improve performance, I plan to change the approach in the next version of the plugin, implementing flushing of rewrite rules only when it is actually needed.

I will implement these changes in the next version of the plugin to improve performance and reduce the impact on sites that use the plugin.

Thanks again for your support and for sharing your feedback!

  • This reply was modified 1 hour, 17 minutes ago by Andrea Ferro.

Thread Starter
Jose

(@giuse)

Thank you very much for your prompt response.

I’m the author of Freesoul Deactivate Plugins.
I’ve opened this thread because a user of FDP has seen a notification given by my plugin about the rewrite rules.
FDP allows the user to specifically disable other plugins on specific pages.
Imagine on the page sample-page you disable plugin A, B, and C, but you keep them active globally.
If those plugins add some rewrite rules, and your plugin flushes the rewrite rules when someone visits sample-page, the new rewrite rules miss those rules added by plugins A, B, and C. The issue is that after they are regenerated by WordPress they will be saved into the database missing some rules.

To avoid this issue, FDP when detects the flushing of the rewrite rules during a normal page load, it calls the homepage behind the scenes enabling all the plugins and saves the rewrite rules, but this time being careful no rule is missed.

This operation consumes server resources. Because your plugin flushes the rewrite rules at every page load, the issue become more serius.
But it would already be a loss of performance without FDP. There is no reason to flush the rewrite rules during a page request. I would do it on plugin activation, or maybe when the user saves the settings of your plugin if you need it, but not on wp_loaded.

It would be great if you can change your code, but of course, I can’t pretend you do it with the next version. I would be very happy, but you are the owner of your time, and you know when you can do it.
I don’t want to stress you.

For me, if you keep your function in the main file, you could just replace the wp_loaded hook with:

register_activation_hook( __FILE__, 'hsts_plugin_flush_rewrite_rules' );

But of course, you know better than everybody else what is better to do in your code.

Thank you in any case for your prompt response.

Have a great day!

Jose

Hi @giuse,

Thank you for your detailed explanation and feedback. I completely understand the problem you pointed out regarding the interaction between plugins and managing rewrite rules.

You are right, flushing rewrite rules on every page load could cause performance issues and conflicts with other plugins that depend on rewrite rules.

Your proposal to move the flush of rewrite rules to plugin activation or settings update is definitely a good idea. This approach would limit the use of server resources and minimize the performance impact during normal page loading.

In response to your request and to ensure better compatibility with FDP and other plugins, I have released the update to the new version 5.0.39 of the plugin early by a few days to change this behavior in the new release. I will remove the hook from wp_loaded and replace it with a more targeted and less frequent approach, probably, indeed definitely using register_activation_hook and register_deactivation_hook.

This change is being tested since I have received initial feedback from some users to ensure that it does not create additional problems or conflicts with other features or plugins.

Thank you again for raising this issue and for your constructive advice. It is through exchanges like this that we can improve our products and the overall user experience.

I wish you a wonderful day and remain available for further comments or suggestions!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer