如果任何用户更改了他/她的当前配置文件值,我想通知管理员。该代码有效,但问题是,一旦信息更新,将会收到两封电子邮件。如何解决此问题?
我的代码是
function my_update() {
global $current_user;
get_currentuserinfo();
$message = '<h3>the user : <span style="color:blue">' .$current_user->display_name . " </span>has updated profile</h3> submitted values:\n<hr>";
foreach($_POST as $key => $value){
add_filter( 'wp_mail_content_type', 'set_html_content_type' );
$message .= substr($key, 0, -3) . " : ". $value ."<br>";
}
add_filter( 'wp_mail_content_type', 'set_html_content_type' );
@wp_mail(get_option('admin_email'), 'User Profile Update', $message);
remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
}
function set_html_content_type() {
return 'text/html';
}
add_action('profile_update','my_update');
我通过添加解决了这个问题
function my_update() {
if(did_action('profile_update') === 1) {
/*my code here*/
}
}
有一些时间找到解决方案。我从这里找到了解决方案
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句