Custom Admin Approval Script
-
Greetings.
I am in need of using the features available in Google Forms to perform the “user registration” for new users in WordPress. Using make.com I successfully can create new users from the Google form data with a prof builder user approval status of “pending”. Once approved I want a custom script to run to enclose the link to WordPress’s native reset password link (as a way to force the user to change their password) in the user approval email body. My various php scripts always result in the error “No {{reset_url}} placeholder found in email content” even though the placeholder is included in the email customizer for user approval.
<?php
/**
* Plugin Name: Custom Admin Approval for Profile Builder
* Description: Customizes email content and handles reset URL replacement for Profile Builder's admin approval process.
* Version: 1.0
* Author: Your Name
*/
// Hook into the 'wppb_send_email' filter.
add_filter('wppb_send_email', 'replace_reset_url_in_email', 10, 2);
/**
* Replaces the {{reset_url}} placeholder in email content and ensures the user's name/email is included.
*
* @param array $email_args Email arguments array.
* @param int $user_id The ID of the user.
* @return array Modified email arguments.
*/
function replace_reset_url_in_email($email_args, $user_id) {
// Log debug info for troubleshooting
error_log(">>> wppb_send_email filter triggered for user ID: $user_id");
// Ensure user and reset URL can be retrieved
$user = get_user_by('id', $user_id);
if (!$user) {
error_log(">>> User not found for ID: $user_id");
return $email_args;
}
// Generate the reset URL
$reset_key = get_password_reset_key($user);
if (is_wp_error($reset_key)) {
error_log(">>> Error generating reset key for user ID: $user_id");
return $email_args;
}
$reset_url = wp_login_url() . "?action=rp&key=$reset_key&login=" . rawurlencode($user->user_login);
error_log(">>> Generated Reset URL for user ID $user_id: $reset_url");
// Replace {{reset_url}} in email content or add fallback
if (strpos($email_args['message'], '{{reset_url}}') !== false) {
$email_args['message'] = str_replace('{{reset_url}}', $reset_url, $email_args['message']);
} else {
error_log(">>> Placeholder {{reset_url}} not found. Adding reset URL explicitly.");
$email_args['message'] .= "<br><br>You can reset your password using this link: $reset_url";
}
// Add user's email or name dynamically in "Dear" section
$user_name = $user->display_name ? $user->display_name : $user->user_email;
if (strpos($email_args['message'], '{{user_email}}') !== false) {
$email_args['message'] = str_replace('{{user_email}}', $user_name, $email_args['message']);
} else {
$email_args['message'] = "Dear $user_name,<br>" . $email_args['message'];
}
// Log final email content for verification
error_log(">>> Final email content for user ID $user_id: " . $email_args['message']);
return $email_args;
}I’ve been trying to use the hooks listed on the prof builder support page to the best of my ability, but the {{reset_url}} placeholder continues to echo no value in the email body.
Your help is appreciated in advance.
- You must be logged in to reply to this topic.