BuddyDev

Search

[Resolved] Customize text for a link in a profile field

  • Participant
    Level: Initiated
    Posts: 10
    lobo on #45684

    Hello,

    I added a URL type field in the member profile, but I can’t manage to customize the text for the link and hide the full URL…

    I tried something like : <a href="https://mywebsite.com/test_customized_link/">URL is now hidden</a>

    But it doesn’t work, it shows all the text not the link customized.

    Is there is a way to customize it please, it’s not really nice to show a full URL like that in a profile field.

    I want this result : URL is now hidden

    Thank you for your help

    Wordpress version : 6.0.1
    BuddyPress version : 10.3.0
    Website URL : Private website closed for public people

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2497
    Ravi on #45687

    Hello Lobo,

    Thank you for posting. Please use the following code to filter all URL field values you can restrict it using field id given as function argument.

    
    add_filter( 'bp_get_the_profile_field_value', function ( $field_value, $field_type, $field_id ) {
    
    	if ( ! bp_is_user() ) {
    		return $field_value;
    	}
    
    	$user_id = bp_displayed_user_id();
    
    	// You can play with user id.
    	if ( 'url' == $field_type ) {
    		$field_value = sprintf( '<a href="%s">%s</a>', esc_url( 'https://mywebsite.com/test_customized_link/' ), esc_html__( 'URL is now hidden' ) );
    	}
    
    	return $field_value;
    }, 10, 3 );
    
    

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 10
    lobo on #45688

    Thanks a lot !! I will test it ASAP 🙂

  • Participant
    Level: Initiated
    Posts: 10
    lobo on #45689

    Hello again,

    Sorry, it doesn’t work, I was wrong, the text is showing like that if I choose text field type : <a href="https://mywebsite.com/test_customized_link/">URL is now hidden</a>

    But if I choose a URL field type, I have an error and the field is not saved with the provided value.

    I tried to modify your code like this by modifying if ( 'url' == $field_type ) to if ( 'text' == $field_type ) but it still doesn’t work.

    And just to clarify, I just want that all URL fields are not filtered and interpret HTML code, for all users, don’t want to specify anything in parameter if possible.

    Thank you

    Since it will be a private website and fields are accessible only to logged on users, no security problems, everyone on this website are trustful people.

    • This reply was modified 4 months, 3 weeks ago by lobo.
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2497
    Ravi on #45717

    Hello Lobo.

    Thank you for the acknowledgement. Please let me know what your requirements mean do you want to filter URL field value for a specific user or based on other criteria so that I can help you.

    Also, please post me the code you are using.

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved