From a3f1bcb0ef7bba2e004cb85f39493922edd7b5a0 Mon Sep 17 00:00:00 2001 From: Ruben Ramirez Date: Fri, 4 Apr 2025 05:46:46 -0500 Subject: [PATCH] Fix: Use correct token value for invitation email link --- functions.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/functions.php b/functions.php index ece3717..863ff55 100644 --- a/functions.php +++ b/functions.php @@ -205,13 +205,18 @@ function quiztech_ajax_send_job_invite() { } elseif ( $result === false ) { // Generic failure from create_invitation if no WP_Error wp_send_json_error( [ 'message' => esc_html__( 'Failed to create invitation.', 'quiztech' ) ], 500 ); - } else { - // Success! $result contains the token. Now send the email. - $token = $result; - $email_sent = $invitations->send_invitation_email( $applicant_email, $token, [ 'job_title' => get_the_title( $job_id ) ] ); + } elseif ( !is_array($result) || !isset($result['token']) ) { + // Handle case where array isn't returned or token is missing + \error_log('Quiztech Send Invite Error: create_invitation did not return expected array with token.'); + wp_send_json_error( [ 'message' => esc_html__( 'Failed to retrieve invitation token after creation.', 'quiztech' ) ], 500 ); + } else { + // Success! $result contains the array. Extract the token. + $token = $result['token']; + // $invitation_id = $result['id']; // ID is available if needed later + $email_sent = $invitations->send_invitation_email( $applicant_email, $token, [ 'job_title' => get_the_title( $job_id ) ] ); - if ( $email_sent ) { - wp_send_json_success( [ 'message' => esc_html__( 'Invitation sent successfully.', 'quiztech' ) ] ); + if ( $email_sent ) { + wp_send_json_success( [ 'message' => esc_html__( 'Invitation sent successfully.', 'quiztech' ) ] ); } else { // Invitation created, but email failed. wp_send_json_error( [ 'message' => esc_html__( 'Invitation created, but the email could not be sent. Please check email settings.', 'quiztech' ) ], 500 );