Adding a check for eventID before sending emails.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 27 Sep 2016 18:51:56 +0000 (14:51 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 27 Sep 2016 18:51:56 +0000 (14:51 -0400)
Adding if statement to check that there's an $eventID.

models/front/events/frontAdd.php

index daf1e26..2fc2213 100644 (file)
@@ -374,154 +374,156 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
                 );
                 $eventID = $this->wpdb->insert_id;
 
-                $locationData = array(
-                    'event'         => $eventID,
-                    'name'          => $place,
-                    'address'       => $address,
-                    'city'          => $city,
-                    'state'         => $state,
-                    'zip'           => $zip,
-                    'phone'         => $contactPhone,
-                    'contact_fname' => $contactFirst,
-                    'contact_lname' => $contactLast,
-                    'email'         => $contactEmail
-
-                );
-                $locationDataFormat = array(
-                     '%d',
-                     '%s',
-                     '%s',
-                     '%d',
-                     '%s',
-                     '%s',
-                     '%s',
-                     '%s',
-                     '%s',
-                     '%s'
-                );
-                if ($lat && $lon) {
-                    $locationData['lat'] = $lat;
-                    $locationData['lon'] = $lon;
-                    $locationDataFormat[] = '%s';
-                    $locationDataFormat[] = '%s';
-                }
-                $this->wpdb->insert(
-                    GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'locations',
-                    $locationData,
-                     $locationDataFormat
-                );
-                $ending = date("Y-m-d", strtotime($ending));
-                $starting = date("Y-m-d", strtotime($starting));
-                $recurData =array(
-                    'event'             => $eventID,
-                    'start_time'        => $smilitaryTime,
-                    'end_time'          => $emilitaryTime,
-                    'start_date'        => $starting,
-                    'from_date'         => $starting,
-                    'to_date'           => $ending,
-                    'all_day'           => $allDay,
-                    'recurring'         => $repeating,
-                    'day_of_month'      => $dayOfMonth,
-                    'week_of_month'     => $weekOfMonth,
-                    'start_time_only'   => $startTimeOnly,
-                    'month_of_year'     => 4095,
-                    'day_of_week'       => $days,
-                    'by_day_of_month'   => $byDayOfMonth,
-                    'last_day_of_month' => $lastDayOfMonth
-                );
-                $this->wpdb->insert(
-                    GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
-                    $recurData,
-                    array(
-                             '%d',
-                             '%s',
-                             '%s',
-                             '%s',
-                             '%s',
-                             '%s',
-                             '%d',
-                             '%d',
-                             '%d',
-                             '%d',
-                             '%d',
-                             '%d',
-                             '%d',
+                if ( $eventID ) {
+                    $locationData = array(
+                        'event'         => $eventID,
+                        'name'          => $place,
+                        'address'       => $address,
+                        'city'          => $city,
+                        'state'         => $state,
+                        'zip'           => $zip,
+                        'phone'         => $contactPhone,
+                        'contact_fname' => $contactFirst,
+                        'contact_lname' => $contactLast,
+                        'email'         => $contactEmail
+
+                    );
+                    $locationDataFormat = array(
+                         '%d',
+                         '%s',
+                         '%s',
+                         '%d',
+                         '%s',
+                         '%s',
+                         '%s',
+                         '%s',
+                         '%s',
+                         '%s'
+                    );
+                    if ($lat && $lon) {
+                        $locationData['lat'] = $lat;
+                        $locationData['lon'] = $lon;
+                        $locationDataFormat[] = '%s';
+                        $locationDataFormat[] = '%s';
+                    }
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'locations',
+                        $locationData,
+                         $locationDataFormat
+                    );
+                    $ending = date("Y-m-d", strtotime($ending));
+                    $starting = date("Y-m-d", strtotime($starting));
+                    $recurData =array(
+                        'event'             => $eventID,
+                        'start_time'        => $smilitaryTime,
+                        'end_time'          => $emilitaryTime,
+                        'start_date'        => $starting,
+                        'from_date'         => $starting,
+                        'to_date'           => $ending,
+                        'all_day'           => $allDay,
+                        'recurring'         => $repeating,
+                        'day_of_month'      => $dayOfMonth,
+                        'week_of_month'     => $weekOfMonth,
+                        'start_time_only'   => $startTimeOnly,
+                        'month_of_year'     => 4095,
+                        'day_of_week'       => $days,
+                        'by_day_of_month'   => $byDayOfMonth,
+                        'last_day_of_month' => $lastDayOfMonth
+                    );
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
+                        $recurData,
+                        array(
+                                 '%d',
+                                 '%s',
+                                 '%s',
+                                 '%s',
+                                 '%s',
+                                 '%s',
+                                 '%d',
+                                 '%d',
+                                 '%d',
+                                 '%d',
+                                 '%d',
+                                 '%d',
+                                 '%d',
+                                 '%d',
+                                 '%d'
+                            )
+                    );
+                    $recurID = $this->wpdb->insert_id;
+                    $Recurrences->optionIncludeSelectListData = false;
+                    $times = $Recurrences->createRecurrenceTimesEntries($recurID, true, true);
+
+                    // event category data
+                    $categoryData = array(
+                        'event'    => $eventID,
+                        'category' => $category
+                    );
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'event_categories',
+                        $categoryData,
+                        array(
                              '%d',
                              '%d'
                         )
-                );
-                $recurID = $this->wpdb->insert_id;
-                $Recurrences->optionIncludeSelectListData = false;
-                $times = $Recurrences->createRecurrenceTimesEntries($recurID, true, true);
-
-                // event category data
-                $categoryData = array(
-                    'event'    => $eventID,
-                    'category' => $category
-                );
-                $this->wpdb->insert(
-                    GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'event_categories',
-                    $categoryData,
-                    array(
-                         '%d',
-                         '%d'
-                    )
-                );
+                    );
 
