Title: Continuous flush_rewrite_rules() causing performance issues
Last modified: October 10, 2025

---

# Continuous flush_rewrite_rules() causing performance issues

 *  Resolved [Duy](https://wordpress.org/support/users/duy1412/)
 * (@duy1412)
 * [8 months ago](https://wordpress.org/support/topic/continuous-flush_rewrite_rules-causing-performance-issues/)
 *     ```wp-block-code
       # 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 DescriptionThe plugin is causing continuous flush_rewrite_rules() calls on every request, leading to severe performance degradation and unnecessary database operations.## Root CauseIn 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>## Impact1. **Performance**: Continuous flush operations on every request2. **Database**: Unnecessary rewrite rules regeneration3. **Cache**: Object cache gets flushed repeatedly4. **User Experience**: Slower page load times, especially on product pages5. **Plugin Conflicts**: Amplifies issues when used with Premmerce Permalink Manager for WooCommerce## Steps to Reproduce1. Install and activate wp-loyalty-rules plugin2. Install and activate Premmerce Permalink Manager for WooCommerce (optional, but amplifies the issue)3. Visit any WooCommerce product page4. Check debug logs - you'll see continuous flush operations5. 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 behaviorphp<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 checkphp<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 activationMove the flush operation to plugin activation hook instead of woocommerce_init.## Temporary WorkaroundUsers 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 InformationIf 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](https://wordpress.org/support/users/akshayathangaraj/)
 * (@akshayathangaraj)
 * [8 months ago](https://wordpress.org/support/topic/continuous-flush_rewrite_rules-causing-performance-issues/#post-18678325)
 * 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](https://wordpress.org/support/users/akshayathangaraj/)
 * (@akshayathangaraj)
 * [8 months ago](https://wordpress.org/support/topic/continuous-flush_rewrite_rules-causing-performance-issues/#post-18678621)
 * 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](https://gist.github.com/alagesanbe08/f1f05ba2484c0e0b094c6aebff7c67b1)**
 * 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
 *  [mikiwal1](https://wordpress.org/support/users/mikiwal1/)
 * (@mikiwal1)
 * [6 months, 1 week ago](https://wordpress.org/support/topic/continuous-flush_rewrite_rules-causing-performance-issues/#post-18736373)
 * [@akshayathangaraj](https://wordpress.org/support/users/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](https://wordpress.org/support/users/haripradeepa/)
 * (@haripradeepa)
 * [6 months, 1 week ago](https://wordpress.org/support/topic/continuous-flush_rewrite_rules-causing-performance-issues/#post-18738861)
 * 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](https://wployalty.net/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)

The topic ‘Continuous flush_rewrite_rules() causing performance issues’ is closed
to new replies.

 * ![](https://ps.w.org/wployalty/assets/icon-128x128.gif?rev=2971238)
 * [Loyalty Points Rewards and Referral for WooCommerce - WPLoyalty](https://wordpress.org/plugins/wployalty/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wployalty/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wployalty/)
 * [Active Topics](https://wordpress.org/support/plugin/wployalty/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wployalty/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wployalty/reviews/)

 * 4 replies
 * 4 participants
 * Last reply from: [haripradeepa](https://wordpress.org/support/users/haripradeepa/)
 * Last activity: [6 months, 1 week ago](https://wordpress.org/support/topic/continuous-flush_rewrite_rules-causing-performance-issues/#post-18738861)
 * Status: resolved