Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jbweb1

    (@jbweb1)

    It works:
    For the next people who try to do something similar, I write you the code I have.

    add_action( 'bbp_voting_voted', 'my_function_on_bbp_vote', 10, 3 );
    function my_function_on_bbp_vote( $post_id, $direction, $score ) {
    
    	if ($direction != 0) { // if user not voted on a topic
    		mycred_add( 'reference', get_current_user_id(), 1, 'Point for voting!' );
    		if ($direction == 1) { // if upvote:
    			mycred_add( 'reference', bbp_get_topic_author_id($post_id), 5, 'Points for asking questions!' );
    		} 
    		if ($direction == -1) { // if downvote:
    			mycred_add( 'reference', bbp_get_topic_author_id($post_id), -2, 'Points for asking non relevant questions!' );
    		}
    	}
    }
    Thread Starter jbweb1

    (@jbweb1)

    Thank you for your quick reply.
    But how can I know if a user already voted ? Even with the identifier, I still can’t know that test. Or may it exists a function has_user_voted($user_id) ?
    To help you viewing what I’m trying to do, here’s my code:

    add_action( 'bbp_voting_voted', 'my_function_on_bbp_vote', 10, 3 );
    function my_function_on_bbp_vote( $post_id, $direction, $score ) {
    	
    	mycred_add( 'reference', get_current_user_id(), 1, 'Point for voting!' );
    	if (1 == 1) { // here's goes the test where I need to check if user has already voted
    		if ($direction == 1) { // if upvote:
    			mycred_add( 'reference', bbp_get_topic_author_id($post_id), 5, 'Points for asking questions!' );
    		} 
    		else { // if downvote:
    			mycred_add( 'reference', bbp_get_topic_author_id($post_id), -2, 'Points for asking non relevant questions!' );
    		}
    	}
    }

    When I use that code, it give me points when I vote but also when I “unvote” and I don’t want to give points when “unvote”

    • This reply was modified 4 years, 2 months ago by jbweb1.
Viewing 2 replies - 1 through 2 (of 2 total)