Allow users to change their vote
-
This isn’t really a support post but I though I would relay the info in case you either want to develop this further, or if you have suggestions on a better way to implement this.
I have a small site that is members only. Members need to be able to change their vote easily.
In order to do this, I added the below code right before the following line in yop_poll_model.php:
if ( $this->user_have_votes_to_vote( $voter ) ){
Custom code:
if ( 'wordpress' == $voter['user_type'] ) { global $wpdb; $wpdb->query( $wpdb->prepare( " update " . $wpdb->yop_polls . " p set total_votes = total_votes - ( select count(pv.poll_id) from " . $wpdb->yop_poll_voters . " pv where p.id = pv.poll_id and pv.user_id = %d and pv.user_type = 'wordpress' ), total_answers = total_answers - ( select count(pl.answer_id) from wp_2_yop_poll_logs pl where p.id = pl.poll_id and pl.user_id = %d and pl.user_type = 'wordpress' ) where p.id = %d; ", $current_user->ID, $current_user->ID, $poll_id ) ); $wpdb->query( $wpdb->prepare( " update " . $wpdb->yop_poll_answers . " pa set votes = votes - ( select count(pl.answer_id) from " . $wpdb->yop_poll_logs . " pl where pa.id = pl.answer_id and pa.poll_id = pl.poll_id and pl.user_id = %d and pl.user_type = 'wordpress' ) where pa.poll_id = %d; ", $current_user->ID, $poll_id ) ); $wpdb->query( $wpdb->prepare( " delete from " . $wpdb->yop_poll_voters . " where poll_id = %d and user_id = %d and user_type = 'wordpress'; ", $poll_id, $current_user->ID ) ); $wpdb->query( $wpdb->prepare( " delete from " . $wpdb->yop_poll_logs . " where poll_id = %d and user_id = %d and user_type = 'wordpress'; ", $poll_id, $current_user->ID ) ); }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Allow users to change their vote’ is closed to new replies.