doubiantiao4994 2016-10-04 03:18
浏览 53
已采纳

将用户元值添加到Wordpress管理员电子邮件中

When a new user registers on our website, they are required to fill out their company information. This information is stored in the _usermeta table with the meta_key 'company'.

All I want to do is include this information in the notification email that Wordpress sends to the site administrator. I have had some luck manipulating pluggables.php (where the default email code is located), but I can't get any meta values to send in the email.

Here is my current code:

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) . "

";
$message .= sprintf(__('Name: %s'), $user->display_name) . "

";
$message .= sprintf(__('E-mail: %s'), $user->user_email) . "

";
$message .= sprintf(__('Company: %s'), $company) . "
";

@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);

The code outputs:

New user registration on your site mywebsite

Name: firstname lastname

E-mail: email@example.com

Company:

I have included get_user_meta() and get_metadata() but the value is always blank.

Any help is greatly appreciated.

  • 写回答

1条回答 默认 最新

  • douxunwei8259 2016-10-06 17:53
    关注

    I figured out the issue. The plugin I use to create new users (profile press) was posting the new user, triggering wp_new_user_notification, THEN adding custom values to the meta table. I moved the meta table function above wp_new_user_notification and the data is transferring as expected. Should anyone else run into this issue, here is how to solve it:

    In wp-includes/pluggable.php, the following works as expected:

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

    As for profile press, navigate to wp-content/plugins/profilepress/classes/class-registration-form-auth.php and put:

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

    above:

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

    Hope this helps anyone else who has similar issues. Special thanks to @RaunakGupta for pointing me in the direction and credit to profile press for their code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)