WordPress.org

Ready to get started?Download WordPress

Forums

Identify if the comment was wrriten by current user (2 posts)

  1. Chorley Rocks
    Member
    Posted 1 year ago #

    I have a function get_comment_class in comment-template.php. This returns a class for CSS.

    I want to indicate in the comment class if the person who wrote the comment is the same as the person who is logged in. My code is...

    // For comment authors who are logged in as current user
    if ( $wp_user_id = get_current_user_id() ) {
    if ( $comment->user_id === $wp_user_id )
    	$classes[] = 'cuser';
    }

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

    It's not working and I don't know why. Can anyone please help?

  2. Chorley Rocks
    Member
    Posted 1 year ago #

    I found this worked in all but one case.

    if ( $comment->user_id == get_current_user_id() ) $classes[] = 'cuser';

Topic Closed

This topic has been closed to new replies.

About this Topic