admin管理员组文章数量:1336631
Is there a way or a snippet that can be created to automatically send an automatic email to users who we manually approve stating there account has been approved.
To go a little in-depth about this - User's are able to sign up to our website and the information is sent to the website, we have a custom plugin that display certain information the user entered, the information is displayed through using Advanced Custom Fields. In the customised plugin section we have "login allowed" checkbox, i want it so when i check this and click update user, the email is sent.
The email would be automatically retrieved from the wordpress's default "Basic information" section if possible. Any guidance / clarification & feedback is majorly appreciated.
EDIT:
add_action(‘acf/save_post’, ‘my_save_post’);
function my_save_post( $post_id ) {
// create some logic here to check if you are editing a user
global $pagenow;
if ($pagenow == ‘user-edit.php’) {
//get the value of the field
$value = get_field(‘login_allowed’,$post_id);
// check if the checkbox is filled
if ( ! $value ='unchecked' ) {
return false;
}
$value == 'checked'{
// Company information
$email = “removed”;
$name = “removed”;
//get user's email
$user = get_user_by('email', $useremail);
if ($user) {
$details['email'] = $user->user_email;
// email data
$to = $useremail;
$subject = 'The subject';
$body = 'The email body content';
$headers = ‘From:‘ . $name . ‘ <‘ . $email . ‘>’ . “\r\n”;
// send email
wp_mail($to, $subject, $body, $headers );
}
}
}
}
Is there a way or a snippet that can be created to automatically send an automatic email to users who we manually approve stating there account has been approved.
To go a little in-depth about this - User's are able to sign up to our website and the information is sent to the website, we have a custom plugin that display certain information the user entered, the information is displayed through using Advanced Custom Fields. In the customised plugin section we have "login allowed" checkbox, i want it so when i check this and click update user, the email is sent.
The email would be automatically retrieved from the wordpress's default "Basic information" section if possible. Any guidance / clarification & feedback is majorly appreciated.
EDIT:
add_action(‘acf/save_post’, ‘my_save_post’);
function my_save_post( $post_id ) {
// create some logic here to check if you are editing a user
global $pagenow;
if ($pagenow == ‘user-edit.php’) {
//get the value of the field
$value = get_field(‘login_allowed’,$post_id);
// check if the checkbox is filled
if ( ! $value ='unchecked' ) {
return false;
}
$value == 'checked'{
// Company information
$email = “removed”;
$name = “removed”;
//get user's email
$user = get_user_by('email', $useremail);
if ($user) {
$details['email'] = $user->user_email;
// email data
$to = $useremail;
$subject = 'The subject';
$body = 'The email body content';
$headers = ‘From:‘ . $name . ‘ <‘ . $email . ‘>’ . “\r\n”;
// send email
wp_mail($to, $subject, $body, $headers );
}
}
}
}
Share
Improve this question
edited May 21, 2020 at 12:48
YxngLBZ
asked May 20, 2020 at 14:14
YxngLBZYxngLBZ
233 bronze badges
1 Answer
Reset to default 0First, add a custom Action Hook that is triggered whenever the user is updated.
For example, when custom meta fields are updated in WordPress, some action hooks such as: updated_{$meta_type}_meta, updated_postmeta, etc.
So if you're using the ACF plugin, you can hook into the 'acf/save_post' action hook. The action hook lets you do something before or after the custom field are being updated. For more info on using the acf/save_post, click here.
Next, you can now send the email to the user using the wp_mail() function.
Based on the code you have provided, I made some refactoring:
add_action(‘acf/save_post’, ‘my_save_post’); function my_save_post( $post_id ) { // create some logic here to check if you are editing a user // Keep an eye on this pagenow check to see if it's correct // Use wp_die( var_dump( $pagenow ); to debug global $pagenow; if ($pagenow == ‘user-edit.php’) { //get the value of the field $value = get_field(‘login_allowed’,$post_id); // Remove this, just here for debugging // wp_die( var_dump( $value ) ); // check if the checkbox is filled if ( $value == 'unchecked' ) { return false; } // Company information $email = “removed”; $name = “removed”; // Debug: I see $useremail variable, is it set somewhere? //get user's email $user = get_user_by('email', $useremail); if ($user) { $details['email'] = sanitize_email( $user->user_email ); // email data $to = $useremail; $subject = 'The subject'; $body = 'The email body content'; $headers = ‘From:‘ . $name . ‘ ’ . “\r\n”; // send email wp_mail($to, $subject, $body, $headers ); } } }
本文标签: phpAutomatic email message after manual user approval
版权声明:本文标题:php - Automatic email message after manual user approval 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742412194a2470008.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论