Last active
May 17, 2025 13:06
-
-
Save yuriinalivaiko/fd6d8b0ef44991a4b94c64284e1cde0e to your computer and use it in GitHub Desktop.
Ultimate Member customization. Display custom images in the member directory grid.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Display custom images in the member directory grid. | |
| */ | |
| add_filter( 'um_ajax_get_members_data', function( $data_array, $user_id, $directory_data ) { | |
| // List needed fields here. | |
| $fields = array( | |
| 'um_image_upload', | |
| 'upload_logo', | |
| ); | |
| foreach ( $fields as $meta_key ) { | |
| $file_name = um_user( $meta_key ); | |
| if ( $file_name ) { | |
| $file_path = trailingslashit( UM()->uploader()->get_upload_user_base_dir( um_user( 'ID' ) ) ) . $file_name; | |
| $file_url = trailingslashit( UM()->uploader()->get_upload_user_base_url( um_user( 'ID' ) ) ) . $file_name; | |
| if ( file_exists( $file_path ) ) { | |
| $data_array[ 'hook_after_user_name' ] .= '<div class="um-photo"><a href="#" class="um-photo-modal" data-src="' . esc_attr( $file_url ) . '"><img src="' . esc_attr( $file_url ) . '" alt="' . esc_attr( $meta_key ) . '"/></a></div>'; | |
| } | |
| } | |
| } | |
| return $data_array; | |
| }, 10, 3 ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code displays the custom image fields in the member directory.
Images are clickable. You'll see an enlarged image in the popup on click.
Add fields you want to display to the
$fieldsarray then add this code to the functions.php file in the theme directory.Expected result
Directory grid

Popup

There is an alternative solution. Read the article Add an image field into the profile card in the member directory.