From 386a4f037d8dda8abd8a5766d8eac2473d41dc75 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Fri, 14 Apr 2017 16:06:18 -0400 Subject: [PATCH] Cleaning up some issues with rewrites. --- setup/frontHooks.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) 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(); + } } }); -- 2.17.1