Support Forum
Support › MB User Meta › Get User email info in Custom post metaResolved
Hi Anh,
I try to get the email data in a custom post meta
Il works for all data inside the table wp_user_meta but the email is in the wp_users table.
Can you tell me how to get the email value from wp_users with MB User Meta ?
Thanks
You can get the email using this code:
$user = wp_get_current_user();
$email = $user->user_email;
Hi Anh,
Thanks for your answer.
I knew that I could get it by code. My question was about to get it directly via the MB Builder ?
Thanks
Adrien
Hi Adrien,
I'm afraid the plugin only supports static value. There's no way to make it understand the dynamic value at the moment.
Thanks Anh,
Maybe it could be a good evolution 🙂
Regards
Adrien
Run into it and ended up using something like following to be able to have users update their email address in the frontend:
add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
$meta_boxes[] = [
'title' => '',
'id' => 'edit_user_profile',
'type' => 'user',
'fields' => [
[
'id' => 'first_name',
'name' => 'First Name',
'type' => 'text',
],
[
'id' => 'last_name',
'name' => 'Last Name',
'type' => 'text',
],
[
'id' => 'twt_user_email',
'name' => 'Email',
'type' => 'email',
'save_field' => false
],
],
];
return $meta_boxes;
} );
//hide user profile metabox in backend (otherwise duplicate)
add_filter( 'rwmb_show_edit_user_profile', '__return_false' );
//populate twt_user_email
add_filter('rwmb_twt_user_email_field_meta', function($meta, $field, $saved) {
$user = wp_get_current_user();
return $user->user_email;
}, 10, 3);
//update users email upon profile update
add_filter('rwmb_profile_update_user_data', function($data, $config ) {
$data['user_email'] = sanitize_email($_POST['twt_user_email']);
return $data;
}, 10, 2);