Custom Fields
Re-Envisioned
Support MB User Meta Get User email info in Custom post meta

  • Creator
    Topic
  • #15238
    Resolved AXEL PARATRE
    Participant

    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 ?

    Capture-2019-07-04-a-13-15-53

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #15252
    Anh Tran
    Keymaster

    You can get the email using this code:

    $user = wp_get_current_user();
    $email = $user->user_email;
    #15254
    AXEL PARATRE
    Participant

    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

    #15269
    Anh Tran
    Keymaster

    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.

    #15280
    AXEL PARATRE
    Participant

    Thanks Anh,

    Maybe it could be a good evolution 🙂

    Regards
    Adrien

    #16303
    Johannes Gross
    Participant

    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);
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
grid gear info copy caret-up caret-down trash