Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to use bp_member_profile_data when its type URL


  • solokco
    Participant

    @solokco

    So I’m trying to retrieve a LINK TYPE FIELD to add SOCIAL ICONS to my members.

    When adding the function bp_get_member_profile_data like so

    if ( bp_get_member_profile_data( ‘field=Twitter’ ) ) {
    < a target=’_blank’ href=”<?php echo bp_get_member_profile_data( ‘field=Twitter’ ) ;?>
    “>Twitter< /a>

    It doesn’t retrieve the URL… I get ALL the LINK like this:
    < a href=”https://twitter.com/comandovictor&#8221; rel=”nofollow”>twitter.com/comandovictor< /a>

    Is there a way to JUST retrieve the URL and NOT ALL that line?

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

  • danbp
    Participant

    @danbp

    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>&nbsp;
    
    <?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' );

    solokco
    Participant

    @solokco

    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?


    danbp
    Participant

    @danbp

    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.


    Juan
    Participant

    @cybnet

    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?


    danbp
    Participant

    @danbp

    @cybnet,

    you’re right, i wrote link instead URL box.
    Perhaps ongoing work around backbone by @imath can inspire you.


    BobSD99
    Participant

    @bobsd99

    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…

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to use bp_member_profile_data when its type URL’ is closed to new replies.
Skip to toolbar