Skip to content

Instantly share code, notes, and snippets.

@imath
Created November 26, 2012 08:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imath/4147276 to your computer and use it in GitHub Desktop.
Save imath/4147276 to your computer and use it in GitHub Desktop.
displaying BuddyPress user's home page link if he's connected into a WordPress post, page or text widget
<?php
/*** displaying BuddyPress user's home page link if he's connected into a WordPress post, page or text widget ***/
/*********
Beginning of the code to paste in the functions.php of your active theme
**********/
/* registering a shortcode is the easiest way i think */
add_shortcode('turenne','turenne_handle_shortcode');
function turenne_handle_shortcode( $atts ){
global $bp;
/* to display a user's home link, user needs to be connected ! */
if( !is_user_logged_in() )
return false;
$user_id = $bp->loggedin_user->id;
$output = '<div class="turenne" style="display:inline-block">';
$display_name = bp_core_get_user_displayname( $user_id );
$home_user_url = bp_core_get_user_domain( $user_id );
extract( shortcode_atts( array(
'avatar' => true,
'size' => 50,
'alias' => ''
), $atts));
/* if no alias, then name of the user */
if( empty( $alias ) )
$alias = $display_name;
$output .= '<a href="'. $home_user_url .'" title="'. $alias .'">';
if( !empty( $avatar ) ) {
$output .= bp_core_fetch_avatar( array( 'item_id' => $user_id, 'object' => 'user', 'type' => 'full', 'width' => $size.'px', 'height' => $size.'px' ) );
}
$output .= '<span style="margin-left:5px;line-height:'.$size.'px">' . $alias . '</span></a><br style="clear:both"/></div>';
return apply_filters( 'turenne_handle_shortcode', $output, $atts );
}
/*********
End of the code to paste in the functions.php of your active theme
**********/
/*** now you can use this kind of shortcode in your posts, pages or text widgets
[turenne avatar="1" alias="affichez votre profil"]
to allow shortcodes in text widgets, please visit :
http://codex.wordpress.org/Function_Reference/do_shortcode
***/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment