Last active
March 17, 2020 16:28
-
-
Save tripflex/6575a90410074457e519c54ff25f5ecc to your computer and use it in GitHub Desktop.
Auto Populate file field from Ultimate Member Profile/Avatar when using WP Job Manager Field Editor
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 | |
add_filter( 'field_editor_auto_populate_company_logo', 'smyles_auto_populate_get_um_user_profile' ); | |
function smyles_auto_populate_get_um_user_profile( $value ){ | |
$user_id = get_current_user_id(); | |
// Set user ID | |
um_fetch_user( $user_id ); | |
// Get current user avatar | |
$avatar_uri = um_get_avatar_uri( um_profile( 'profile_photo' ), 32 ); | |
// Returns default UM avatar, e.g. https://ultimatemember.com/wp-content/uploads/2015/01/default_avatar.jpg | |
$url = ! empty( $avatar_uri ) ? $avatar_uri : um_get_default_avatar_uri(); | |
// Remove any query args from the URL | |
return strtok( $url, '?' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This assumes the meta key is
company_logo
to auto populate for, if you want to use a different meta key, changecompany_logo
in the code above to the correct meta key.Two caveats with this as well:
You can NOT use the auto save feature to user meta, as this will NOT update the ultimate member profile image
When a user updates a listing with a new image, this will NOT update the ultimate member profile image
Reason being is that Ultimate Member does NOT save the full image URL to the user's meta (or even an attachment ID), all it saves is the filename which leaves us no way to update it correctly.