• Resolved Duy

    (@duy1412)


    # Bug Report: Continuous flush_rewrite_rules() causing performance issues

    ## Plugin Information

    - **Plugin Name**: WP Loyalty Rules (wp-loyalty-rules)

    - **Plugin Version**: Latest version (as of October 2025)

    - **WordPress Version**: 6.x

    - **WooCommerce Version**: Latest

    - **Related Plugin**: Premmerce Permalink Manager for WooCommerce (woo-permalink-manager)

    ## Issue Description

    The plugin is causing continuous
    flush_rewrite_rules() calls on every request, leading to severe performance degradation and unnecessary database operations.

    ## Root Cause

    In App/Controllers/Site/MyAccount.php, the addEndPoints() method has been changed from:

    **Previous version (working):**

    php<br><br>$status = apply_filters( 'wlr_flush_rewrite_rules', false );<br><br>if ( $status ) {<br><br>flush_rewrite_rules();<br><br>}<br><br>

    **Current version (problematic):**

    php<br><br>$status = apply_filters( 'wlr_flush_rewrite_rules', true );<br><br>if ( $status ) {<br><br>flush_rewrite_rules();<br><br>}<br><br>

    ## Impact

    1. **Performance**: Continuous flush operations on every request

    2. **Database**: Unnecessary rewrite rules regeneration

    3. **Cache**: Object cache gets flushed repeatedly

    4. **User Experience**: Slower page load times, especially on product pages

    5. **Plugin Conflicts**: Amplifies issues when used with Premmerce Permalink Manager for WooCommerce

    ## Steps to Reproduce

    1. Install and activate wp-loyalty-rules plugin

    2. Install and activate Premmerce Permalink Manager for WooCommerce (optional, but amplifies the issue)

    3. Visit any WooCommerce product page

    4. Check debug logs - you'll see continuous flush operations

    5. Monitor server performance - CPU usage increases significantly

    ## Debug Log Evidence

    <br><br>&#091;10-Oct-2025 15:14:41 UTC] &#091;HOOK wp_loaded] priority 10: WP_Rewrite::flush_rules @ /home/runcloud/webapps/cv-wordpress/wp-includes/class-wp-rewrite.php:1873<br><br>&#091;10-Oct-2025 15:14:41 UTC] &#091;REWRITE FILTER] require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('wp_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Rewrite->flush_rules, WP_Rewrite->refresh_rewrite_rules, WP_Rewrite->rewrite_rules, apply_filters('rewrite_rules_array')<br><br>

    ## Suggested Fix

    ### Option 1: Revert to previous behavior

    php<br><br>$status = apply_filters( 'wlr_flush_rewrite_rules', false );<br><br>if ( $status ) {<br><br>flush_rewrite_rules();<br><br>}<br><br>

    ### Option 2: Add endpoint existence check

    php<br><br>public <em>function</em> addEndPoints() {<br><br>if ( <em>self</em>::$woocommerce->isBannedUser()<br><br>|| ! apply_filters( 'wlr_before_adding_menu_endpoint', true )<br><br>) {<br><br>return;<br><br>}<br><br>// Check if endpoint already exists<br><br>if (!get_option('wlr_loyalty_reward_endpoint_added')) {<br><br>$status = apply_filters( 'wlr_flush_rewrite_rules', true );<br><br>if ( $status ) {<br><br>flush_rewrite_rules();<br><br>update_option('wlr_loyalty_reward_endpoint_added', true);<br><br>}<br><br>}<br><br>add_rewrite_endpoint( 'loyalty_reward', EP_ROOT | EP_PAGES );<br><br>}<br><br>

    ### Option 3: Only flush on plugin activation

    Move the flush operation to plugin activation hook instead of woocommerce_init.

    ## Temporary Workaround

    Users can add this filter to their theme's functions.php or a MU plugin:

    php<br><br>add_filter('wlr_flush_rewrite_rules', '__return_false');<br><br>

    ## Additional Information

    - The issue affects all sites using the plugin

    - Performance impact is more noticeable on high-traffic sites

    - The endpoint loyalty_reward only needs to be added once, not on every request

    - **Plugin Conflict**: When used with Premmerce Permalink Manager for WooCommerce, the issue is amplified because:

    - Premmerce Permalink Manager hooks into rewrite_rules_array filter

    - Each flush triggers the Premmerce filter, causing additional processing

    - The combination creates a cascade effect of rewrite rule regeneration

    ## Contact Information

    If you need additional debugging information or access to a test site, please let me know.

    ---

    **Priority**: High (Performance Impact)

    **Severity**: Critical (Affects site performance)
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support akshayathangaraj

    (@akshayathangaraj)

    Hi,

    Thanks for reaching out. This is Akshaya from WPLoyalty Support Team.

    I’ve received your message and will get back to you shortly after reviewing the details.

    Regards,

    WPLoyalty support team.

    Plugin Support akshayathangaraj

    (@akshayathangaraj)

    Hi,

    Thanks again for your detailed report and the analysis — we really appreciate the time you took to outline the issue so clearly.

    As a follow-up:
    We’ve enabled the rewrite rule flush by default to ensure endpoints are registered correctly out of the box. However, if you’d prefer to disable the automatic flush_rewrite_rules() behavior, you can use the following snippet as a workaround:

    🔗 Disable flush_rewrite_rules Gist

    This will allow you to control when rewrite rules are flushed and help avoid unnecessary operations on every request.

    Let us know if this resolves the issue on your end!

    Regards,

    WPLoyalty support team

    @akshayathangaraj is it ok to use the plugin with flush disabled?

    it cannot be enabled caused very long loading Times.

    Will it work with the snippet?

    Plugin Support haripradeepa

    (@haripradeepa)

    Hi,
    Thank you for reaching out!

    To investigate this further and explore possible solutions, could you please submit a support ticket on our website at WPLoyalty Support?

    This will help us analyze the situation more effectively and provide you with the best possible solution. Looking forward to your response!

    Regards,
    WPLoyalty support team.

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.