Add users xprofile fields to a comment

Hey,
So I'm not familiar with coding but I'm a fast learner (:

My question is divided to three parts:
1. When a user makes a comment, id like to see all his xprofile details (buddypress). It can be in the comment content area or as part of the details related to the comment (name, avatar etc.). prefer the easier way (:

2. Is it possible, and if so, how, to relate the users xprofile details as mentioned above, without giving the user the ability to actually post any content of his own, he/she won't see the text area. I just need the user to post his/hers own profile details.

3. I want all the comments made for a post appear on another page. not each comment to have a separated page, but all comments made for a specific post, be all on the same page, but not the original post page.

I know its allot to ask ill be very grateful to anyone that can help me here.
Thanks allot!!!

  • Jack Kitterhing

    Hi there @Matan,

    Hope you're well today and thanks for your question.

    1 and 2, can you clarify how you want this to display on the front-end please? Where should the xprofile fields displayed, do you have a mockup? How many fields?

    3:

    . I want all the comments made for a post appear on another page. not each comment to have a separated page, but all comments made for a specific post, be all on the same page, but not the original post page.

    Can you clarify on that please, is it meant to be a separate page the user clicks through too? Or something else?

    Thanks!

    Kind Regards
    Jack.

  • Matan

    Hey Jack! Thank you,
    1. front-end... so if usually, when a user posts a comment, the name and avatar appears on the side or above the content of the comment. I want to add, next to them also his gender, birthday, and home town.

    2. Imagine, its not a comment, but only a kind of "check-in" button, where a user just tells you; "Im here!" (with the addition of his profile details)

    3. Lets leave that aside for now (:

    Thanks Allot

  • Hoang Ngo

    Hi @Matan,

    About add those fields to a comment, so the most easy way is we will filter the comment text and add the fields below it.

    Here is a sample code for that, please add the code to your theme functions.php

    add_filter( 'comment_text', 'append_xprofile_to_comment', 10, 2 );
    function append_xprofile_to_comment( $comment_text, $comment ) {
    	$fields               = array( 'gender', 'birthday', 'home town', 'location' );
    	$xprofile_fields_html = '';
    	foreach ( $fields as $field ) {
    		$value = xprofile_get_field_data($field,$comment->user_id);
    		if ( ! empty( $value ) ) {
    			$xprofile_fields_html .= $field . ': ' . $value . '<br/>';
    		}
    	}
    	if ( ! empty( $xprofile_fields_html ) ) {
    		$comment_text .= '<br/>' . $xprofile_fields_html;
    	}
    	return $comment_text;
    }

    If user dont register, so it will not show anything :slight_smile:

    If you have any issues please don't hesitate to let us know so we can assist

    Best Regards
    Hoang

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.