• Resolved Azizul Karim

    (@azizul-karim-aec)


    I want to link comment author to their profile url. I’ve added this code to achieve this-

    function wpum_lets_change_comment_author_url( $return, $author, $comment_ID ) {
    
    	$user = get_user_by( 'login', $author );
    	$profile_url = wpum_get_profile_url( $user );
    
    	$return = "<a href='$profile_url' rel='external nofollow' class='url'>$author</a>";
    
    	return $return;
    
    }
    add_filter( 'get_comment_author_link', 'wpum_lets_change_comment_author_url', 10, 3 );

    This code returning with error Trying to get property 'user_login' of non-object in ...\plugins\wp-user-manager\includes\functions.php on line 823 and getting profile page url only.

    How can I solve the issue?

Viewing 1 replies (of 1 total)
  • Plugin Author WP User Manager

    (@wpusermanager)

    The issue is that some comments might have authors who are guests, not users. You need to check that the comment has a user_id first, eg.

    function wpum_lets_change_comment_author_url( $return, $author, $comment_ID ) {
    	$comment = get_comment( $comment_ID );
    	if ( $comment->user_id == 0 ) {
    		// Comment author not a user
    		return $return;
    	}
    	
    	$user = get_user_by( 'id', $comment->user_id );
    	$profile_url = wpum_get_profile_url( $user );
    
    	$return = "<a href='$profile_url' rel='external nofollow' class='url'>$author</a>";
    
    	return $return;
    
    }
    add_filter( 'get_comment_author_link', 'wpum_lets_change_comment_author_url', 10, 3 );
Viewing 1 replies (of 1 total)
  • The topic ‘Comment authors linked to profile url’ is closed to new replies.