Setting up notice for new members
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 25 Apr 2018 20:39:14 +0000 (16:39 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 25 Apr 2018 20:39:14 +0000 (16:39 -0400)
Setup on front end sign up form.

classes/notifications.php
config/plugin.ini
models/admin/ajax/billingFlagExpiredUsers.php
models/admin/ajax/billingRunQueue.php
models/admin/ajax/billingSetupQueue.php
models/front/billing/becomeMember.php
setup/adminHooks.php
views/front/billing/becomeMember.html

index dcfa912..e23be30 100644 (file)
@@ -255,15 +255,14 @@ class GlmNotifications
      */
     public function getNotificationsByType( $type )
     {
-        return $this->wpdb->get_results(
+        return $this->wpdb->get_var(
             $this->wpdb->prepare(
                 "SELECT id
                    FROM "  . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX .  "notification_types
                   WHERE send_by_action
                     AND send_action = %d",
                 $this->config['send_action_numb'][$type]
-            ),
-            ARRAY_A
+            )
         );
     }
 
@@ -361,7 +360,8 @@ class GlmNotifications
                 "SELECT id
                    FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notification_queue
                   WHERE notification_type = %d
-                    AND account = %d",
+                    AND account = %d
+                    AND processed_time IS NULL",
                 $notification_type,
                 $account
             )
@@ -371,11 +371,13 @@ class GlmNotifications
                 GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'notification_queue',
                 array(
                     'notification_type' => $notification_type,
-                    'account'           => $account
+                    'account'           => $account,
+                    'queued_time'       => date('Y-m-d H:i:s')
                 ),
                 array(
                     '%d',
-                    '%d'
+                    '%d',
+                    '%s'
                 )
             );
         }
@@ -392,14 +394,14 @@ class GlmNotifications
      * @access public
      * @return array
      */
-    public function getQueuedNotifications( $limit )
+    public function getQueuedNotifications( $limit = null )
     {
         $query =
         "SELECT *
            FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notification_queue";
-        //$query = " WHERE processed_time IS NULL";
+        $query .= " WHERE processed_time IS NULL";
         if ( $numb = filter_var( $limit, FILTER_VALIDATE_INT ) ) {
-            $query .= " LIMIT $limit OFFSET 0";
+            $query .= " LIMIT $numb OFFSET 0";
         }
         return $this->wpdb->get_results(
             $query,
@@ -421,7 +423,7 @@ class GlmNotifications
     {
         $this->wpdb->update(
             GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'notification_queue',
-            array( 'processed_time' => date( 'Y-m-d' ) ),
+            array( 'processed_time' => date( 'Y-m-d H:i:s' ) ),
             array( 'id' => $queue_id ),
             array( '%s' ),
             array( '%d' )
index 90f2589..da0cffa 100644 (file)
@@ -37,9 +37,11 @@ send_date_period[40] = "Year"
 ; Send Action
 send_action[10] = "Create Invoice"
 send_action[20] = "Received Payment"
+send_action[30] = "New Member"
 
 send_action_numb['Create Invoice']   = 10;
 send_action_numb['Received Payment'] = 20;
+send_action_numb['New Member']       = 30;
 
 ; Send Date When
 send_date_when[10] = "Before"
index d9f79cb..7593c40 100644 (file)
@@ -92,6 +92,5 @@ class GlmMembersAdmin_ajax_billingFlagExpiredUsers
             );
         }
 
-        wp_die();
     }
 }
index c77a936..a53ec13 100644 (file)
@@ -74,6 +74,7 @@ class GlmMembersAdmin_ajax_billingRunQueue
         // Get the queue and send notices.
         $queued = $Notifications->getQueuedNotifications();
         echo '<pre>$queued: ' . print_r( $queued, true ) . '</pre>';
+        // return false;
         if ( isset( $queued ) && !empty( $queued ) ) {
             foreach ( $queued as $queue ) {
                 $Notifications->sendEmailNotification( $queue['notification_type'], $queue['account'] );
@@ -81,6 +82,5 @@ class GlmMembersAdmin_ajax_billingRunQueue
                 // $Notifications->deleteQueue( $queue['id'] );
             }
         }
-        wp_die();
     }
 }
index 13f1dda..a4d1374 100644 (file)
@@ -89,6 +89,7 @@ class GlmMembersAdmin_ajax_billingSetupQueue
             }
             $accounts = $billingSupport->getAccountsRenewing( $notice['send_date_number'], $before );
             echo '<pre>$accounts: ' . print_r( $accounts, true ) . '</pre>';
+            // return false;
             if ( isset( $accounts ) && is_array( $accounts ) && !empty( $accounts ) ) {
                 foreach ( $accounts as $account ) {
                     $Notifications->queueNotice( $notice['id'], $account['id'] );
@@ -96,6 +97,5 @@ class GlmMembersAdmin_ajax_billingSetupQueue
             }
         }
 
-        wp_die();
     }
 }
index 9e3f46c..b01821f 100644 (file)
@@ -15,6 +15,7 @@
 define('GLM_MEMBERS_BILLING_MEMBER_MENU', true);
 require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataInvoices.php';
 require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/billingSupport.php';
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/notifications.php';
 
 class GlmMembersFront_billing_becomeMember // extends GlmDataBilling
 {
@@ -115,14 +116,14 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling
 
         case 'newMembership':
             $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
-            $messages[] = '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+            // $messages[] = '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
             // Need to see if the email address they're using is already setup as a contact.
             // If it is then we need to give a message about it and not let them sign up again.
 
             $email_to_check = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL );
