From: Steve Sutton Date: Wed, 9 Mar 2016 21:27:52 +0000 (-0500) Subject: Setting up rewrite rules X-Git-Tag: v1.0.0^2~175 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=ceef6928cd0a7f00c7c133cf19d0b17966eb38de;p=WP-Plugins%2Fglm-member-db-events.git Setting up rewrite rules --- diff --git a/index.php b/index.php index 822fd64..ce655ef 100644 --- a/index.php +++ b/index.php @@ -144,9 +144,9 @@ if (is_file(GLM_MEMBERS_EVENTS_PLUGIN_DB_SCRIPTS.'/dbVersions.php')) { // Load Events Management Settings data /* None - Need to figure out a smooth way to do this. +*/ $eventsManagementSettings = $wpdb->get_row( "SELECT * FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."management WHERE id = 1", ARRAY_A ); unset($eventsManagementSettings['id']); -*/ function glmMembersRegisterEvents($addOns) { @@ -158,6 +158,7 @@ function glmMembersRegisterEvents($addOns) { 'slug' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG, 'actions' => $GLOBALS['glmMembersEventsAddOnValidActions'], 'config' => array( + 'settings' => $GLOBALS['eventsManagementSettings'] ), 'shortcodes' => $GLOBALS['glmMembersEventsShortcodes'], 'shortcodesDescription' => $GLOBALS['glmMembersEventsShortcodesDescription'] diff --git a/models/front/events/list.php b/models/front/events/list.php index 067ef72..3eb1df4 100644 --- a/models/front/events/list.php +++ b/models/front/events/list.php @@ -32,6 +32,8 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction */ public function modelAction($actionData = false) { + $allEvents = $this->getList(); + //echo '
' . print_r( $allEvents, true ) . '
'; $status = $categoryId = null; $action = ''; $settings = $events = $event = $categoryEvents = array(); diff --git a/setup/frontHooks.php b/setup/frontHooks.php index dbde9c9..f6ca254 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -25,3 +25,26 @@ * * *** 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_event_page'].')/([^/]*)$'] = 'index.php?pagename=$matches[1]&eventId=$matches[2]'; + return $newrules + $rules; +}); + +// Add memberslug query var +add_filter('query_vars', function($vars) { + array_push($vars, 'eventId'); + 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_event_page'].')/([^/]*)$'] ) ) { + global $wp_rewrite; + $wp_rewrite->flush_rules(); + } +}); +