send_approval_notification( $user_id ); } elseif ( $new_status === HVAC_Trainer_Status::STATUS_DISABLED ) { $this->send_disabled_notification( $user_id ); } } /** * Send new registration notification to admins * * @param int $user_id User ID * @param array $registration_data Registration form data */ public function send_new_registration_notification( $user_id, $registration_data ) { $user = get_userdata( $user_id ); if ( ! $user ) { return false; } // Get notification emails $options = get_option( 'hvac_ce_options', array() ); $notification_emails = isset( $options['notification_emails'] ) ? $options['notification_emails'] : get_option( 'admin_email' ); // Convert comma-separated list to array if ( is_string( $notification_emails ) ) { $notification_emails = array_map( 'trim', explode( ',', $notification_emails ) ); } // Generate approval token $approval_token = $this->generate_approval_token( $user_id ); update_user_meta( $user_id, 'hvac_approval_token', $approval_token ); // Build approval URL $approval_url = add_query_arg( array( 'hvac_approve_trainer' => $user_id, 'hvac_approval_token' => $approval_token, ), home_url( '/master-trainer/dashboard/' ) ); // Get email template $template = $this->get_email_template( 'new_registration' ); // Replace placeholders $replacements = array( '{trainer_name}' => $user->display_name, '{trainer_email}' => $user->user_email, '{business_name}' => get_user_meta( $user_id, 'business_name', true ), '{business_phone}' => get_user_meta( $user_id, 'business_phone', true ), '{business_email}' => get_user_meta( $user_id, 'business_email', true ), '{registration_date}' => date( 'F j, Y', strtotime( $user->user_registered ) ), '{application_details}' => get_user_meta( $user_id, 'application_details', true ), '{approval_url}' => $approval_url, '{website_name}' => get_bloginfo( 'name' ), '{website_url}' => home_url(), ); $subject = str_replace( array_keys( $replacements ), array_values( $replacements ), $template['subject'] ); $message = str_replace( array_keys( $replacements ), array_values( $replacements ), $template['body'] ); // Send emails $headers = array( 'Content-Type: text/html; charset=UTF-8' ); foreach ( $notification_emails as $email ) { wp_mail( $email, $subject, $message, $headers ); } return true; } /** * Send approval notification to trainer * * @param int $user_id User ID */ public function send_approval_notification( $user_id ) { $user = get_userdata( $user_id ); if ( ! $user ) { return false; } // Get email template $template = $this->get_email_template( 'account_approved' ); // Replace placeholders $replacements = array( '{trainer_name}' => $user->display_name, '{trainer_email}' => $user->user_email, '{business_name}' => get_user_meta( $user_id, 'business_name', true ), '{dashboard_url}' => home_url( '/trainer/dashboard/' ), '{login_url}' => home_url( '/community-login/' ), '{website_name}' => get_bloginfo( 'name' ), '{website_url}' => home_url(), '{current_date}' => date( 'F j, Y' ), ); $subject = str_replace( array_keys( $replacements ), array_values( $replacements ), $template['subject'] ); $message = str_replace( array_keys( $replacements ), array_values( $replacements ), $template['body'] ); // Send email $headers = array( 'Content-Type: text/html; charset=UTF-8' ); return wp_mail( $user->user_email, $subject, $message, $headers ); } /** * Send disabled notification to trainer * * @param int $user_id User ID */ public function send_disabled_notification( $user_id ) { $user = get_userdata( $user_id ); if ( ! $user ) { return false; } // Get email template $template = $this->get_email_template( 'account_disabled' ); // Replace placeholders $replacements = array( '{trainer_name}' => $user->display_name, '{trainer_email}' => $user->user_email, '{business_name}' => get_user_meta( $user_id, 'business_name', true ), '{support_email}' => get_option( 'admin_email' ), '{website_name}' => get_bloginfo( 'name' ), '{website_url}' => home_url(), '{current_date}' => date( 'F j, Y' ), ); $subject = str_replace( array_keys( $replacements ), array_values( $replacements ), $template['subject'] ); $message = str_replace( array_keys( $replacements ), array_values( $replacements ), $template['body'] ); // Send email $headers = array( 'Content-Type: text/html; charset=UTF-8' ); return wp_mail( $user->user_email, $subject, $message, $headers ); } /** * Get email template * * @param string $template_key Template key * @return array Template data with subject and body */ private function get_email_template( $template_key ) { $options = get_option( 'hvac_ce_email_templates', array() ); // Default templates $defaults = array( 'new_registration' => array( 'subject' => 'New HVAC Trainer Registration - {trainer_name}', 'body' => '
A new HVAC trainer has registered and is awaiting approval.
{application_details}
Or copy this link: {approval_url}
', ), 'account_approved' => array( 'subject' => 'Your HVAC Trainer Account Has Been Approved!', 'body' => 'Dear {trainer_name},
Great news! Your HVAC trainer account has been approved and you now have full access to create and manage training events.
If you have any questions or need assistance, please don\'t hesitate to reach out to our support team.
We\'re excited to have you as part of our training community!
Best regards,
                    The {website_name} Team
Dear {trainer_name},
We regret to inform you that your HVAC trainer account on {website_name} has been disabled.
Your account may have been disabled for one of the following reasons:
If you believe this action was taken in error or would like to discuss reactivating your account, please contact our support team at {support_email}.
We appreciate your understanding.
Sincerely,
                    The {website_name} Team