2017-11-02 26 views
1

ユーザーが彼女/彼のプロファイルを更新すると、管理者はメール通知を受け取る機能を作成しようとしています。 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); 

答えて

1

は、ここに私の現在のコードです。次はあなたに適切なユーザーメタ取得する必要があります。ここでは

$user = get_user_meta($get_current_user_id, $key, true);

をあなたはCodexからユーザーの姓を取得する方法の例です。

<?php 
    $user_id = 9; 
    $key = 'last_name'; 
    $single = true; 
    $user_last = get_user_meta($user_id, $key, $single); 
    echo '<p>The '. $key . ' value for user id ' . $user_id . ' is: ' . $user_last . '</p>'; 
?> 

あなたは$uservar_dump()必要があります変数を使用して値を返す方法を確認します。

EDIT:あなたの質問を更新しましたとおり

、機能get_user_meta()の第二paremeterがメタキーです。この場合のメタキーは、検索するユーザーの一部です。たとえば、名または姓。あなたのコードに次のように変更します。

<?php $user_fnm = get_user_meta($user_id, 'name'/*I am 90% sure this one is right*/, $single); $user_lnm = get_user_meta($user_id, 'last_name', $single); ?>

これは、あなたが望む結果を取得する必要があります。今すぐ行う必要があるのはechoで、__($yourvar)を使って画面に表示してください。

+0

ありがとう、私はちょっと働いて、質問の私の更新を確認してください。 – Lpion

関連する問題