Sync User Comments Posted Before Installing UM
-
Hello @codings,
The profile tab “Comments” retrieves comments by the
user_idparameter that should match the profile owneruser_id. When guests leave a comment this comment is saved with emptyuser_id.You can override the comments.php template in your theme to use the
author_emailparameter instead of theuser_id. This doc describes how to override UM templates – Template structure & Overriding templates via a theme.Try to paste this code to the file
wp-content/themes/{active_theme}/ultimate-member/profile/comments.php<?php /** * Template for the profile comments * * Copy this file to yourtheme/ultimate-member/profile/comments.php to override default comments.php template. * * @version 2.6.1 * * @var int $count_comments * @var object $comments */ if ( ! defined( 'ABSPATH' ) ) { exit; } $user_id = ! empty( $_POST['user_id'] ) ? absint( $_POST['user_id'] ) : um_profile_id(); $page = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1; $comments = get_comments( array( 'number' => 10, 'offset' => ( $page - 1 ) * 10, 'author_email' => um_profile( 'user_email' ), 'post_status' => array('publish'), 'type__not_in' => apply_filters( 'um_excluded_comment_types', array('') ), ) ); if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { //Only for AJAX loading posts if ( ! empty( $comments ) ) { foreach ( $comments as $comment ) { UM()->get_template( 'profile/comments-single.php', '', array( 'comment' => $comment ), true ); } } } else { if ( ! empty( $comments ) ) { ?> <div class="um-ajax-items"> <?php foreach ( $comments as $comment ) { UM()->get_template( 'profile/comments-single.php', '', array( 'comment' => $comment ), true ); } if ( $count_comments > 10 ) { ?> <div class="um-load-items"> <a href="javascript:void(0);" class="um-ajax-paginate um-button" data-hook="um_load_comments" data-user_id="<?php echo esc_attr( um_get_requested_user() ); ?>" data-page="1" data-pages="<?php echo esc_attr( ceil( $count_comments / 10 ) ); ?>"> <?php _e( 'load more comments', 'ultimate-member' ); ?> </a> </div> <?php } ?> </div> <?php } else { ?> <div class="um-profile-note"> <span> <?php if ( um_profile_id() == get_current_user_id() ) { _e( 'You have not made any comments.', 'ultimate-member' ); } else { _e( 'This user has not made any comments.', 'ultimate-member' ); } ?> </span> </div> <?php } }Regards
Amazing! Worked flawlessly. Excellent support.
I will find a way to spend money with your company (buying pro, etc). Thanks again!
Hi @codings,
I’m glad I was able to help.
Can I mark this thread Resolved?Yes, thank you again 🙂
-
This reply was modified 2 years, 4 months ago by
codings.
-
This reply was modified 2 years, 4 months ago by
The topic ‘Sync User Comments Posted Before Installing UM’ is closed to new replies.
(@codings)
2 years, 4 months ago
Hi, I searched various places and could not find an answer to this:
When installing UM on a site which previously allowed guest comments, then opening site registration for users to create an account, on the comments tab it says “This user has not made any comments” even for users who commented before with the same email address.
Is there any way to sync users’ comments if they create an account after commenting as a guest?
If not, could you consider adding this as a tool in future versions? A button to run a user sync which would find any comments by the same email address and add it to the comments tab of their new account.
Thank you.