Setting up rewrite rules
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 9 Mar 2016 21:27:52 +0000 (16:27 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 9 Mar 2016 21:27:52 +0000 (16:27 -0500)
index.php
models/front/events/list.php
setup/frontHooks.php

index 822fd64..ce655ef 100644 (file)
--- 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']
index 067ef72..3eb1df4 100644 (file)
@@ -32,6 +32,8 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction
      */
     public function modelAction($actionData = false)
     {
+        $allEvents = $this->getList();
+        //echo '<pre>' . print_r( $allEvents, true ) . '</pre>';
         $status = $categoryId = null;
         $action = '';
         $settings = $events = $event = $categoryEvents = array();
index dbde9c9..f6ca254 100644 (file)
  *
  *  *** 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();
+    }
+});
+