• Saša

    (@stodorovic)


    There is serious performance issue. The method bttk_register_post_types (admin/class-blossomthemes-toolkit-admin.php) calls flush_rewrite_rules on each request:

    /**
     * Register post types.
     *
     * @link http://codex.wordpress.org/Function_Reference/register_post_type
     */
    function bttk_register_post_types() {
    	$myarray = $this->bttk_get_posttype_array();
    	foreach ($myarray as $key => $value) {
    
    		$args = array(
    			// ....
    		);
    		register_post_type( $key, $args );
    		flush_rewrite_rules();
    	}
    }
    

    It’s recommended to do it only if it’s needed:

    This function is useful when used with custom post types as it allows for automatic flushing of the WordPress rewrite rules (usually needs to be done manually for new custom post types). However, this is an expensive operation so it should only be used when necessary.

    Possible solution (eg. WooCoommerce and many other plugins works on same way) is to set some option to 'yes' when plugin has to flush rewrite rules:

    		register_post_type( $key, $args );
    		if ( 'yes' === get_option( 'bttk_queue_flush_rewrite_rules' ) ) {
    			update_option( 'bttk_queue_flush_rewrite_rules', 'no' );
    			flush_rewrite_rules();
    		}
    

    Example: the method activate should set option to 'yes':

    public static function activate() {
    	update_option( 'bttk_queue_flush_rewrite_rules', 'yes' );
    }
    

    Side effect is that .htaccess can be corrupted after some time if there are a lot of concurrent requests which update this file at each request.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘The function flush_rewrite_rules – performance/.htaccess issue’ is closed to new replies.