當新用戶在我們的網站上註冊時,他們需要填寫他們的公司信息。這些信息存儲在meta_key'company'的_usermeta表中。將用戶元值添加到Wordpress管理郵件
我想要做的就是將此信息包含在Wordpress發送給網站管理員的通知電子郵件中。我有一些運氣操縱pluggables.php(默認電子郵件代碼所在的位置),但我無法獲取任何元值來發送電子郵件。
這裏是我當前的代碼:
function wp_new_user_notification($user_id, $plaintext_pass = '') {
$user = get_userdata($user_id);
$user_meta = get_user_meta($user_id);
$company = $user_meta['company'][0];
// The blogname option is escaped with esc_html on the way into the database in sanitize_option
// we want to reverse this for the plain text arena of emails.
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$message = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
$message .= sprintf(__('Name: %s'), $user->display_name) . "\r\n\r\n";
$message .= sprintf(__('E-mail: %s'), $user->user_email) . "\r\n\r\n";
$message .= sprintf(__('Company: %s'), $company) . "\r\n";
@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
代碼輸出:在您的網站
新用戶註冊mywebsite
名稱:名姓
電子郵件:電子郵件@ example.com
公司:
我已經包含get_user_meta()和get_metadata(),但該值始終爲空。
任何幫助,非常感謝。
您是否檢查數據庫中是否存在「公司」用戶還是不是?這可能是,雖然用戶註冊'公司'元未被插入到數據庫中。 –
我檢查了這個...對於每個id,meta_key生成爲「公司」,並且根據他們的提交添加meta_value,例如, 'McDonalds' –
好了,現在在wp_mail之前使用'die();'並打印'get_user_meta($ user_id)'並檢查它是否返回'company'。 –