BuddyDev

Search

How to add custom comments meta fields to users testimonials?

  • Participant
    Level: Initiated
    Posts: 11
    Ronald Story on #55125

    Hello BuddyDev Team!

    We would like to have some kind of hints of directions to follow in order to be able to add custom comments meta fields to users testimonials (which seems to be working as custom comments for custom post type testimonials).

    We would appreciate if your recommended approach could through the child theme, or the action/filter hooks through the custom function.php?

    Thanks in advance!

  • Participant
    Level: Initiated
    Posts: 11
    Ronald Story on #55126

    As an example one of the extra custom fields we would like to add is for example: “Your rating”, this will be a star rating according to some subjects. We are planning to have some other fields that might be or not be public.

    Thanks in advance!

    • This reply was modified 1 month, 1 week ago by Ronald Story.
  • Participant
    Level: Initiated
    Posts: 11
    Ronald Story on #55130

    Hello Team, hope you are doing great.

    Just mentioning we just manage to add some fields in the front-end through the post-form.php, we still would appreciate your comments on the back-end side of the fields to be able to align our work to the user-testimonial plugin you developed.

  • Keymaster
    (BuddyDev Team)
    Posts: 24881
    Brajesh Singh on #55132

    Hi Ronald,
    Thank you for the post.
    The testimonials are comments(WordPress comments) on a custom post type. All you need to do it add comment meta on save and then how it in the admin.

    Please let me know if you need assistance with something specific.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 11
    Ronald Story on #55171

    Hello Brajesh and BuddyDev Team, hope you are doing great!

    Here is a small update on our requirements – We would like some assistance regarding the next topics:

    1. Unfortunately we think we were not specific enough with the previous resolved ticket that we opened ( Right now users can writte testimonial without being “friends”, but we were actually interested in make public users able to posts testimonials without being members at all).

    Any public user just cannot submit a testimonial form properly, cause it seems to be just stuck.

    We only made these changes on the code currently:

    On the Child Theme functions.php:

    
    /* CUSTOM - All users can write testimonials permission */
    
    add_filter( 'bp_testimonial_user_can_write', 'custom_write_permission' );
    
    function custom_write_permission( $can_write ) {
    	
    	$can_write = true;
    	
    	return $can_write;
    	
    }
    

    On the testimonial-loop.php, we changed the if conditional in order to display the bp_testimonials_post_form() to anyone except the owner of the profile.

    
    <div class="u-testimonials">
    <?php if ( bp_is_my_profile() ) : ?>
    	<div class="error" id="message">
            <?php printf( __( 'You must not write your own testimonials.', 'bp-user-testimonials' )); ?>
    
        </div>
    <?php else :
    		bp_testimonials_post_form(); ?>
    <?php endif; ?>
    

    We also modified the wordpress->settings->discussion and disabled “Comment author must fill out name and email” so it should allow public users to writte testimonials, However we would later maybe add a name and email fields to the testimonial form.

    We appreciate any kind of support within this matter.

    2. About our request to add rating stars to the testimonials, we have some idea of how to add “comment meta” to a testimonial comment right after it is posted. We found the function save_testimonial(), which seems to get the $testimonial_id so then we could do something like add_comment_meta( $testimonial_id, 'rating', $_POST['rating'] ); The Post form will need to be modified in order to contain an input for star ratings. We would like to know if you think this could be a good solution or you could actually guide us through a better one?

    3. The final subject it is the way to “Display the meta data in the Wp dashboard”. As you already know we are able to see the testimonials in wp dashboard inside the edit panel of the “user testimonials” custom posts. We would like to ask you for some specific support to how could we display inside the comments panel all the meta fields that we could add to the testimonials (By default it is only showing Name, Web, and Comment message).

    As always we are really grateful with the BuddyDev team work and support towards the plugin and these requests.
    Thanks in advance for your help!

    • This reply was modified 4 weeks, 1 day ago by Ronald Story.
  • Participant
    Level: Initiated
    Posts: 11
    Ronald Story on #55175

    About the requirement number 1, we have actually changed the way users are able to comment. So you can just focus on requirements number 2 and 3.

    Thanks in advance for your support!

  • Keymaster
    (BuddyDev Team)
    Posts: 24881
    Brajesh Singh on #55183

    Hi Ronald,
    Hope you are doing well.
    I am sorry for the delayed reply.

    2. Yes, that is the right way. Just make sure to sanitize properly.

    3. WordPress uses WP_Post_Comments_List_Table which does not support adding custom columns. The only way to do it would be to filter to get_comment to inject the rating stars if the context is admin and parent post type is our utestimonials.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved