Support » Plugin: Buddypress Xprofile Custom Fields Type » bp_get_profile_field_data returns additional markup for email and website fields

  • Resolved Garrett Hyder

    (@garrett-eclipse)


    Hello,

    I noticed recently that the HTML5 Website and Email fields are returning with markup when called through the bp_get_profile_field_data function. This is conflicting with the link wrapping markup I have in place. My desire is to have just the email/web address returned as plain text as the method does for text fields.

    I noticed in the plugin code that this function is being intercepted with a filter:
    add_filter( 'xprofile_get_field_data', array($this, 'bxcft_get_field_data'), 10, 2 );

    And that it’s returning the markup for these fields:

    public function bxcft_get_field_data($value, $field_id)
            {
                $field = new BP_XProfile_Field($field_id);
                $value_to_return = strip_tags($value);
                if ($value_to_return !== '') {
    ...
                    // Email.
                    elseif ($field->type == 'email') {
                        if (strpos($value_to_return, 'mailto') === false) {
                            $value_to_return = sprintf('<a href="mailto:%s">%s</a>',
                                                    $value_to_return,
                                                    $value_to_return);
                        }
                    }
                    // Web.
                    elseif ($field->type == 'web') {
                        if (strpos($value_to_return, 'href=') === false) {
                            $value_to_return = sprintf('<a href="%s">%s</a>',
                                $value_to_return,
                                $value_to_return);
                        }
                    }
    ...
                }
    
                return apply_filters('bxcft_show_field_value', $value_to_return, $field->type, $field_id, $value);
            }

    I was able to strip this markup from my template using the strip_tags php function,
    strip_tags(bp_get_profile_field_data('field='.$fields['email'].'&user_id='.$user_id));
    but would prefer if I could simply disable this behaviour in the plugin.

    Much appreciated,
    Cheers

    https://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Miguel López

    (@atallos)

    Hi,

    If you want to modify the way emails and web are displayed you should use the filter bxcft_get_field_data. Check the FAQ if you need more details to see how to use it.

    Thread Starter Garrett Hyder

    (@garrett-eclipse)

    Thanks @donmik,

    Good to know for sure, and would probably see that as the method to add the links around the fields rather than strip them. I would suggest by default provide the fields in plaintext as they’re expected, similar to standard fields. As it would make more sense for me to receive the value when requested through bp_get_profile_field_data and then have the filter available so if I want the link functionality it can be introduced in that fashion rather than the other way around having to filter to get the plain value of the field.

    Appreciated,
    Cheers

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘bp_get_profile_field_data returns additional markup for email and website fields’ is closed to new replies.