Skip to:
Content
Pages
Categories
Search
Top
Bottom

Link To Member Profile In Form Field


  • littlemisslanna
    Participant

    @littlemisslanna

    So right now I am using Gravity Forms with the Sticky List plugin to create an editable database people can submit information to. I have a hidden field that automatically populates the username of the submitter, which is cool and what I want. But I would like that username in question to link to that user’s BuddyPress profile.

    I have a feeling it has to do with some PHP code, but I’m not savvy with php as I’d like to be. This is what I have so far, from a previous topic I found on the forum.

    add_filter( 'gform_field_value_linkuser', 'link_username' );
    
    <?php
    add_filter( 'gform_field_value_linkuser', 'link_username' );
    function link_username($user_login) {
       return '$_COOKIE['utm_campaign']; < NO idea what to return here! 
    }

    ?>
    I assume the return value should be something like <a href="URL.com/members/[USERNAME]">Username </a>, but I don’t know how to make that work in PHP!

    Please help me out! BP is version 2.5.2, BBP Version is 2.5.9, WP version is most recent one, Gravity Forms 1.9.19, Gravity Forms Sticky List plugin 1.4.1.

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)

  • littlemisslanna
    Participant

    @littlemisslanna

    Update!

    add_filter("gform_field_value_linkuser", "populate_linkuser");
    function populate_linkuser($value) {
    
            $current_user = wp_get_current_user();
            $user=$current_user->user_nicename ;
            $profilelink = '<a href="/members/$user">$user</a>';
            return $profilelink;
      
    }

    The above isn’t breaking anything, but it’s not working, either. Any ideas?


    danbp
    Participant

    @danbp

    Hi,

    you can use
    bp_get_loggedin_user_link
    Get the link for the logged-in user’s profile.

    or
    bp_loggedin_user_domain
    Generate the link for the logged-in user’s profile.

    Something like
    $profilelink = '<a href="'. bp_get_loggedin_user_link() .'">$user</a>';


    littlemisslanna
    Participant

    @littlemisslanna

    Hi there!

    Thanks very much. Unfortunately, it doesn’t seem to be working. It’s just posting “$user” and it’s not linked.

    I read somewhere that gravity forms itself struggles with links, but I don’t know what exactly to do to handle it. I know I can shove javascript into the “custom header” area on my template. Any ideas?


    danbp
    Participant

    @danbp

    That’s unfortunately what i expected… GF is a third party premium plugin for which nobody can help you here, except if he/she use that plugin.

    If you read here, it’s somehow explained in details.

    What you already used (gform_field_value_linkuser), linkuser is a GF field name. If i’m right, see the advanced tab of that field and complete the name parameter.

    Here a snippet which let you see how to link a username to his profile, when you’re outside of the member_loop. It will output the current user name on the site wide activity header. For test only.

    Note that it use BuddyPress default Name field and that it comes from a BP form. As you use GF, you certainly need to find how to grab properly a GF field value.

    Function goes to bp-cutom, may also work in theme’s functions.php

    function bpfr_my_profile_link_on_SWA_header () {	
    	$user_id = get_current_user_id();
    	$profile_url = bp_loggedin_user_domain();
    
    	if( !is_user_logged_in() ) {
    		return;
    	}
    
    	echo '<br>Test userlink:&nbsp;'; 
    
    	if ( !$data = bp_get_profile_field_data( 'field=Name' ) ) : 
    
    		echo xprofile_get_field_data( 'Name', bp_get_member_user_id() ) .'<a href="'. $profile_url .'">'. bp_core_get_username( $user_id ).'</a><br>';
    
    	endif;		
    
    }
    add_action( 'bp_activity_type_tabs', 'bpfr_my_profile_link_on_SWA_header' ); 

    Sorry, I can’t help you more.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar