Last active
February 7, 2021 17:08
-
-
Save denisbaranov/0c7580ba81bd15441556a030b1851bc5 to your computer and use it in GitHub Desktop.
Special field types (files, images, etc.) can't be added into the profile card. Settings don't contain these fields. You can use your custom function attached to the filter "um_ajax_get_members_data" to add additional data into the variable "user".
This file contains 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 | |
/** | |
* This example shows how to add an image field into the variable "user" in the member directory. | |
* | |
* Change the variable $key - enter meta_key of the field you need. | |
* Add this code snippet to the end of the file functions.php in the active theme directory. | |
* | |
* @link Documentation https://docs.ultimatemember.com/ | |
* @link Article https://docs.ultimatemember.com/article/1586-add-an-image-field-into-the-profile-card-in-the-member-directory | |
*/ | |
add_filter( 'um_ajax_get_members_data', 'custom_um_ajax_get_members_data', 10, 3 ); | |
function custom_um_ajax_get_members_data( $data_array, $user_id, $directory_data ) { | |
// Enter the field meta_key here: | |
$key = 'um_logo'; | |
$field = UM()->fields()->get_field( $key ); | |
if ( $field && $field['type'] === 'image' ) { | |
$value = UM()->fields()->field_value( $key ); | |
if ( $value ) { | |
$imgURL = UM()->uploader()->get_upload_user_base_url( $user_id ) . '/' . $value; | |
$data_array[$key] = [ | |
'url' => $imgURL, | |
'html' => '<img src="' . esc_url( $imgURL ) . '" alt="' . esc_attr( $field['label'] ) . '"/>' | |
]; | |
} | |
} | |
return $data_array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Once the field is added you can use it in template files members-list.php and members-list.php like this:
<# if ( typeof user.um_logo !== 'undefined' ) { #>{{{user.um_logo.html}}}<# } #>
You can override template files in the theme directory. Read the article Template structure & Overriding templates via a theme for details.