Skip to content

Instantly share code, notes, and snippets.

@cryptexvinci
Created March 29, 2022 04:47
Show Gist options
  • Save cryptexvinci/289d6b69d877a5a74d0e254912e9108f to your computer and use it in GitHub Desktop.
Save cryptexvinci/289d6b69d877a5a74d0e254912e9108f to your computer and use it in GitHub Desktop.
display the user profile like at the end of the blog post where I only have to change the user id.
<?php
/*
Code snippet of Plugin Ultimate Member
URL: https://wordpress.org/plugins/ultimate-member/
*/
// Display field data of Ultimate Member
// e.g. [um_field_data userid='24']
add_shortcode('um_field_data', 'um_profile_after_post_shortcode');
function um_profile_after_post_shortcode($atts) {
$default = array(
'userid' => NULL,
);
$a = shortcode_atts($default, $atts);
ob_start();
um_fetch_user( $a['userid'] );
$user_id = $a['userid'];
$name = um_user('display_name');
$avatar = get_avatar( $a['userid'], 96 );
// get_avatar( $a['userid'], 96 );
// um_get_user_avatar_url( $a['userid'], $size = '96' );
?>
<div class="um-members um-members-grid masonry">
<div class="um-member" style="max-width:300px">
<div class="um-member-photo radius-1" style="text-align:center">
<?php echo $avatar;?>
<style type="text/css">.um-member-photo img{border-radius:50%;}</style>
</div>
<div class="um-member-card" style="text-align:center">
<div class="um-member-name">
<a href="<?php echo um_user_profile_url();?>" style="font-size: 16px;line-height: 26px;color: #444;font-weight: 700;">
<?php echo $name;?>
</a>
</div>
<div class="um-friends-bar" style="text-align:center">
<div class="um-friends-rc" style="display:block;float:none;margin-bottom:1em;">
<a href="<?php echo esc_url( UM()->Friends_API()->api()->friends_link( $user_id ) ); ?>" style="border:none;">
<?php _e( 'friends', 'um-friends' ); ?><?php echo UM()->Friends_API()->api()->count_friends( $user_id ); ?>
</a>
</div>
<?php if ( UM()->Friends_API()->api()->can_friend( $user_id, get_current_user_id() ) ) { ?>
<div class="um-friends-btn" style="display:block;float:none">
<?php echo UM()->Friends_API()->api()->friend_button( $user_id, get_current_user_id() ); ?>
<?php do_action( 'um_after_friend_button_profile', $user_id ); ?>
</div>
<?php } ?>
<div class="um-clear"></div>
</div>
</div>
</div>
</div>
<?php
$shortcode_content = ob_get_contents();
ob_end_clean();
return $shortcode_content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment