Support » Plugin: Multi Rating » Hiding ratings if alreday voted

  • Resolved bobotton

    (@bobotton)


    Hi!

    Overall great plugin, good job!
    My question is more of a pre-purchase type.

    I’m using Free version and my users say that they see the form even though they have already voted, i.e. on page reload it shows again the rating form.
    However, I would like to hide the form if the logged-in user has already voted.

    On your github page I found a gist with the desired funciton:
    https://gist.github.com/danielpowney/7493d4109c05d6c6883a2592af6bc67d

    Is it going to work with the free version? Should I just download the file and place it into /templates or /includes folder of the plugin?

    If its not working with free version what should I do after purchasing the Pro version – same actions manually or is there some sort of admin control for this very useful feature (which I believe is worth being included into free version)?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author dpowney

    (@dpowney)

    Hello!

    There’s no equivalent user_rating_exists() function in the free version. But you can easily create your own. You can query the db table. user_id = 0 for anonymous users.

    SELECT * FROM wp_mr_rating_item_entry WHERE user_id = 1

    You could extend the validation of the rating form using the filter mr_after_rating_form_validation_save for example.

    /**
     * Custom rating form validation free version
     * 
     * @param unknown $validation_results
     * @param unknown $data
     * @return $validation_results
     */
    function mr_custom_rating_form_validation_check( $validation_results, $data ) {
    
    	$post_id = $data['post_id'];
    
    	global $wp_roles;
    	$user = wp_get_current_user();
    	$user_id = $user->ID;
    	
    	/* Add custom check here */
    	if ( true ) {
    		array_push( $validation_results, array( 
    				'severity' => 'error', 
    				'field' => 'name',
    				'name' => 'my_error',
    				'message' => __( 'My error.', 'multi-rating-pro' ) ) );
    	}
    	
    	 
    	return $validation_results;
    }
    add_filter( 'mr_after_rating_form_validation_save', 'mr_custom_rating_form_validation_check', 10, 12);

    The Pro version does not allow logged in users to rate the same post multiple times by default. Logged in users can update/delete existing ratings as well.

    Hope this helps!

    • This reply was modified 10 months, 1 week ago by dpowney.
    • This reply was modified 10 months, 1 week ago by dpowney.
    Thread Starter bobotton

    (@bobotton)

    Hi, Daniel!

    I appreciate your advice and willingness to help! Did I get it right: I need to put the code of “Custom rating form validation free version” example into my theme’s functions.php file, correct?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hiding ratings if alreday voted’ is closed to new replies.