Custom Fields
Support MB User Meta add and use local avatar with user meta extension

  • Creator
  • #8308
    Resolved brkard


    I have tested user meta with example code here:

    I cant add avatar to user profiles wiht that code.

    Is it possible to add and use local avatar with user meta extension by some way ?

    If so can you share the snippet code if possible ?


Viewing 1 replies (of 1 total)
  • Author
  • #11288

    This is actually quite easy and will add the profile picture in your wp-admin profile screen.

    // Add User Profile Support
    add_filter( 'rwmb_meta_boxes', 'your_prefix_register_user_meta_boxes' ));
    function your_prefix_register_user_meta_boxes( $meta_boxes ) {
            $meta_boxes[] = array (
                'title' => 'Profile Picture',
                'id' => 'profile_picture',
                'fields' => array(
                    array (
                        'id' => 'custom_avatar',
                        'type' => 'single_image',
                        'name' => 'Upload Avatar',
                'type' => 'user',
            return $meta_boxes;

    To get the avatar URL use:

    // Check if MetaBox is available
    if (function_exists('rwmb_meta')) {
      // Get the attachment object
      $avatar = rwmb_meta( 'custom_avatar', array( 'object_type' => 'user' ), $user_id );
    // Check if the user has a custom avatar, get the URL
      if ($avatar) $avatar_url = $avatar['url']; // this will get the 150x150 sized avatar
    // If no avatar is set, use your own custom one
      else $avatar_url = site_url().'path/to/your/default/avatar.jpg';
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.