Update for event detail pages for active events only.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 27 Apr 2018 15:20:24 +0000 (11:20 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 27 Apr 2018 15:20:24 +0000 (11:20 -0400)
If anything but active give 404 page.

setup/frontHooks.php

index 6e823fc..bc797a2 100644 (file)
@@ -81,11 +81,30 @@ if (strpos(GLM_MEMBERS_PLUGIN_CURRENT_URL, '/'.$this->config['settings']['canoni
     // Get the event name for use in the page title
     global $wpdb;
     $eventData = $wpdb->get_row(
-        "SELECT name,intro
+        "SELECT name,intro,status
            FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events
-          WHERE name_slug = '".$GLOBALS['glmDetailSlug']."'",
+          WHERE name_slug = '".$GLOBALS['glmDetailSlug']."'
+            AND status = " . $this->config['status_numb']['Active'] . "",
         ARRAY_A
     );
+     if ( ! $eventData ) {
+        // If the eventData is not found then create 404
+        function glm_throw_404(){
+            global $wp_query;
+            $wp_query->set_404();
+            status_header( 404 );
+            nocache_headers();
+            add_filter('wp_title', function($title) {
+                return 'Error 404 - Not Found!';
+            }, 99, 1);
+            $template404 = get_404_template();
+            if ( $template404 ) {
+                require $template404;
+            }
+            exit;
+        }
+        add_action('wp', 'glm_throw_404');
+    }
     $GLOBALS['glmEventName']  = $eventData['name'];
     $GLOBALS['glmEventIntro'] = $eventData['intro'];
 
@@ -203,7 +222,7 @@ if (isset($this->config['addOns']['glm-member-db'])) {
         10,
         2
     );
-        
+
     // Add content to member detail page - Get it from the existing event listing shortcode
     // Unlike the filters above this one is not listed by default on the member detail page
     //  but can be applied to custom member db view files if they remove any "descriptionAfter"