* 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) {
-
- // Check if rule is not set
- if ( ! isset( $rules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)$'] ) ) {
-
- // Add the new rule
- $newrules = array();
- $newrules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)$']='index.php?pagename=$matches[1]&memberslug=$matches[2]';
- return $newrules + $rules;
- }
-
- // If already set, just return the rules unchanged.
- return $rules;
-
+// Setup rewrite for member detail page
+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;
});
-
-/* This code is being replace for testing by the above to avoid intermittent 404's on the detail pages.
-// 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() {
+add_filter( 'query_vars', function($vars) {
+ array_push($vars, 'memberslug');
+ return $vars;
+});
+add_action('wp_loaded', function() {
+ $rules = get_option('rewrite_rules');
+ if ( ! isset( $rules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)$'] ) ) {
+ trigger_error('Doing rewrite flush - Member detail page', E_USER_NOTICE); // Logging that this is happening so we can track when that happens.
global $wp_rewrite;
$wp_rewrite->flush_rules();
- });
-
-}
-*/
+ }
+});
/*
* Add a filter to correct rel_canonical header entries
}, 99, 1);
}
-// Add memberslug query var
-add_filter('query_vars', function($vars) {
- array_push($vars, 'memberslug');
- return $vars;
-});
-
// 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';