From: Chuck Scott Date: Fri, 14 Apr 2017 20:06:18 +0000 (-0400) Subject: Cleaning up some issues with rewrites. X-Git-Tag: v1.2.10^2~2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=386a4f037d8dda8abd8a5766d8eac2473d41dc75;p=WP-Plugins%2Fglm-member-db-packaging.git Cleaning up some issues with rewrites. --- diff --git a/setup/frontHooks.php b/setup/frontHooks.php index bcc1f19..d0791ac 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -26,11 +26,11 @@ * *** Also note that parameters will be in the context of the main front controller constructor. *** */ - // Setup rewrite for package detail page +define( 'GLM_PACKAGING_REWRITE_RULE', '('.$this->config['settings']['canonical_package_page'].')/([^/]*)$'); add_filter( 'rewrite_rules_array', function($rules) { $newrules = array(); - $newrules['('.$this->config['settings']['canonical_package_page'].')/([^/]*)$']='index.php?pagename=$matches[1]&packageslug=$matches[2]'; + $newrules[GLM_PACKAGING_REWRITE_RULE]='index.php?pagename=$matches[1]&packageslug=$matches[2]'; return $newrules + $rules; }); add_filter( 'query_vars', function($vars) { @@ -38,11 +38,14 @@ add_filter( 'query_vars', function($vars) { return $vars; }); add_action('wp_loaded', function() { - $rules = get_option('rewrite_rules'); - if ( ! isset( $rules['('.$this->config['settings']['canonical_package_page'].')/([^/]*)$'] ) ) { - trigger_error('Doing rewrite flush - Package detail page', E_USER_NOTICE); // Logging that this is happening so we can track when that happens. - global $wp_rewrite; - $wp_rewrite->flush_rules(); + // Only do this if this is a front-end request + if (!is_admin()) { + $rules = get_option('rewrite_rules'); + if ( ! isset( $rules[GLM_PACKAGING_REWRITE_RULE] ) ) { + trigger_error('Doing rewrite flush - Package detail page', E_USER_NOTICE); // Logging that this is happening so we can track when that happens. + global $wp_rewrite; + $wp_rewrite->flush_rules(); + } } });