Continuous flush_rewrite_rules() causing performance issues
-
# 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 continuousflush_rewrite_rules()calls on every request, leading to severe performance degradation and unnecessary database operations.
## Root Cause
InApp/Controllers/Site/MyAccount.php, theaddEndPoints()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>[10-Oct-2025 15:14:41 UTC] [HOOK wp_loaded] priority 10: WP_Rewrite::flush_rules @ /home/runcloud/webapps/cv-wordpress/wp-includes/class-wp-rewrite.php:1873<br><br>[10-Oct-2025 15:14:41 UTC] [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 activation
Move the flush operation to plugin activation hook instead ofwoocommerce_init.
## Temporary Workaround
Users can add this filter to their theme'sfunctions.phpor 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 endpointloyalty_rewardonly 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 intorewrite_rules_arrayfilter
- 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)
Viewing 4 replies - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.