From: Chuck Scott Date: Fri, 17 Jun 2016 19:31:19 +0000 (-0400) Subject: Reworked how we're checking for our rewrite rules and flusing the cache. X-Git-Tag: v1.1.8^2~16 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=2d40538373ae88372de5b8dccc02ee964d2bb52d;p=WP-Plugins%2Fglm-member-db-packaging.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 d2f77fb..02265ed 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 package detail pages -add_filter('rewrite_rules_array', function($rules) { - $newrules = array(); - $newrules['('.$this->config['settings']['canonical_package_page'].')/([^/]*)$'] = 'index.php?pagename=$matches[1]&packageslug=$matches[2]'; - return $newrules + $rules; -}); +// Check if the canonical package page rewrite rule is not currently in place. +$rules = get_option( 'rewrite_rules' ); +if ( ! isset( $rules['('.$this->config['settings']['canonical_package_page'].')/([^/]*)$'] ) ) { + + // Setup rewrite for member detail pages + add_filter('rewrite_rules_array', function($rules) { + $newrules = array(); + $newrules['('.$this->config['settings']['canonical_package_page'].')/([^/]*)$']='index.php?pagename=$matches[1]&packageslug=$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 package slug 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_package_page'].')/([^/]*)$'] ) ) { - global $wp_rewrite; - $wp_rewrite->flush_rules(); - } -}); - if (isset($this->config['addOns']['glm-member-db'])) { // Add content to member listing page - Get it from the existing package listing shortcode