From: Chuck Scott Date: Fri, 17 Jun 2016 19:29:44 +0000 (-0400) Subject: Reworked how we're checking for our rewrite rules and flusing the cache. X-Git-Tag: v2.1.11^2~3^2~4 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=81826e72db385def967822c5c4d2ff8a0c552ad8;p=WP-Plugins%2Fglm-member-db.git Reworked how we're checking for our rewrite rules and flusing the cache. --- diff --git a/setup/frontHooks.php b/setup/frontHooks.php index 6a80ea8b..2b2f9794 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -26,12 +26,24 @@ * Also note that parameters will be in the context of the main front controller constructor. */ -// Setup rewrite for member detail pages -add_filter('rewrite_rules_array', function($rules) { - $newrules = array(); - $newrules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)$'] = 'index.php?pagename=$matches[1]&memberslug=$matches[2]'; - return $newrules + $rules; -}); +// Check if the canonical member page rewrite rule is not currently in place. +$rules = get_option( 'rewrite_rules' ); +if ( ! isset( $rules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)$'] ) ) { + + // Setup rewrite for member detail pages + add_filter('rewrite_rules_array', function($rules) { + $newrules = array(); + $newrules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)$']='index.php?pagename=$matches[1]&memberslug=$matches[2]'; + return $newrules + $rules; + }); + + // Rewrite is not in place, so setup init call to add it and flush the rewrite cache + add_filter('init', function() { + global $wp_rewrite; + $wp_rewrite->flush_rules(); + }); + +} // Add memberslug query var add_filter('query_vars', function($vars) { @@ -39,15 +51,6 @@ add_filter('query_vars', function($vars) { return $vars; }); -// On init, check if we need to flush the rewrite rules to pickup the new ones -add_filter('init', function() { - $rules = get_option( 'rewrite_rules' ); - if ( ! isset( $rules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)$'] ) ) { - global $wp_rewrite; - $wp_rewrite->flush_rules(); - } -}); - // Squash Bread Crumbs if using Breadcrumb NavXT plugin -- NEED TO CREATE A MANAGEMENT OPTION FOR THIS TO TURN IT ON/OFF $plugin_name = 'glm-member-db/glm-member-db.php'; include_once( ABSPATH . 'wp-admin/includes/plugin.php' );