Calling “flush_rewrite_rules” on every page load
-
Hi,
In the
includes/Manager/TemplateRedirection.phpfile of the plugin, on line 43 the following action is being added:add_action( 'init', array( $this, 'kirki_utility_pages_rewrite_rules' ) );This action calls the following function:
public function kirki_utility_pages_rewrite_rules() {
$utility_pages = Page::fetch_list('kirki_utility', true, array( 'publish' ) );
foreach ( $utility_pages as $key => $page ) {
$utility_page_type = $page['utility_page_type'];
$id = $page['id'];
$slug = $page['slug'];
if ( $utility_page_type !== '404' ) {
// Add custom rewrite rule for login
add_rewrite_rule( "^$slug$", "index.php?kirki_utility_page_type=$utility_page_type&kirki_utility_page_id=$id", 'top' );
}
}
flush_rewrite_rules( true );
}This means the
flush_rewrite_rulesfunction is being called on every page load (line 115 of the file). Along with thetrueargument provided to the function, this causes a hard refresh which forces the.htaccessfile to be rewritten on every page load.As per the WordPress Developer Resources, this operation can be extremely costly in terms of performance and should be called sparingly. Every attempt should be made to avoid using it in hooks that execute on each page load, such as init.
Additionally, this has created a conflict with WPML which is sensitive to repeated
.htaccessrewrites.Could you please review this code to see if it would be possible in a future update to avoid doing this flush on every page load?
Regards,
You must be logged in to reply to this topic.