From 8adb6141ccca7fea6363877c25c130deacc168a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Harper?= Date: Tue, 5 Dec 2023 14:34:53 -0500 Subject: [PATCH] Respect public voting settings Applying https://github.com/Tmeister/idea-factory/pull/25. Thanks tareq1988 --- includes/class.process-vote.php | 12 ++++++------ public/includes/helpers.php | 4 ++-- templates/template-ideas.php | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/includes/class.process-vote.php b/includes/class.process-vote.php index d49e728..7c95fdb 100644 --- a/includes/class.process-vote.php +++ b/includes/class.process-vote.php @@ -44,13 +44,13 @@ function process_vote_up(){ $userid = get_current_user_ID(); - } elseif ( !is_user_logged_in() && $public_can_vote ) { + } elseif ( !is_user_logged_in() && $public_can_vote == 'on' ) { $userid = isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : 0; } // if the public can vote and the user has already voted or they are logged in and have already voted then bail out - if ( $public_can_vote && $has_public_voted || $has_private_voted ) { + if ( $public_can_vote == 'on' && $has_public_voted || $has_private_voted ) { echo 'already-voted'; die(); } @@ -59,7 +59,7 @@ function process_vote_up(){ update_post_meta( $postid, '_idea_votes', intval( $votes ) + 1 ); update_post_meta( $postid, '_idea_total_votes', intval( $total_votes ) + 1 ); - if ( !is_user_logged_in() && $public_can_vote ) { + if ( !is_user_logged_in() && $public_can_vote == 'on' ) { $args = array( 'postid' => $postid ); idea_factory_add_public_vote( $args ); @@ -107,14 +107,14 @@ function process_vote_down(){ $userid = get_current_user_ID(); - } elseif ( !is_user_logged_in() && $public_can_vote ) { + } elseif ( !is_user_logged_in() && $public_can_vote == 'on' ) { $userid = isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : 0; } // if the public can vote and the user has already voted or they are logged in and have already voted then bail out - if ( $public_can_vote && $has_public_voted || $has_private_voted ) { + if ( $public_can_vote == 'on' && $has_public_voted || $has_private_voted ) { echo 'already-voted'; die(); } @@ -124,7 +124,7 @@ function process_vote_down(){ update_post_meta( $postid, '_idea_total_votes', intval( $total_votes ) + 1 ); // update user meta so they can't vote on this again - if ( !is_user_logged_in() && $public_can_vote ) { + if ( !is_user_logged_in() && $public_can_vote == 'on' ) { $args = array( 'postid' => $postid ); idea_factory_add_public_vote( $args ); diff --git a/public/includes/helpers.php b/public/includes/helpers.php index 9bef41a..de8e893 100644 --- a/public/includes/helpers.php +++ b/public/includes/helpers.php @@ -182,7 +182,7 @@ function idea_factory_is_voting_active( $postid = '' ) { //if ( ( !idea_factory_has_private_voted( $postid ) && is_user_logged_in() || !idea_factory_has_public_voted( $postid ) && $public_can_vote ) && 'approved' !== $status ){ - if ( ( ( false == idea_factory_has_private_voted( $postid ) && is_user_logged_in()) || false == idea_factory_has_public_voted( $postid ) && $public_can_vote && !is_user_logged_in() ) && 'approved' !== $status ){ + if ( ( ( false == idea_factory_has_private_voted( $postid ) && is_user_logged_in()) || false == idea_factory_has_public_voted( $postid ) && $public_can_vote == 'on' && !is_user_logged_in() ) && 'approved' !== $status ){ return true; @@ -407,7 +407,7 @@ function idea_factory_submit_header(){ $intro_message = idea_factory_get_option('if_welcome','if_settings_main',apply_filters('idea_factory_default_message', __('Submit and vote for new features!','idea-factory'))); $public_can_vote = idea_factory_get_option('if_public_voting','if_settings_main'); - if ( is_user_logged_in() || $public_can_vote ): ?> + if ( is_user_logged_in() || $public_can_vote == 'on' ): ?>