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
- This topic has 5 replies, 2 voices, and was last updated 1 year, 3 months ago by
Codog.
-
AuthorPosts
-
January 18, 2024 at 3:11 AM #44325
Codog
ParticipantHi there,
I use a custom field for a profile picture on thetype => '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 🙂
January 18, 2024 at 3:15 AM #44326Codog
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() ); }
January 18, 2024 at 11:15 PM #44343Peter
ModeratorHello,
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 hookrwmb_the_value
to display the image instead of using a custom admin column.January 18, 2024 at 11:26 PM #44344Codog
ParticipantHi 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 userwmb_the_value
to show the output of thefile_upload
custom field as an admin column. It would be very helpful if you could you post a basic example?Many Thanks 🙂
January 20, 2024 at 2:00 PM #44356Peter
ModeratorHello,
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 );
January 22, 2024 at 12:57 AM #44362Codog
ParticipantHi Peter,
perfect!Thank you 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.