ユーザーが彼女/彼のプロファイルを更新すると、管理者はメール通知を受け取る機能を作成しようとしています。 wp_usersに格納されたデータではなく、wp_usermetaに格納された変更を知りたいと思います。 Ultimate Memberで作成されたmetakeysはかなりたくさんあります。ユーザー変更プロファイル
電子メールには変更された値のみが含まれている必要があります。また、古い値も表示されるのが最適です。
私はUltimateMemberプラグインを使用しています。 thisサイトによると、私は始めるためにこれが必要になります。
function action_um_after_user_account_updated($get_current_user_id) {
// make action magic happen here...
};
add_action('um_after_user_account_updated', 'action_um_after_user_account_updated', 10, 1);
検索し、主にthisに基づいて、多くの後、私はこの思い付いた:
function action_um_after_user_account_updated($get_current_user_id, $prev_value) {
$key = 'name';
$user = get_user_meta($user_id, $key, $single);
$single = true;
if($prev_value->$key != $user->$key) {
$admin_email = "[email protected]";
$message .= sprintf(__('New Name is: %s'), $user). "\r\n\r\n";
$message .= sprintf(__('Old name was: %s'), $prev_value). "\r\n\r\n";
wp_mail($admin_email, sprintf(__('[DB] Name changed')),$message);
}
};
// add the action
add_action('um_after_user_account_updated', 'action_um_after_user_account_updated', 10, 1);
まあ、それはで仕事をdoesntのすべて。私はPHPコードの問題を抱えているか、コードが古くなっているかどうかはわかりませんが、うまくいきません。
私は、私が知る限り、wp_mailを使用する必要があるpluggable.phpも含めました。 (include ABSPATH . WPINC . '/pluggable.php';
)を私のテーマ(smartpress)のヘッダファイルに入れてください。
- Wordpressの-バージョン:4.8.2
- 究極のメンバーのバージョン:1.3.88
- PHPバージョン:5.6
UPDATE:
私が今作っ代わりにプラグイン、ちょっと働いています。私はメールを受信し、提供されたmeta_keysから値を取得します。今、私はメールにすべてのmeta_valueを表示したくない。変更したものだけを表示する。以前の値を保存する方法はありますか?プロファイルが更新されて比較される直前ですか? $user = get_user_meta($user_id, $key, $single);
いくつかの変数をあなたが渡して空になっている:私はあなたの問題はここに配置されていることを信じてい
function profile_update_name() {
$user_id = get_current_user_id();
$single = true;
$user_fnm = get_user_meta($user_id, 'firstnamemother', $single);
$user_lnm = get_user_meta($user_id, 'nachnamemother', $single);
$admin_email = "[email protected]";
$message .= sprintf(__($user_fnm .' '. $user_lnm . ' has updated the profile.')). "\r\n\r\n";
$message .= sprintf(__('New Name is: %s'), $user_fnm .' '. $user_lnm). "\r\n\r\n";
$message .= sprintf(__('Old name was: %s'), $user_lnm). "\r\n\r\n";
wp_mail($admin_email, sprintf(__('[DB] Name changed')),$message);
};
// add the action
add_action('um_user_after_updating_profile', 'profile_update_name', 1, 10);
ありがとう、私はちょっと働いて、質問の私の更新を確認してください。 – Lpion