-            $messages[] = '<pre>$email_to_check: ' . print_r( $email_to_check, true ) . '</pre>';
+            // $messages[] = '<pre>$email_to_check: ' . print_r( $email_to_check, true ) . '</pre>';
             $verify_email   = filter_var( $_REQUEST['email_verify'], FILTER_VALIDATE_EMAIL );
-            $messages[] = '<pre>$verify_email: ' . print_r( $verify_email, true ) . '</pre>';
+            // $messages[] = '<pre>$verify_email: ' . print_r( $verify_email, true ) . '</pre>';
             if ( !$email_to_check ) {
                 $error = true;
                 $messages[] = $errors['email'] = "<span style='color: red;'>Not a valid Email!</span>";
@@ -323,11 +324,15 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling
                     'role'       => $wpRole
                 )
             );
+            // echo '<pre>$wpUserID: ' . print_r( $wpUserID, true ) . '</pre>';
             if (is_int($wpUserID) && $wpUserID > 0) {
                 // Store the contact ID and active status into user meta data.
                 update_user_meta($wpUserID, 'glmMembersContactID', $newContactID);
                 update_user_meta($wpUserID, 'glmMembersContactActive', true);
                 // echo '<pre>$wpUserID: ' . print_r( $wpUserID, true ) . '</pre>';
+            } else if ( is_wp_error( $wpUserID ) ) {
+                $error = true;
+                $messages[''] = $errors['username'] = '<span style="color:red;">An error occurred! ' . $wpUserID->get_error_message() . '</span>';
             } else {
                 $error = true;
                 $messages[] = '<span style="color:red;">An error occurred! wpUserID</span>';
@@ -454,6 +459,14 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling
                 } else {
                     $invoiceHtml = $BillingSupport->viewInvoice( $invoice_id );
                     $view = 'thankyou';
+                    // Send admin user email notification of new member
+
+                    // Check for any notices for new members and send them out for this new member.
+                    $Notification = new GlmNotifications( $this->wpdb, $this->config );
+                    $notification = $Notification->getNotificationsByType( 'New Member' );
+                    if ( $notification ) {
+                        $Notification->sendEmailNotification( $notification, $accountID );
+                    }
                 }
             }
             break;
index 07c3e08..83666c0 100644 (file)
@@ -34,50 +34,50 @@ add_filter(
     1
 );
 
-// add_filter(
-//     'glm_associate_cron_request',
-//     function( $cron_task ){
-//         $new_cron = array(
-//             array(
-//                 'menu'       => 'ajax',
-//                 'action'     => 'billingFlagExpiredUsers',
-//                 'daysOfWeek' => range( 1, 7 ),
-//                 'times'      => range( 1, 24 ),
-//                 'params'     => array()
-//             )
-//         );
-//         return array_merge( $cron_task, $new_cron );
-//     }
-// );
+add_filter(
+    'glm_associate_cron_request',
+    function( $cron_task ){
+        $new_cron = array(
+            array(
+                'menu'       => 'ajax',
+                'action'     => 'billingFlagExpiredUsers',
+                'daysOfWeek' => range( 1, 7 ),
+                'times'      => range( 1, 24 ),
+                'params'     => array()
+            )
+        );
+        return array_merge( $cron_task, $new_cron );
+    }
+);
 
-// add_filter(
-//     'glm_associate_cron_request',
-//     function( $cron_task ) {
-//         $new_cron = array(
-//             array(
-//                 'menu'       => 'ajax',
-//                 'action'     => 'billingSetupQueue',
-//                 'daysOfWeek' => range( 1, 7 ),
-//                 'times'      => range( 1, 24 ),
-//                 'params'     => array()
-//             )
-//         );
-//         return array_merge( $cron_task, $new_cron );
-//     }
-// );
+add_filter(
+    'glm_associate_cron_request',
+    function( $cron_task ) {
+        $new_cron = array(
+            array(
+                'menu'       => 'ajax',
+                'action'     => 'billingSetupQueue',
+                'daysOfWeek' => range( 1, 7 ),
+                'times'      => range( 3 ),
+                'params'     => array()
+            )
+        );
+        return array_merge( $cron_task, $new_cron );
+    }
+);
 
-// add_filter(
-//     'glm_associate_cron_request',
-//     function( $cron_task ) {
-//         $new_cron = array(
-//             array(
-//                 'menu'       => 'ajax',
-//                 'action'     => 'billingRunQueue',
-//                 'daysOfWeek' => range( 1, 7 ),
-//                 'times'      => range( 1, 24 ),
-//                 'params'     => array()
-//             )
-//         );
-//         return array_merge( $cron_task, $new_cron );
-//     }
-// );
+add_filter(
+    'glm_associate_cron_request',
+    function( $cron_task ) {
+        $new_cron = array(
+            array(
+                'menu'       => 'ajax',
+                'action'     => 'billingRunQueue',
+                'daysOfWeek' => range( 1, 7 ),
+                'times'      => range( 4 ),
+                'params'     => array()
+            )
+        );
+        return array_merge( $cron_task, $new_cron );
+    }
+);
index f1b4cfe..ea1897e 100644 (file)
                 required />
             </div>
         </div>
+        {if $errors.username}<div>{$errors.username}</div>{/if}
         <div>
             The password must be at least 8 characters and include at least one number, one letter, and at least one special character. (# . - _ , $ % & !)
         </div>