Viewing 5 replies - 16 through 20 (of 20 total)
  • Ah, sorry to say but one final bug remains. It awards the post author twice if the commenter is a member (because I have set 1 point for Content Author in the core comment settings).

    Can we make this custom hook to ignore giving points if the commenter is already a member, because the core plugin does that already…

    edit: or the alternative would be to set points to 0 in core settings? ??

    Plugin Author myCred

    (@designbymerovingi)

    Here is an updated version:

    if ( function_exists( 'mycred_add' ) ) {
    	add_action( 'comment_post',              'award_new_guest_comments', 10, 2 );
    	function award_new_guest_comments( $comment_id, $comment_status )
    	{
    		if ( $comment_status == '1' )
    			award_points_for_guest_comments( 'approved', '', $comment_id );
    	}
    	add_action( 'transition_comment_status', 'award_points_for_guest_comments', 10, 3 );
    	function award_points_for_guest_comments( $new_status, $old_status, $comment )
    	{
    		// Look for approved comments and "guests"
    		if ( $new_status != 'approved' ) return;
    
    		// Grab the comment object in case it is not there
    		if ( !is_object( $comment ) )
    			$comment = get_comment( $comment );
    
    		// Ignore logged in users
    		if ( $comment->user_id != 0 ) return;
    
    		// Ignore Pingbacks or Trackbacks
    		if ( !empty( $comment->comment_type ) ) return;
    
    		// Get post author
    		$post = get_post( (int) $comment->comment_post_ID );
    		$post_author = $post->post_author;
    
    		// Check if the post author should be excluded
    		if ( mycred_exclude_user( $post_author ) === true ) return;
    
    		// Award points to author
    		mycred_add(
    			'new_comment', // reference
    			$post_author, // who to get points
    			1, // number of points to award
    			'Guest comment on <a href=%c_post_url%>%c_post_title%</a>', // log template to use
    			$comment->comment_ID, // save comment id as reference id
    			array( 'ref_type' => 'comment' ) // enable support for comment related template tags
    		);
    	}
    }

    I am returning with another request of adjustment. Currently, this awards points to Content Author (author of post). So basically the author gets points for commenting on their own post.

    Is there a possibility to check if the commenter is the author of post, and if so, skip/don’t award?

    Here is the complete code that I use:

    if ( function_exists( 'mycred_add' ) ) {
    	add_action( 'comment_post',              'award_new_guest_comments', 10, 2 );
    	function award_new_guest_comments( $comment_id, $comment_status )
    	{
    		if ( $comment_status == '1' )
    			award_points_for_guest_comments( 'approved', '', $comment_id );
    	}
    	add_action( 'transition_comment_status', 'award_points_for_guest_comments', 10, 3 );
    	function award_points_for_guest_comments( $new_status, $old_status, $comment )
    	{
    		// Look for approved comments
    		if ( $new_status != 'approved' ) return;
    
    		// Grab the comment object in case it is not there
    		if ( !is_object( $comment ) )
    			$comment = get_comment( $comment );
    
    		// Ignore Pingbacks or Trackbacks
    		if ( !empty( $comment->comment_type ) ) return;
    
    		// Get post author
    		$post = get_post( (int) $comment->comment_post_ID );
    		$post_author = $post->post_author;
    
    		// Check if the post author should be excluded
    		if ( mycred_exclude_user( $post_author ) === true ) return;
    
    		// Award points to author
    		mycred_add(
    			'new_comment', // reference
    			$post_author, // who to get points
    			1, // number of points to award
    			'Guest comment on <a href=%c_post_url%>%c_post_title%</a>', // log template to use
    			$comment->comment_ID, // save comment id as reference id
    			array( 'ref_type' => 'comment' ) // enable support for comment related template tags
    		);
    	}
    }

    Plugin Author myCred

    (@designbymerovingi)

    Sure you can.

    In the above code you have the $post_author variable setup so you just need to make some comparing.

    Example to check against an email:

    $user = get_user_by( 'email', $comment->comment_author_email );
    // If a user exists and it's user ID is the same as the content authors
    if ( $user !== false && $user->ID == $post_author ) return;

    You would place this before mycred_add() and after $post_author = $post->post_author

    Works! Thank you Gabriel.

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Guest comments not affecting comment points?’ is closed to new replies.