Skip to content

Instantly share code, notes, and snippets.

@max-kk
Last active May 6, 2022 17:55
Show Gist options
  • Save max-kk/2d773bc181ad5cb5268d7f8155988662 to your computer and use it in GitHub Desktop.
Save max-kk/2d773bc181ad5cb5268d7f8155988662 to your computer and use it in GitHub Desktop.
FV :: unvote
+(function($) {
// action before voting
FvLib.addFilter('fv/vote/get_data', function(data) {
if ( data.res !== 10 ) {
return data;
}
data.no_process = "yes";
if ( FvVote.is_voted_for(data.contestant_id) ) {
localStorage.removeItem( "voted_" + data.contestant_id );
jQuery(".contest-block[data-id='" + data.contestant_id + "']").removeClass("is-voted");
FvModal.goVoted("success", "Unvoted!", "The vote was removed!", "", data.contestant_id);
fv_set_votes_count(data.contestant_id, data.new_votes);
}
return data;
}, 9, 1);
})(jQuery);
<?php
// COPY AFTER
add_action('fv/vote/fail', function($code, $contest, $competitor, $add_subscription, $used_votes, $check_ip_query, $check_ip) {
$vote = array_pop($check_ip);
ModelVotes::q()->delete( $vote->id );
$competitor->votes_count = $competitor->votes_count - 1;
$competitor->save();
FV_Public_Vote::echoVoteRes(10, false, $add_subscription, 0, $competitor->votes_count); // echo response
}, 10, 7);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment