我正在创建一个包含2种自定义角色类型(医生和档案管理员)的网站。医生可以通过自定义帖子类型和用户类型上的受限功能维护自己的bios,从而只允许他们查看自己的生物编辑页面。
我试图做的是,每当角色类型为“医生”的用户更新其配置文件时,向任何角色类型为“配置文件管理员”的用户发送警报电子邮件。我现在的功能可以正常工作,在医生角色类型用户更新时发送电子邮件,但现在我只能在发送到静态电子邮件地址时才能工作。请参见下面的代码:
// 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 (\'myemail@email.com\');
$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 );
}
}
我试图编写一个函数来循环遍历所有配置文件管理电子邮件并返回一个数组。见下文:
// 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;
}
我们的想法是使用它来填充$strTo参数,如下所示:
$strTo = get_practice_admin_emails();
但这不起作用。我不确定我是否把这件事复杂化了,我没有找到一个明显的答案,但如果有任何见解,我将不胜感激。