Answers:
最简单的方法是使用“规则”执行此操作。接下来的步骤,应该做的工作。
return $account_unchanged->pass != $account->pass;我以前没有在Rules中尝试过,但是可能是比较$accountand $account->original对象上的值的问题。
在自定义代码中执行此操作的一种方法是实现hook_user_presave():
function MYMODULE_user_presave(&$edit, $account, $category) {
// Don't show message for registering users.
if (isset($account->is_new) && $account->is_new) {
return;
}
if (!empty($edit['pass']) && $account->pass != $edit['pass']) {
// Password has been changed.
}
}
您可能可以在中进行相同的操作hook_user_update(),但是我之前从未尝试过。以上内容来自一个实时项目,效果很好。
使用规则可能会更容易,因为您已经在使用它,但是您需要启用PHP过滤器模块。
说明如下:
admin/modulesadmin/config/workflow/rulesAfter updating an existing user account从事件下拉列表中的React中选择。Execute custom PHP code在value部分中添加以下PHP自定义代码
if(!empty($account->current_pass)) {
return true;
}
然后添加一个动作并选择 Send mail
[account:mail]并填充主题字段和消息字段。