From c8aa4b317c6329724a95a4b014c805a93bb07763 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 25 Apr 2018 16:39:14 -0400 Subject: [PATCH] Setting up notice for new members Setup on front end sign up form. --- classes/notifications.php | 22 ++--- config/plugin.ini | 2 + models/admin/ajax/billingFlagExpiredUsers.php | 1 - models/admin/ajax/billingRunQueue.php | 2 +- models/admin/ajax/billingSetupQueue.php | 2 +- models/front/billing/becomeMember.php | 19 +++- setup/adminHooks.php | 90 +++++++++---------- views/front/billing/becomeMember.html | 1 + 8 files changed, 78 insertions(+), 61 deletions(-) diff --git a/classes/notifications.php b/classes/notifications.php index dcfa912..e23be30 100644 --- a/classes/notifications.php +++ b/classes/notifications.php @@ -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' ) diff --git a/config/plugin.ini b/config/plugin.ini index 90f2589..da0cffa 100644 --- a/config/plugin.ini +++ b/config/plugin.ini @@ -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" diff --git a/models/admin/ajax/billingFlagExpiredUsers.php b/models/admin/ajax/billingFlagExpiredUsers.php index d9f79cb..7593c40 100644 --- a/models/admin/ajax/billingFlagExpiredUsers.php +++ b/models/admin/ajax/billingFlagExpiredUsers.php @@ -92,6 +92,5 @@ class GlmMembersAdmin_ajax_billingFlagExpiredUsers ); } - wp_die(); } } diff --git a/models/admin/ajax/billingRunQueue.php b/models/admin/ajax/billingRunQueue.php index c77a936..a53ec13 100644 --- a/models/admin/ajax/billingRunQueue.php +++ b/models/admin/ajax/billingRunQueue.php @@ -74,6 +74,7 @@ class GlmMembersAdmin_ajax_billingRunQueue // Get the queue and send notices. $queued = $Notifications->getQueuedNotifications(); echo '
$queued: ' . print_r( $queued, true ) . '
'; + // 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(); } } diff --git a/models/admin/ajax/billingSetupQueue.php b/models/admin/ajax/billingSetupQueue.php index 13f1dda..a4d1374 100644 --- a/models/admin/ajax/billingSetupQueue.php +++ b/models/admin/ajax/billingSetupQueue.php @@ -89,6 +89,7 @@ class GlmMembersAdmin_ajax_billingSetupQueue } $accounts = $billingSupport->getAccountsRenewing( $notice['send_date_number'], $before ); echo '
$accounts: ' . print_r( $accounts, true ) . '
'; + // 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(); } } diff --git a/models/front/billing/becomeMember.php b/models/front/billing/becomeMember.php index 9e3f46c..b01821f 100644 --- a/models/front/billing/becomeMember.php +++ b/models/front/billing/becomeMember.php @@ -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[] = '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + // $messages[] = '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; // 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[] = '
$email_to_check: ' . print_r( $email_to_check, true ) . '
'; + // $messages[] = '
$email_to_check: ' . print_r( $email_to_check, true ) . '
'; $verify_email = filter_var( $_REQUEST['email_verify'], FILTER_VALIDATE_EMAIL ); - $messages[] = '
$verify_email: ' . print_r( $verify_email, true ) . '
'; + // $messages[] = '
$verify_email: ' . print_r( $verify_email, true ) . '
'; if ( !$email_to_check ) { $error = true; $messages[] = $errors['email'] = "Not a valid Email!"; @@ -323,11 +324,15 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling 'role' => $wpRole ) ); + // echo '
$wpUserID: ' . print_r( $wpUserID, true ) . '
'; 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 '
$wpUserID: ' . print_r( $wpUserID, true ) . '
'; + } else if ( is_wp_error( $wpUserID ) ) { + $error = true; + $messages[''] = $errors['username'] = 'An error occurred! ' . $wpUserID->get_error_message() . ''; } else { $error = true; $messages[] = 'An error occurred! wpUserID'; @@ -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; diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 07c3e08..83666c0 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -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 ); + } +); diff --git a/views/front/billing/becomeMember.html b/views/front/billing/becomeMember.html index f1b4cfe..ea1897e 100644 --- a/views/front/billing/becomeMember.html +++ b/views/front/billing/becomeMember.html @@ -265,6 +265,7 @@ required /> + {if $errors.username}
{$errors.username}
{/if}
The password must be at least 8 characters and include at least one number, one letter, and at least one special character. (# . - _ , $ % & !)
-- 2.17.1