2016-10-04 25 views
0

當新用戶在我們的網站上註冊時,他們需要填寫他們的公司信息。這些信息存儲在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(),但該值始終爲空。

任何幫助,非常感謝。

+0

您是否檢查數據庫中是否存在「公司」用戶還是不是?這可能是,雖然用戶註冊'公司'元未被插入到數據庫中。 –

+0

我檢查了這個...對於每個id,meta_key生成爲「公司」,並且根據他們的提交添加meta_value,例如, 'McDonalds' –

+0

好了,現在在wp_mail之前使用'die();'並打印'get_user_meta($ user_id)'並檢查它是否返回'company'。 –

回答

1

我想通了這個問題。我用來創建新用戶的插件(配置文件按)發佈新用戶,觸發wp_new_user_notification,然後將自定義值添加到元表。我移動了wp_new_user_notification上方的元表函數,並且數據按預期進行傳輸。如果沒有其他人遇到這個問題,在這裏是如何解決這個問題:

在WP-包括/ pluggable.php,如預期了以下工作:

$company = get_user_meta($user_id, 'company', true); 
$message .= sprintf(__('Company: %s'), $company) . "\r\n"; 

至於概況新聞,導航到WP-內容/插件/ profilepress /類/類登記外形auth.php並把:

// register custom profile field 
if (! is_wp_error($user_id)) { 
. 
//truncated 
. 
      do_action('pp_after_custom_field_update', $key, $value, $user_id, 'registration'); 
     } 
    } 
以上

if (is_int($user_id) && 'enable' == $new_user_notification) { 
     wp_new_user_notification($user_id, null, 'admin'); 
    } 

希望這有助於任何有類似問題的人。特別感謝@RaunakGupta指出我的方向,並將他們的代碼歸功於個人資料出版社。

相關問題