Hi
instead using a link field type, use a normal text box and harcode the link to social account in the function. That way, the user has only to enter his account name and the link is build when the data is on front-end.
profile fields are stripped
profile datas are made clickable by default for search purpose in BP
We don’t want this for icons or when linking to a social network.
Here an usage example which use fontawesome to add the icons. That the general idea, change it to your need.
function bpfr_socialize_profile () {
echo '<br>';
if ( $data = bp_get_profile_field_data( 'field=Twitter ' ) ) :
?>
<a href="http://twitter.com/<?php echo xprofile_get_field_data( 'Twitter', bp_displayed_user_id() );?>/" target="_blank" title="Twitter"><i class="icon-twitter"></i><?php echo $data; ?></a>
<?php endif;
if ( $data = bp_get_profile_field_data( 'field=Facebook ' ) ) :
?>
<a href="http://facebook.com/<?php echo xprofile_get_field_data( 'Facebook', bp_displayed_user_id() );?>/" target="_blank" title="Facebook"><i class="icon-facebook"></i><?php echo $data; ?></a>
<?php
endif;
}
add_filter( 'bp_before_member_header_meta', 'bpfr_socialize_profile' );
Ok, this is great for new users, but already have like 1.500 users with this URL fields added.
Any ideas how I could solve this?
Take a look at DB tables related to xprofile:
_bp_xprofile_data
_bp_xprofile_fields
_bp_xprofile_groups
_bp_xprofile_meta
If users entered data like https://twitter.com/comandovictor
use a mysql command to wipe out https://twitter.com/
via phpMyAdmin.
UPDATE table_name SET col_name = REPLACE(col_name, 'old_value', 'new_value');
wp_ is default table prefix, change it if you use another prefix.
UPDATE wp_bp_xprofile_data SET col_name = REPLACE(value, 'https://twitter.com/', '');
That’s the fastest method. Don’t forget to backup the table BEFORE doing this.
Changing the field type can be done from the xprofile admin.
Hello. I’m dealing with this also but the proposal solution is not good. @danbp said “instead using a link field type, use a normal text box”. The problem is that the field type is not “link”, it is “URL” and the data is validated against URL format, not link. So we, as developers, should have the option to get the value of the URL instead of a formated link.
¿Any other suggestion?
@cybnet,
you’re right, i wrote link instead URL box.
Perhaps ongoing work around backbone by @imath can inspire you.
I think you may want the funtion wp_extract_urls().
So for example:
$url = wp_extract_urls( xprofile_get_field_data( '23', $user->ID ) );
echo "URL: $url[0]";
New to WP coding but this worked for me…