Skip to:

Validating a url from xprofile field

  • dunc



    I’m trying to validate the URL provided by members in an xprofile field ‘Website’ and need some help please.

    The xprofile data is retrieved with:

    bp_member_profile_data( ‘field=Website’ )

    What I’m trying to do is create a link to the member’s website using this data, however some users enter the http:// bit and some don’t. I’ve tried a simple pregmatch php to look for ‘http://’ and then apply rules accordingly, but I can’t get it to work with bp_member_profile_data( ‘field=Website’ ).

    The link I’m trying to achieve is actually working in the main BP profile loop. I tried to see how it was done there and I came across this somewhat confusing function in bp-xprofile-filters.php:

    function xprofile_filter_link_profile_data( $field_value, $field_type = ‘textbox’ ) {
    if ( ‘datebox’ == $field_type )
    return $field_value;

    if ( !strpos( $field_value, ‘,’ ) && ( count( explode( ‘ ‘, $field_value ) ) > 5 ) )
    return $field_value;

    $values = explode( ‘,’, $field_value );

    if ( $values ) {
    foreach ( (array)$values as $value ) {
    $value = trim( $value );

    /* If the value is a URL, skip it and just make it clickable. */
    if ( preg_match( ‘@(https?://([-w.]+)+(:d+)?(/([w/_.]*(?S+)?)?)?)@’, $value ) ) {
    $new_values[] = make_clickable( $value );
    } else {
    if ( count( explode( ‘ ‘, $value ) ) > 5 )
    $new_values[] = $value;
    $new_values[] = ‘‘ . $value . ‘‘;

    $values = implode( ‘, ‘, $new_values );

    return $values;

    Any tips would be greatly appreciated.


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

  • sannymedia


    After searching Google for hours I found your post, and was happy at least someone had the same issue.
    Have you found a solution?
    –> I found the same file and I have exactly the same issue –> and even though I added a text on my registration page right after that profile field to please add the http:// , many users still just type in www
    –> hence their website link becomes a mixture of my mainblog and their address and their link doesn’t work, due to the this part I guess
    in the “else” where the Members Slug is added. (I was thinking of just removing it, but I’m not sure)

    I am not a developer and on my journey I found a solution in order to get rid of all profile links which didn’t make sense either but the issue with the website still remains. Maybe you found a solution and you can share it? I’d be really thankful.

    Here is what I found in order to get rid of the profile links, thanks to Jeff Sayre:
    1) add a file named bp-custom.php just to your plugins folder
    2 ) with the content that I can’t insert here unfortunately but from the first post of Jeff Sayre on this link:

    That did it for me!



    this works for me
    <a href="http://”&gt;

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Validating a url from xprofile field’ is closed to new replies.
Skip to toolbar