• Resolved codings

    (@codings)


    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support yuriinalivaiko

    (@yuriinalivaiko)

    Hello @codings,

    The profile tab “Comments” retrieves comments by the user_id parameter that should match the profile owner user_id. When guests leave a comment this comment is saved with empty user_id.

    You can override the comments.php template in your theme to use the author_email parameter instead of the user_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

    Thread Starter codings

    (@codings)

    Amazing! Worked flawlessly. Excellent support.

    I will find a way to spend money with your company (buying pro, etc). Thanks again!

    Plugin Support yuriinalivaiko

    (@yuriinalivaiko)

    Hi @codings,
    I’m glad I was able to help.
    Can I mark this thread Resolved?

    Thread Starter codings

    (@codings)

    Yes, thank you again ??

    • This reply was modified 1 year, 1 month ago by codings.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sync User Comments Posted Before Installing UM’ is closed to new replies.