-                $smarty = new smartyTemplateSupport();
+                    $smarty = new smartyTemplateSupport();
 
-                $eventsList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-events-index&glm_action=index";
-                $viewPath = GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/views';
-                $smarty->template->setTemplateDir($viewPath);
-                $smarty->templateAssign('eventUrlBase', get_bloginfo('url') . '/add-an-event/');
-                $smarty->templateAssign('title', 'Events');
-                $smarty->templateAssign('to_email', $to_email);
-                $smarty->templateAssign('from_email', $fromEmail);
-                $smarty->templateAssign('emailNotification', $emailNotification);
-                $smarty->templateAssign('pendingEvents', $eventsList);
-                $smarty->templateAssign('name', $name);
-                $smarty->templateAssign('startDate', $starting);
-                $smarty->templateAssign('endDate', $ending);
-                $smarty->templateAssign('startTime', $startTime);
-                $smarty->templateAssign('endTime', $endTime);
+                    $eventsList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-events-index&glm_action=index";
+                    $viewPath = GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/views';
+                    $smarty->template->setTemplateDir($viewPath);
+                    $smarty->templateAssign('eventUrlBase', get_bloginfo('url') . '/add-an-event/');
+                    $smarty->templateAssign('title', 'Events');
+                    $smarty->templateAssign('to_email', $to_email);
+                    $smarty->templateAssign('from_email', $fromEmail);
+                    $smarty->templateAssign('emailNotification', $emailNotification);
+                    $smarty->templateAssign('pendingEvents', $eventsList);
+                    $smarty->templateAssign('name', $name);
+                    $smarty->templateAssign('startDate', $starting);
+                    $smarty->templateAssign('endDate', $ending);
+                    $smarty->templateAssign('startTime', $startTime);
+                    $smarty->templateAssign('endTime', $endTime);
 
 
-                $eventsList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-events-index&glm_action=index";
-                $smarty->templateAssign('items', $events);
+                    $eventsList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-events-index&glm_action=index";
+                    $smarty->templateAssign('items', $events);
 
-                // Add standard parameters
-                require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php';
+                    // Add standard parameters
+                    require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php';
 
-                $viewFile = 'front/events/ownerEmail.html';
+                    $viewFile = 'front/events/ownerEmail.html';
 
-                // Generate output from model data and view
-                $htmlMessage = $smarty->template->fetch($viewFile);
+                    // Generate output from model data and view
+                    $htmlMessage = $smarty->template->fetch($viewFile);
 
-                function set_content_type(){
-                    return "text/html";
-                }
+                    function set_content_type(){
+                        return "text/html";
+                    }
 
-                // change the default wordpress from name when sending mail
-                add_filter('wp_mail_from_name','yoursite_wp_mail_from_name');
-                function yoursite_wp_mail_from_name($name) {
-                    $siteName = get_bloginfo('name');
-                    return $siteName;
-                }
-                // Send confirmation email, set the content type to allow html by using this filter
-                add_filter( 'wp_mail_content_type', 'set_content_type' );
+                    // change the default wordpress from name when sending mail
+                    add_filter('wp_mail_from_name','yoursite_wp_mail_from_name');
+                    function yoursite_wp_mail_from_name($name) {
+                        $siteName = get_bloginfo('name');
+                        return $siteName;
+                    }
+                    // Send confirmation email, set the content type to allow html by using this filter
+                    add_filter( 'wp_mail_content_type', 'set_content_type' );
 
-                $to      = $to_email;
-                $subject = 'Event Form Submission';
-                $message = $htmlMessage;
-                $headers = 'From:' . $fromEmail . "\r\n" .
-                           'Reply-To:' . $contactEmail;
-                $header[] = 'From:' . $fromEmail;
-                $header[] = 'Reply-To:' . $contactEmail;
+                    $to      = $to_email;
+                    $subject = 'Event Form Submission';
+                    $message = $htmlMessage;
+                    $headers = 'From:' . $fromEmail . "\r\n" .
+                               'Reply-To:' . $contactEmail;
+                    $header[] = 'From:' . $fromEmail;
+                    $header[] = 'Reply-To:' . $contactEmail;
 
-                wp_mail($to, $subject, $message, $header);
+                    wp_mail($to, $subject, $message, $header);
 
-                // remove the filter to avoid conflicts
-                remove_filter( 'wp_mail_content_type', 'set_content_type' );
+                    // remove the filter to avoid conflicts
+                    remove_filter( 'wp_mail_content_type', 'set_content_type' );
+                }
 
                 $view = 'confirmation';
             }