Show the Frontend Custom User Profile Image - within MB Admin Columns

Support MB Admin Columns Show the Frontend Custom User Profile Image - within MB Admin ColumnsResolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #44325
    CodogCodog
    Participant

    Hi there,
    I use a custom field for a profile picture on the type => 'user' MB frontend user form where users can upload a custom image using a 'file_upload' field. I know this is straight forward using the 'image_upload' field where there is no need to create a custom admin column, I can simply show it like this in the custom field itself:

    'admin_columns' => [
        'position' => 'before username',
        'title'    => 'Profile Picture',
        ],

    I know this works fine.

    However, for technical reasons I need to use the 'file_upload' field for the job - but the above method does NOT show the user uploaded image in the admin column for the 'file_upload' field type? Just a link to the image?

    So I thought I would create an action hook following your documentation to show it. Here is what I have so far....

    `add_action( 'init', 'prefix_add_profile_columns', 20 );
    function prefix_add_profile_columns() {
    class Prefix_Custom_Profile_Columns extends \MBAC\Post {
    public function columns( $columns ) {
    $columns = parent::columns( $columns );
    $position = 'before';
    $target = 'username';
    $this->add( $columns, 'profile_picture', 'Profile Picture', $position, $target );
    // Add more if you want
    return $columns;
    }
    public function show( $column, $post_id ) {
    switch ( $column ) {
    case 'profile_picture':

    // My image query to go here.

    break;
    }
    }
    }

    new Prefix_Custom_Profile_Columns( 'user', array() );
    }

    Right now the custom admin column does not even register (show) in the 'users.php'. What am I missing? Or is there another method?

    Thanks in advance 🙂

    #44326
    CodogCodog
    Participant

    ..... sorry forgot to close the code block. For clarity....

    add_action( 'init', 'prefix_add_profile_columns', 20 );
    function prefix_add_profile_columns() {
        class Prefix_Custom_Profile_Columns extends \MBAC\Post {
            public function columns( $columns ) {
                $columns  = parent::columns( $columns );
                $position = 'before';
                $target   = 'username';
                $this->add( $columns, 'profile_picture', 'Profile Picture', $position, $target );
                // Add more if you want
                return $columns;
            }
            public function show( $column, $post_id ) {
                switch ( $column ) {
                    case 'profile_picture':
                          // My My image query to go here.
                        break;
                }
            }
        }
        
        new Prefix_Custom_Profile_Columns( 'user', array() );
    }
    #44343
    PeterPeter
    Moderator

    Hello,

    I see you have a similar question in the past https://support.metabox.io/topic/add-fallback-image-when-there-is-no-featured-image/
    You can modify the admin column of the file_upload field with the filter hook rwmb_the_value to display the image instead of using a custom admin column.

    #44344
    CodogCodog
    Participant

    Hi Peter,
    so I did! But I didn't follow up on that implementation in the end. After looking at the links you provided it's still not 100% clear on how to use rwmb_the_value to show the output of the file_upload custom field as an admin column. It would be very helpful if you could you post a basic example?

    Many Thanks 🙂

    #44356
    PeterPeter
    Moderator

    Hello,

    Here is an example:

    add_filter( 'rwmb_the_value', function( $output, $field, $args, $object_id ) {    
        if( is_admin() && $field['id'] == 'file_upload_id') {
            $file_value = rwmb_meta( 'file_upload_id', $args, $object_id );
            if( !empty( $file_value ) ) {
                $file_value = array_pop( $file_value );
                $output = '<img src="'. $file_value['url'] .'" alt="File image" width="32" height="32">';
            }
        }
    
        return $output;
    }, 11, 4 );
    #44362
    CodogCodog
    Participant

    Hi Peter,
    perfect!

    Thank you 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.