BuddyDev

Search

[Resolved] Echo xprofile_get_field_data returns text without space.

  • Participant
    Level: Enlightened
    Posts: 71
    Lefteris on #47815

    Hello and happy new year to all the team 🙂

    I am using xprofile_get_field_data to echo a text from a ‘Multi-line Text Area’ field. However i get all the text in a single line and not in paragraphs that it should be.

    I have also used the below filter to allow some tags in the field and it’s working correct in the bp profile, but not in the echo with xprofile_get_field_data to another page of the website.

    
    // Allow some style in tags in BP richtext editor
    function custom_allowed_tags( $xprofile_allowedtags, $data_obj, $field_id ) {
    
    		if ( $field_id && bp_xprofile_is_richtext_enabled_for_field( $field_id ) ) {
    		$custom_tags = array(
    			'span'   => array( 'style' => 1 ),
    			'a'    => array( 'href' => 1, 'target' => 1 ),
    		);
    
    		$xprofile_allowedtags = array_merge( $xprofile_allowedtags, $custom_tags );
    	}
    
    		return $xprofile_allowedtags;
    }
    add_filter( 'xprofile_allowed_tags', 'custom_allowed_tags' , 30, 3 );
    

    How could i get the same html result from echo xprofile_get_field_data ?

    Thank very much for your help.

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #47816

    Hi,
    Happy new year to you too!

    Thank you for the question.
    The reason is xprofile_get_field_data does not apply the filters which are applied on profile by “bp_get_the_profile_field_value()” function.

    The solution is to manually call the filter or call the applied functions.
    For example, in case of text area, you can call wpautop($value) and that will add line/paragraph breaks.

    Here is an example showing it in action
    https://github.com/buddydev/bp-shortcodes/blob/master/src/shortcodes/profile/class-profile-data-shortcodes.php#L107

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 71
    Lefteris on #47864

    Thank you very much Brajesh for your kind help 🙂

    • This reply was modified 1 year, 2 months ago by Lefteris.

You must be logged in to reply to this topic.

This topic is: resolved