Hi @ctyldsley
echo '/hbcmembers/' . bp_core_get_username( get_current_user_id() ) . '/profile/';
Will output /hbcmembers/logged-in-username/profile/
Hope that helps.
Thanks @HenryWright! But how would I get this into a html link? I can add a html block in the theme’s visual composer. Thanks in advance!
You can wrap it in a shortcode.
Add following in your functions.php file:
add_shortcode( 'CUSER-PROFILE', 'cuser_profile_shortocode_handler' );
function cuser_profile_shortocode_handler( $atts ){
$atts = shortcode_atts( array(
'text' => 'my profile',
), $atts );
if( !is_user_logged_in() )
return '';
$link = home_url( '/hbcmembers/' . bp_core_get_username( get_current_user_id() ) . '/profile/' );
return "<a href='". esc_attr( $link ) ."'>" . $atts['text'] . "</a>";
}
Then you can add [CUSER-PROFILE text=”Edit Profile”] in html block etc..
Thanks for trying to help with this @ckchaudhary! We really need to try solve it within the next 24 hours.
This doesn’t seem to work in a HTML box but is working when I test it on a blank page. Almost there!
How would I edit it to make my image file (/wp-content/uploads/2015/01/ManageProfile.png) link to the Profile page for whoever is logged in at the time?
@ctyldsley
I am assuming you will be be putting the image that connects each user to their profile in a template although I am not sure which one you would want to place it in but something like this should work:
<a href="<?php echo bp_loggedin_user_domain(); ?>"><img src="<?php bloginfo('url'); ?>/wp-content/uploads/2015/01/ManageProfile.png"></a>
Thanks for all of your help everyone!! Finally there, although it’s not the most beautiful thing, it works for this case.
//Shortcode for getting user profile URL
add_shortcode( 'CUSER-PROFILE', 'cuser_profile_shortocode_handler' );
function cuser_profile_shortocode_handler( $atts ){
$atts = shortcode_atts( array(
'text' => 'my profile',
), $atts );
if( !is_user_logged_in() )
return '';
$link = home_url( '/hbcmembers/' . bp_core_get_username( get_current_user_id() ) . '/profile/' );
return "<a href='". esc_attr( $link ) ."'>" . "<img src ='". $atts['text'] . "'> </a>";
}
Using the shortcode but rather than inputting text I just input the URL of the image along with it and it links the image.
@ctyldsley
Use the below code if you only want the image linking to their profile for logged in users.
if ( is_user_logged_in() ) {
<a href="<?php echo bp_loggedin_user_domain(); ?>"><img src="<?php bloginfo('url'); ?>/wp-content/uploads/2015/01/ManageProfile.png"></a>
}
Thanks @bphelp! We’ve already made it so that the page content isn’t displayed if you’re not logged in, and instead it asks you to login. But that’s handy to know for the future! Really appreciate everyone’s help.