I'm creating a site that includes 2 custom role types (Doctor and Profile Admin). The doctors are able to maintain their own bios through a custom post type and restricted capabilities on their user type allowing them to only see their own bio edit page.
What Im trying to do is send an alert email to any users with the role type Profile Admin whenever a user with the role type Doctor updates their profile. The function I have now works as intended, sends an email when doctor role type users update, except right now I can only get it working when sending to a static email address. See code below:
// Send notification email when doctor updates profile
add_action( 'post_updated', 'doc_profile_change_email' );
function doc_profile_change_email ($post) {
if ( current_user_can('doctor') ) {
$user_info = get_userdata ($post->post_author);
$strTo = array ('[email protected]');
$strSubject = get_the_title($post) . ' updated their profile.';
$strMessage = get_the_title($post) . ' submitted their profile for review at ' . wp_get_shortlink ($post->ID) . '&preview=true. Please proof.';
wp_mail( $strTo, $strSubject, $strMessage );
}
}
I attempted to write a function that loops through all the profile admin emails and return an array. See below:
// Get practice admin emails
function get_practice_admin_emails() {
$profile_admin_emails = array();
$profile_admins = get_users( $args );
$args = array(
'role' => 'profile_admin',
);
foreach ( $profile_admins as $user ) {
$profile_admin_emails[ $user->user_email ];
}
return $profile_admin_emails;
}
The thought was to use this to populate the $strTo argument as follows:
$strTo = get_practice_admin_emails();
But this isn't working. I'm not sure if I'm over complicating this and there is an obvious answer I'm missing but any insight would be greatly appreciated.