Validating a url from xprofile field
-
Hi,
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;
else
$new_values[] = ‘‘ . $value . ‘‘;
}
}$values = implode( ‘, ‘, $new_values );
}return $values;
}Any tips would be greatly appreciated.
Thanks,
Dunc
- The topic ‘Validating a url from xprofile field’ is closed to new replies.