Skip to content

Instantly share code, notes, and snippets.

@tripflex
Last active March 17, 2020 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/6575a90410074457e519c54ff25f5ecc to your computer and use it in GitHub Desktop.
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
<?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, '?' );
}
@tripflex
Copy link
Author

tripflex commented Jan 7, 2020

This assumes the meta key is company_logo to auto populate for, if you want to use a different meta key, change company_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment