• Resolved Jose

    (@giuse)


    Hello

    In the main file of the plugin I see this line:

    add_action('wp_loaded', 'hsts_plugin_flush_rewrite_rules');

    Here the function that is called at every page load:

    function hsts_plugin_flush_rewrite_rules(): void {
    global $wp_rewrite;
    if ( $wp_rewrite instanceof WP_Rewrite ) {
    $wp_rewrite->flush_rules();
    }
    }

    This means every time you visit a page the flushes the rewrite rules. This is a big loss in terms of performance.
    Why are you doing that without any conditions? Is it a way to flush the rewrite rules only when you need it? For example on plugin activation?

    Thank you.

    Have a great day!
    Jose

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Andrea Ferro

    (@unicorn03)

    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 2 months, 4 weeks 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

    Plugin Author Andrea Ferro

    (@unicorn03)

    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!

    Thread Starter Jose

    (@giuse)

    Hi @unicorn03

    thank you so much for being so collaborative and fast. It was really a pleasure to open this thread and seeing solved after a few minutes.

    I wish you all the best for your plugin and have a wonderful day too!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.